Class: RProxy::HttpPostTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/r_proxy/http_post_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri, path) ⇒ HttpPostTemplate

Returns a new instance of HttpPostTemplate.



6
7
8
9
10
11
12
# File 'lib/r_proxy/http_post_template.rb', line 6

def initialize(uri, path)
  @route = path
  @protocol = "POST #{@route} HTTP/1.1"
  @host = uri.host
  @port = uri.port
  @headers = init_headers
end

Instance Method Details

#create(user, pass, value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/r_proxy/http_post_template.rb', line 14

def create(user, pass, value)
  body = {
    user: user,
    pass: pass,
    value: value,
    timestamp: Time.now.getutc.to_i
  }.to_json

  @headers['Content-Length'] = body.bytesize

  headers_str = header_to_s

  "#{@protocol}\r\n#{headers_str}\r\n#{body}\r\n"
end