Method: Rev::HttpClient#post_binary

Defined in:
lib/rev-api/http_client.rb

#post_binary(operation, file, headers = {}) ⇒ Net::HTTP::Response

Performs HTTP POST of binary data. Note, unlike post, this returns a Net::HTTP::Response, not HTTParty::Response.

Parameters:

  • operation (String)

    URL suffix describing specific operation

  • file (File)

    file-like object containing the data to post

  • headers (Hash) (defaults to: {})

    hash of headers to use for the request

Returns:

  • (Net::HTTP::Response)

    response



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rev-api/http_client.rb', line 83

def post_binary(operation, file, headers = {})
  uri = URI.parse("#{self.class.base_uri}#{operation}")
  headers = @default_headers.merge(headers)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  post = Net::HTTP::Post.new(uri.request_uri, headers)
  post["Content-Length"] = file.stat.size.to_s
  post.body_stream = file

  response = http.request(post)
end