Class: SolidusBactracs::Api::BatchSyncer

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_bactracs/api/batch_syncer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, shipment_matcher:) ⇒ BatchSyncer

Returns a new instance of BatchSyncer.



17
18
19
20
# File 'lib/solidus_bactracs/api/batch_syncer.rb', line 17

def initialize(client:, shipment_matcher:)
  @client = client
  @shipment_matcher = shipment_matcher
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/solidus_bactracs/api/batch_syncer.rb', line 15

def client
  @client
end

#shipment_matcherObject (readonly)

Returns the value of attribute shipment_matcher.



15
16
17
# File 'lib/solidus_bactracs/api/batch_syncer.rb', line 15

def shipment_matcher
  @shipment_matcher
end

Class Method Details

.from_configObject



7
8
9
10
11
12
# File 'lib/solidus_bactracs/api/batch_syncer.rb', line 7

def from_config
  new(
    client: SolidusBactracs::Api::Client.from_config,
    shipment_matcher: SolidusBactracs.config.api_shipment_matcher,
  )
end

Instance Method Details

#call(shipments) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solidus_bactracs/api/batch_syncer.rb', line 22

def call(shipments)
  begin
    response = client.bulk_create_orders(shipments)
  rescue RateLimitedError => e
    ::Spree::Bus.publish(:'solidus_bactracs.api.rate_limited', shipments: shipments, error: e)
    raise e
  rescue RequestError => e
    ::Spree::Bus.publish(:'solidus_bactracs.api.sync_errored', shipments: shipments, error: e)

    raise e
  end
end