Class: DearInventory::Request

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dear_inventory/lib/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters, num_previous_records: 0) ⇒ Request

Returns a new instance of Request.



24
25
26
27
28
# File 'lib/dear_inventory/lib/request.rb', line 24

def initialize(parameters, num_previous_records: 0)
  @parameters = T.let(parameters, DearInventory::Models::Request)
  @num_previous_records = T.let(num_previous_records, Integer)
  @retries = T.let(0, Integer)
end

Class Method Details

.call(parameters, num_previous_records: 0) ⇒ Object



14
15
16
# File 'lib/dear_inventory/lib/request.rb', line 14

def self.call(parameters, num_previous_records: 0)
  new(parameters, num_previous_records: num_previous_records).call
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dear_inventory/lib/request.rb', line 31

def call
  options = request_params(@parameters.action, @parameters.params)
  response = HTTP.headers(headers).
    public_send(@parameters.action, @parameters.uri, options)

  DearInventory::Response.new(
    response: response,
    request: @parameters,
    num_previous_records: @num_previous_records
  )
rescue DearInventory::APILimitError, HTTP::ConnectionError => e
  retry_request(e)
end