Class: SolidusBactracs::ConsoleHarness
- Inherits:
-
Object
- Object
- SolidusBactracs::ConsoleHarness
- Defined in:
- lib/solidus_bactracs/console_harness.rb
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#shipments ⇒ Object
readonly
Returns the value of attribute shipments.
-
#shipments_elegible ⇒ Object
readonly
Returns the value of attribute shipments_elegible.
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
-
#syncer ⇒ Object
readonly
Returns the value of attribute syncer.
Instance Method Summary collapse
- #has_shipment?(id) ⇒ Boolean
- #has_shipment_number?(ship_number) ⇒ Boolean
-
#initialize ⇒ ConsoleHarness
constructor
A new instance of ConsoleHarness.
- #refresh ⇒ Object
- #serialize(shipment) ⇒ Object
- #try_batch(batch_size = nil) ⇒ Object
- #try_one(a_shipment = nil) ⇒ Object
Constructor Details
#initialize ⇒ ConsoleHarness
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
#batch ⇒ Object
Returns the value of attribute batch.
5 6 7 |
# File 'lib/solidus_bactracs/console_harness.rb', line 5 def batch @batch end |
#cursor ⇒ Object
Returns the value of attribute cursor.
5 6 7 |
# File 'lib/solidus_bactracs/console_harness.rb', line 5 def cursor @cursor end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
3 4 5 |
# File 'lib/solidus_bactracs/console_harness.rb', line 3 def runner @runner end |
#shipments ⇒ Object (readonly)
Returns the value of attribute shipments.
3 4 5 |
# File 'lib/solidus_bactracs/console_harness.rb', line 3 def shipments @shipments end |
#shipments_elegible ⇒ Object (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 |
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
3 4 5 |
# File 'lib/solidus_bactracs/console_harness.rb', line 3 def sync @sync end |
#syncer ⇒ Object (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
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
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 |
#refresh ⇒ Object
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 |