Sha256: 1e6850cb335125fb79700182c19523dee334ae814f926da52f68cefbc0fc9bbb

Contents?: true

Size: 787 Bytes

Versions: 8

Compression:

Stored size: 787 Bytes

Contents

require 'json'

module RProxy
  class HttpPostTemplate

    def initialize(route)
      @route = route
      @headers = init_headers
      @protocol = "POST #{route} HTTP/1.1"
    end

    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}"
    end

    private

    def header_to_s
      tmp = ''
      @headers.each do |k, v|
        tmp += "#{k}: #{v}\r\n"
      end
      tmp
    end

    def init_headers
      {
        'User-Agent' => "RProxy/#{RProxy::VERSION}",
        'Content-Type' => 'application/json',
      }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
r_proxy-0.2.7 lib/r_proxy/http_post_template.rb
r_proxy-0.2.6 lib/r_proxy/http_post_template.rb
r_proxy-0.2.5 lib/r_proxy/http_post_template.rb
r_proxy-0.2.4 lib/r_proxy/http_post_template.rb
r_proxy-0.2.3 lib/r_proxy/http_post_template.rb
r_proxy-0.2.2 lib/r_proxy/http_post_template.rb
r_proxy-0.2.1 lib/r_proxy/http_post_template.rb
r_proxy-0.2.0 lib/r_proxy/http_post_template.rb