Method: ESHQ::Client#post

Defined in:
lib/eshq/client.rb

#post(path, params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eshq/client.rb', line 20

def post(path, params)
  url = url_for(path)

  request = Net::HTTP::Post.new(url.path)
  request.set_form_data(params.merge(credentials))

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true if url.is_a?(URI::HTTPS)
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  response = http.request(request)
  if response.code == "200"
    response.content_type == "application/json" ? MultiJson.load(response.body) : true
  else
    raise "Error #{response.body}"
  end
end