Class: SpreePacketa::Services::Tracker
- Inherits:
-
Object
- Object
- SpreePacketa::Services::Tracker
- Defined in:
- lib/spree_packeta/services/tracker.rb
Instance Attribute Summary collapse
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
-
#shipment ⇒ Object
readonly
Returns the value of attribute shipment.
Instance Method Summary collapse
-
#current_status ⇒ Hash
Get current status of the packet.
-
#initialize(shipment, operations = nil) ⇒ Tracker
constructor
A new instance of Tracker.
-
#needs_sync? ⇒ Boolean
Check if shipment needs status sync.
-
#sync_status! ⇒ Hash
Sync status from Packeta and update shipment.
-
#tracking_history ⇒ Array<Hash>
Get full tracking history.
Constructor Details
#initialize(shipment, operations = nil) ⇒ Tracker
Returns a new instance of Tracker.
8 9 10 11 |
# File 'lib/spree_packeta/services/tracker.rb', line 8 def initialize(shipment, operations = nil) @shipment = shipment @operations = operations || Soap::Operations.new end |
Instance Attribute Details
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
6 7 8 |
# File 'lib/spree_packeta/services/tracker.rb', line 6 def operations @operations end |
#shipment ⇒ Object (readonly)
Returns the value of attribute shipment.
6 7 8 |
# File 'lib/spree_packeta/services/tracker.rb', line 6 def shipment @shipment end |
Instance Method Details
#current_status ⇒ Hash
Get current status of the packet
17 18 19 20 21 22 23 |
# File 'lib/spree_packeta/services/tracker.rb', line 17 def current_status ensure_packet_exists! status = operations.packet_status(shipment.packeta_packet_id) update_shipment_status(status) status end |
#needs_sync? ⇒ Boolean
Check if shipment needs status sync
53 54 55 56 57 58 |
# File 'lib/spree_packeta/services/tracker.rb', line 53 def needs_sync? return true if shipment.packeta_last_sync_at.nil? sync_interval = SpreePacketa.configuration.tracking_sync_interval shipment.packeta_last_sync_at < sync_interval.seconds.ago end |
#sync_status! ⇒ Hash
Sync status from Packeta and update shipment
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spree_packeta/services/tracker.rb', line 38 def sync_status! status = current_status # Update last sync timestamp shipment.update!(packeta_last_sync_at: Time.current) # Update Spree shipment state based on Packeta status update_spree_shipment_state(status) status end |
#tracking_history ⇒ Array<Hash>
Get full tracking history
29 30 31 32 33 |
# File 'lib/spree_packeta/services/tracker.rb', line 29 def tracking_history ensure_packet_exists! operations.packet_tracking(shipment.packeta_packet_id) end |