class Stuart::Infrastructure::HttpClient

Public Class Methods

new(authenticator) click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 7
def initialize(authenticator)
  @authenticator = authenticator
end

Public Instance Methods

perform_get(resource) click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 11
def perform_get(resource)
  to_api_response Typhoeus.get(url(resource), headers: default_header)
end
perform_post(resource, body) click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 15
def perform_post(resource, body)
  to_api_response Typhoeus.post(url(resource), headers: default_header, body: body)
end

Private Instance Methods

default_header() click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 25
def default_header
  { "Authorization" => "Bearer #{@authenticator.access_token}",
    "User-Agent" => "stuart-client-ruby/#{Stuart::Version::STRING}",
    "Content-Type" => "application/json" }
end
to_api_response(response) click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 31
def to_api_response(response)
  status_code = response.response_code
  body = JSON.parse(response.response_body) if response.response_body
  ApiResponse.new(status_code, body)
end
url(resource) click to toggle source
# File lib/stuart-client-ruby/infrastructure/http_client.rb, line 21
def url(resource)
  "#{@authenticator.environment[:base_url]}#{resource}"
end