Class: EasybillRestClient::Request

Inherits:
Object
  • Object
show all
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

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_detailsObject



38
39
40
# File 'lib/easybill_rest_client/request.rb', line 38

def request_details
  body_allowed? ? request.body : uri.query
end

#runObject



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