Class: SolidusShipstation::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_shipstation/api/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_runner:, error_handler:, shipment_serializer:) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
# File 'lib/solidus_shipstation/api/client.rb', line 18

def initialize(request_runner:, error_handler:, shipment_serializer:)
  @request_runner = request_runner
  @error_handler = error_handler
  @shipment_serializer = shipment_serializer
end

Instance Attribute Details

#error_handlerObject (readonly)

Returns the value of attribute error_handler.



16
17
18
# File 'lib/solidus_shipstation/api/client.rb', line 16

def error_handler
  @error_handler
end

#request_runnerObject (readonly)

Returns the value of attribute request_runner.



16
17
18
# File 'lib/solidus_shipstation/api/client.rb', line 16

def request_runner
  @request_runner
end

#shipment_serializerObject (readonly)

Returns the value of attribute shipment_serializer.



16
17
18
# File 'lib/solidus_shipstation/api/client.rb', line 16

def shipment_serializer
  @shipment_serializer
end

Class Method Details

.from_configObject



7
8
9
10
11
12
13
# File 'lib/solidus_shipstation/api/client.rb', line 7

def from_config
  new(
    request_runner: RequestRunner.from_config,
    error_handler: SolidusShipstation.config.error_handler,
    shipment_serializer: SolidusShipstation.config.api_shipment_serializer,
  )
end

Instance Method Details

#bulk_create_orders(shipments) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/solidus_shipstation/api/client.rb', line 24

def bulk_create_orders(shipments)
  params = shipments.map do |shipment|
    shipment_serializer.call(shipment)
  rescue StandardError => e
    error_handler.call(e, shipment: shipment)
    nil
  end.compact

  return if params.empty?

  request_runner.call(:post, '/orders/createorders', params)
end