Sha256: 82ef08488f990a388e42ba20fb637f30c4090c45fa5b29b69efa547ed0021b84

Contents?: true

Size: 943 Bytes

Versions: 2

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module SolidusBactracs
  module Api
    class BatchSyncer
      class << self
        def from_config
          new(
            client: SolidusBactracs::Api::Client.from_config,
            shipment_matcher: SolidusBactracs.config.api_shipment_matcher,
          )
        end
      end

      attr_reader :client, :shipment_matcher

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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_bactracs-4.0.1 lib/solidus_bactracs/api/batch_syncer.rb
solidus_bactracs-4.0.0 lib/solidus_bactracs/api/batch_syncer.rb