class EasybillRestClient::ApiClient
Constants
- DEFAULT_RETRY_COOL_OFF_TIME
- DEFAULT_TRIES
- MAX_PAGE_SIZE
Attributes
api_key[R]
logger[R]
retry_cool_off_time[R]
tries[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/easybill_rest_client/api_client.rb, line 17 def initialize(options = {}) @api_key = options.fetch(:api_key) @retry_cool_off_time = options.fetch(:retry_cool_off_time, DEFAULT_RETRY_COOL_OFF_TIME) @tries = options.fetch(:tries, DEFAULT_TRIES) @logger = options.fetch(:logger, Logger.new($stdout)) end
Public Instance Methods
request(method, endpoint, params = {})
click to toggle source
# File lib/easybill_rest_client/api_client.rb, line 30 def request(method, endpoint, params = {}) request = Request.new( api_key: api_key, method: method, endpoint: endpoint, params: params, logger: logger, tries: tries, retry_cool_off_time: retry_cool_off_time ) Response.new(request.run).body end
request_collection(method, endpoint, params = {})
click to toggle source
# File lib/easybill_rest_client/api_client.rb, line 24 def request_collection(method, endpoint, params = {}) fetch_pages do |page| request(method, endpoint, params.merge(page: page, limit: MAX_PAGE_SIZE)) end end
Private Instance Methods
fetch_pages() { |page| ... }
click to toggle source
# File lib/easybill_rest_client/api_client.rb, line 45 def fetch_pages Enumerator.new do |y| page = 1 loop do collection = yield(page) collection[:items].each do |item| y << item end break if collection[:page] >= collection[:pages] page += 1 end end.lazy end