class Hithorizons::Company::BaseApi
Constants
- API_URL
Public Class Methods
get(path)
click to toggle source
# File lib/hithorizons/company/base_api.rb, line 39 def self.get(path) request(path, 'GET') end
initialize_client()
click to toggle source
# File lib/hithorizons/company/base_api.rb, line 30 def self.initialize_client ::Faraday.new(url: Hithorizons.config.api_url) do |faraday| faraday.request :json faraday.response :json faraday.adapter Faraday.default_adapter end end
process_request(uri, method = 'GET', payload = nil)
click to toggle source
# File lib/hithorizons/company/base_api.rb, line 8 def self.process_request(uri, method = 'GET', payload = nil) response = request(uri, method, payload) raise(Hithorizons::Error, response.body) if response.status != 200 Hithorizons::Company::Response.new(response.body) end
request(uri, method = 'GET', payload = nil)
click to toggle source
# File lib/hithorizons/company/base_api.rb, line 16 def self.request(uri, method = 'GET', payload = nil) client = initialize_client client.send(method.downcase.to_sym) do |request| request.headers['Ocp-Apim-Subscription-Key'] = Hithorizons.config.api_key request.url("#{API_URL}#{uri}") if method == 'GET' request.params = payload else request.body = payload end end end