class Abt::Providers::Harvest::Api
Constants
- API_ENDPOINT
- VERBS
Attributes
access_token[R]
account_id[R]
Public Class Methods
new(access_token:, account_id:)
click to toggle source
# File lib/abt/providers/harvest/api.rb, line 12 def initialize(access_token:, account_id:) @access_token = access_token @account_id = account_id end
Public Instance Methods
connection()
click to toggle source
# File lib/abt/providers/harvest/api.rb, line 52 def connection @connection ||= Faraday.new(API_ENDPOINT) do |connection| connection.headers["Authorization"] = "Bearer #{access_token}" connection.headers["Harvest-Account-Id"] = account_id connection.headers["Content-Type"] = "application/json" end end
get_paged(path, query = {})
click to toggle source
# File lib/abt/providers/harvest/api.rb, line 23 def get_paged(path, query = {}) result_key = path.split("?").first.split("/").last page = 1 records = [] loop do result = get(path, query.merge(page: page)) records += result[result_key] break if result["total_pages"] == page page += 1 end records end
request(*args)
click to toggle source
# File lib/abt/providers/harvest/api.rb, line 40 def request(*args) response = connection.public_send(*args) if response.success? Oj.load(response.body) else error_class = Abt::HttpError.error_class_for_status(response.status) encoded_response_body = response.body.force_encoding("utf-8") raise error_class, "Code: #{response.status}, body: #{encoded_response_body}" end end