Class: EasybillRestClient::Request
- Inherits:
-
Object
- Object
- EasybillRestClient::Request
- Defined in:
- lib/easybill_rest_client/request.rb
Constant Summary collapse
- BASE_URL =
'https://api.easybill.de/rest/v1'
- USERNAME =
'[email protected]'
- SUPPORTED_METHODS =
%i[get post put delete].freeze
- OPEN_TIMEOUT =
30
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Request
constructor
A new instance of Request.
- #request_details ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/easybill_rest_client/request.rb', line 13 def initialize(opts = {}) unless SUPPORTED_METHODS.include?(opts.fetch(:method).to_sym) raise ArgumentError, "Unsupported HTTP method '#{method}'" end @api_key = opts.fetch(:api_key) @method = opts.fetch(:method) @endpoint = opts.fetch(:endpoint) @params = opts.fetch(:params) @logger = opts.fetch(:logger) @tries = opts.fetch(:tries) @retry_cool_off_time = opts.fetch(:retry_cool_off_time) end |
Instance Method Details
#request_details ⇒ Object
38 39 40 |
# File 'lib/easybill_rest_client/request.rb', line 38 def request_details body_allowed? ? request.body : uri.query end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/easybill_rest_client/request.rb', line 27 def run request_logger.info("#{method.to_s.upcase} #{endpoint} #{request_details}") retry_on(TooManyRequests) do retry_on(Net::OpenTimeout) do response = perform_request raise TooManyRequests if response.is_a?(Net::HTTPTooManyRequests) response end end end |