class MojFileUploaderApiClient::HttpClient

Constants

DEFAULT_OPTIONS

Attributes

base_url[RW]
options[RW]
response[RW]

Public Class Methods

configure() { |self| ... } click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 19
def configure
  yield(self)
end

Public Instance Methods

call() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 24
def call
  execute_request
  response
end
endpoint() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 29
def endpoint
  raise 'not implemented'
end
options() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 43
def options
  # Using `self.class.options` allows overriding defaults in individual API
  # calls and ensure that overrides do not persist across calls.
  DEFAULT_OPTIONS.merge(self.class.options || {})
end
payload() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 37
def payload; end
payload?() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 39
def payload?
  !payload.nil?
end
verb() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 33
def verb
  raise 'not implemented'
end

Private Instance Methods

execute_request() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 61
def execute_request
  begin
    res = RestClient::Request.execute(request_details)
    code, body = res.code, res.body
  rescue RestClient::Exception => ex
    code, body = ex.http_code, ex.response
  end

  self.response = Response.new(code: code, body: body)
end
request_details() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 55
def request_details
  {method: verb, url: url}.merge(options).tap do |args|
    args.merge!(payload: payload.to_json) if payload?
  end
end
url() click to toggle source
# File lib/mojfile_uploader_api_client/http_client.rb, line 51
def url
  File.join(HttpClient.base_url, endpoint)
end