class Nonnative::HTTPClient

Attributes

host[R]

Public Class Methods

new(host) click to toggle source
# File lib/nonnative/http_client.rb, line 5
def initialize(host)
  @host = host
end

Protected Instance Methods

delete(pathname, headers = {}, timeout = 60) click to toggle source
# File lib/nonnative/http_client.rb, line 26
def delete(pathname, headers = {}, timeout = 60)
  with_exception do
    uri = URI.join(host, pathname)
    RestClient::Request.execute(method: :delete, url: uri.to_s, headers: headers, timeout: timeout)
  end
end
get(pathname, headers = {}, timeout = 60) click to toggle source
# File lib/nonnative/http_client.rb, line 11
def get(pathname, headers = {}, timeout = 60)
  with_exception do
    uri = URI.join(host, pathname)
    RestClient::Request.execute(method: :get, url: uri.to_s, headers: headers, timeout: timeout)
  end
end
post(pathname, payload, headers = {}, timeout = 60) click to toggle source
# File lib/nonnative/http_client.rb, line 18
def post(pathname, payload, headers = {}, timeout = 60)
  with_exception do
    uri = URI.join(host, pathname)
    RestClient::Request.execute(method: :post, url: uri.to_s, payload: payload.to_json, headers: headers,
                                timeout: timeout)
  end
end
put(pathname, payload, headers = {}, timeout = 60) click to toggle source
# File lib/nonnative/http_client.rb, line 33
def put(pathname, payload, headers = {}, timeout = 60)
  with_exception do
    uri = URI.join(host, pathname)
    RestClient::Request.execute(method: :put, url: uri.to_s, payload: payload.to_json, headers: headers,
                                timeout: timeout)
  end
end

Private Instance Methods

with_exception() { || ... } click to toggle source
# File lib/nonnative/http_client.rb, line 45
def with_exception
  yield
rescue RestClient::Exceptions::ReadTimeout => e
  raise e
rescue RestClient::ExceptionWithResponse => e
  e.response
end