Class: EasybillRestClient::ApiClient
- Inherits:
-
Object
- Object
- EasybillRestClient::ApiClient
- Defined in:
- lib/easybill_rest_client/api_client.rb
Constant Summary collapse
- DEFAULT_RETRY_COOL_OFF_TIME =
15
- DEFAULT_TRIES =
5
- MAX_PAGE_SIZE =
1000
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #request(method, endpoint, params = {}) ⇒ Object
- #request_collection(method, endpoint, params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ApiClient
Returns a new instance of ApiClient.
17 18 19 20 21 22 |
# File 'lib/easybill_rest_client/api_client.rb', line 17 def initialize( = {}) @api_key = .fetch(:api_key) @retry_cool_off_time = .fetch(:retry_cool_off_time, DEFAULT_RETRY_COOL_OFF_TIME) @tries = .fetch(:tries, DEFAULT_TRIES) @logger = .fetch(:logger, Logger.new($stdout)) end |
Instance Method Details
#request(method, endpoint, params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 = {}) ⇒ Object
24 25 26 27 28 |
# 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 |