Module: PaapiMini::Http

Defined in:
lib/http_client.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.post(uri, payload, headers, options = {}) ⇒ Object

Post



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/http_client.rb', line 16

def self.post(uri, payload, headers, options = {})
  begin
    parsed_uri, http = create_http(uri, options.has_key?(:proxy_url) ? options[:proxy_url] : nil)
    req = Net::HTTP::Post.new(parsed_uri.request_uri)

    headers.each do |key, value|
      req[key.to_s] = value.to_s
    end

    if options.has_key?(:basic_auth)
      req.basic_auth(options[:basic_auth][0], options[:basic_auth][1])
    end

    req.body = payload
    http.request(req)
  rescue => e
    raise PaapiMini::Http::Error.new("#{e.message} #{e.backtrace}" )
  end
end