Class: Ondotori::WebAPI::HttpWebAccess

Inherits:
WebAccess
  • Object
show all
Defined in:
lib/ondotori/webapi/httpwebaccess.rb

Instance Method Summary collapse

Methods inherited from WebAccess

#initialize

Constructor Details

This class inherits a constructor from Ondotori::WebAPI::WebAccess

Instance Method Details

#access(uri, params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ondotori/webapi/httpwebaccess.rb', line 14

def access(uri, params)
  web_uri = URI.parse(uri)
  http = Net::HTTP.new(web_uri.host, web_uri.port)
  http.use_ssl = (web_uri.scheme == "https")

  response = http.request_post(web_uri.path, params.to_json, make_headers)
  case response
  when Net::HTTPSuccess
    response
  when Net::HTTPClientError, Net::HTTPServerError
    response
  else
    # response.value raises Eception...
    raise Ondotori::WebAPI::Api::Errors::HttpAccessError.new("#{response.message}", "#{response.code}", 9995)
  end
end

#make_headersObject



10
11
12
# File 'lib/ondotori/webapi/httpwebaccess.rb', line 10

def make_headers
  { "Content-Type" => "application/json", "X-HTTP-Method-Override" => "GET" }
end