Class: SolidusBactracs::ConsoleHarness

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConsoleHarness

Returns a new instance of ConsoleHarness.



7
8
9
10
11
12
13
14
15
# File 'lib/solidus_bactracs/console_harness.rb', line 7

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

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



5
6
7
# File 'lib/solidus_bactracs/console_harness.rb', line 5

def batch
  @batch
end

#cursorObject

Returns the value of attribute cursor.



5
6
7
# File 'lib/solidus_bactracs/console_harness.rb', line 5

def cursor
  @cursor
end

#runnerObject (readonly)

Returns the value of attribute runner.



3
4
5
# File 'lib/solidus_bactracs/console_harness.rb', line 3

def runner
  @runner
end

#shipmentsObject (readonly)

Returns the value of attribute shipments.



3
4
5
# File 'lib/solidus_bactracs/console_harness.rb', line 3

def shipments
  @shipments
end

#shipments_elegibleObject (readonly)

Returns the value of attribute shipments_elegible.



3
4
5
# File 'lib/solidus_bactracs/console_harness.rb', line 3

def shipments_elegible
  @shipments_elegible
end

#syncObject (readonly)

Returns the value of attribute sync.



3
4
5
# File 'lib/solidus_bactracs/console_harness.rb', line 3

def sync
  @sync
end

#syncerObject (readonly)

Returns the value of attribute syncer.



3
4
5
# File 'lib/solidus_bactracs/console_harness.rb', line 3

def syncer
  @syncer
end

Instance Method Details

#has_shipment?(id) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/solidus_bactracs/console_harness.rb', line 21

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

#has_shipment_number?(ship_number) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/solidus_bactracs/console_harness.rb', line 25

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

#refreshObject



17
18
19
# File 'lib/solidus_bactracs/console_harness.rb', line 17

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

#serialize(shipment) ⇒ Object



29
30
31
32
# File 'lib/solidus_bactracs/console_harness.rb', line 29

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

#try_batch(batch_size = nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/solidus_bactracs/console_harness.rb', line 46

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

#try_one(a_shipment = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/solidus_bactracs/console_harness.rb', line 34

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 if (a_shipment == @shipments[@cursor] || shipment == @shipments[@cursor])
    return resp
  end
ensure
  puts resp
end