Sha256: de5a96d4d6eab7731f90a62d7a571400cfcaee4b00e41db7b9c703d9e43d8f6a

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

module SolidusBactracs
  class ConsoleHarness
    attr_reader :runner, :syncer, :sync, :shipments, :shipments_elegible

    attr_accessor :cursor, :batch

    def initialize
      @runner = SolidusBactracs::Api::RequestRunner.new
      @syncer = SolidusBactracs::Api::BatchSyncer.from_config
      @sync = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new
      @shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
      @shipments_elegible = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.all_eligible_shipments
      @cursor = 0
      @batch = 4
    end

    def refresh
      @shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
    end

    def has_shipment?(id)
      @shipments.find_by(id: id)
    end

    def has_shipment_number?(ship_number)
      @shipments.find_by(number: ship_number)
    end

    def serialize(shipment)
      # SolidusShipstation::Api::ApplianceShipmentSerializer.new(shipment)
      @syncer.client.shipment_serializer.call(shipment, @runner.authenticate!)
    end

    def try_one(a_shipment = nil)
      puts "trying shipment #{(shipment = a_shipment || @shipments[@cursor]).id}"
      # resp = @runner.call(:post, '/orders/createorders', [serialize(shipment)])
      resp = @runner.authenticated_call(shipment: shipment, serializer: @syncer.client.shipment_serializer)
      if resp
        @cursor += 1
        return resp
      end
    ensure
      puts resp
    end

    def try_batch(batch_size=nil)
      b = [batch_size.to_i, @batch].max
      b.times do
        break unless try_one
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_bactracs-3.5.1 lib/solidus_bactracs/console_harness.rb
solidus_bactracs-3.5.0 lib/solidus_bactracs/console_harness.rb
solidus_bactracs-3.4.0 lib/solidus_bactracs/console_harness.rb
solidus_bactracs-3.3.2 lib/solidus_bactracs/console_harness.rb