Class: SpreePacketa::Services::PacketCreator
- Inherits:
-
Object
- Object
- SpreePacketa::Services::PacketCreator
- Defined in:
- lib/spree_packeta/services/packet_creator.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
-
#create_packet ⇒ Hash
Create a Packeta packet from a Spree shipment.
-
#initialize(shipment, operations = nil) ⇒ PacketCreator
constructor
A new instance of PacketCreator.
Constructor Details
#initialize(shipment, operations = nil) ⇒ PacketCreator
Returns a new instance of PacketCreator.
8 9 10 11 |
# File 'lib/spree_packeta/services/packet_creator.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/packet_creator.rb', line 6 def operations @operations end |
#shipment ⇒ Object (readonly)
Returns the value of attribute shipment.
6 7 8 |
# File 'lib/spree_packeta/services/packet_creator.rb', line 6 def shipment @shipment end |
Instance Method Details
#create_packet ⇒ Hash
Create a Packeta packet from a Spree shipment
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/spree_packeta/services/packet_creator.rb', line 17 def create_packet raise ValidationError, 'Shipment already has a Packeta packet' if shipment.packeta_packet_id.present? # Extract attributes from shipment attributes = build_packet_attributes # Validate attributes first operations.packet_attributes_valid?(attributes) # Create the packet result = operations.create_packet(attributes) # Update shipment with packet details update_shipment_with_packet(result) result rescue ValidationError => e Rails.logger.error("Failed to create Packeta packet for shipment #{shipment.id}: #{e.}") raise end |