Class: SpreePacketa::Soap::Operations
- Inherits:
-
Object
- Object
- SpreePacketa::Soap::Operations
- Defined in:
- lib/spree_packeta/soap/operations.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#cancel_packet(packet_id) ⇒ Boolean
Cancel a packet (if allowed).
-
#create_packet(attributes) ⇒ Hash
Create a new packet.
-
#initialize(client = nil) ⇒ Operations
constructor
A new instance of Operations.
-
#packet_attributes_valid?(attributes) ⇒ Boolean
Validate packet attributes before creating a packet.
-
#packet_label_pdf(packet_id, format: 'A7 on A4', offset: 0) ⇒ String
Get packet label as PDF.
-
#packet_status(packet_id) ⇒ Hash
Get current status of a packet.
-
#packet_tracking(packet_id) ⇒ Array<Hash>
Get full tracking history for a packet.
Constructor Details
#initialize(client = nil) ⇒ Operations
Returns a new instance of Operations.
8 9 10 |
# File 'lib/spree_packeta/soap/operations.rb', line 8 def initialize(client = nil) @client = client || Client.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/spree_packeta/soap/operations.rb', line 6 def client @client end |
Instance Method Details
#cancel_packet(packet_id) ⇒ Boolean
Cancel a packet (if allowed)
98 99 100 101 |
# File 'lib/spree_packeta/soap/operations.rb', line 98 def cancel_packet(packet_id) client.call(:cancel_packet, packet_id: packet_id) true end |
#create_packet(attributes) ⇒ Hash
Create a new packet
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spree_packeta/soap/operations.rb', line 39 def create_packet(attributes) response = client.call(:create_packet, attributes: packet_attributes_hash(attributes)) result = response.body[:create_packet_response][:create_packet_result] { id: result[:id], barcode: result[:barcode], barcode_text: result[:barcode_text] } end |
#packet_attributes_valid?(attributes) ⇒ Boolean
Validate packet attributes before creating a packet
17 18 19 20 21 22 23 |
# File 'lib/spree_packeta/soap/operations.rb', line 17 def packet_attributes_valid?(attributes) response = client.call(:packet_attributes_valid, attributes: packet_attributes_hash(attributes)) true rescue ValidationError => e Rails.logger.error("Packet attributes validation failed: #{e.}") raise end |
#packet_label_pdf(packet_id, format: 'A7 on A4', offset: 0) ⇒ String
Get packet label as PDF
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/spree_packeta/soap/operations.rb', line 109 def packet_label_pdf(packet_id, format: 'A7 on A4', offset: 0) response = client.call( :packet_label_pdf, packet_id: packet_id, format: format, offset: offset ) response.body[:packet_label_pdf_response][:packet_label_pdf_result] end |
#packet_status(packet_id) ⇒ Hash
Get current status of a packet
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/spree_packeta/soap/operations.rb', line 55 def packet_status(packet_id) response = client.call(:packet_status, packet_id: packet_id) result = response.body[:packet_status_response][:packet_status_result] { date_time: result[:date_time], status_code: result[:status_code], code_text: result[:code_text], status_text: result[:status_text], branch_id: result[:branch_id], destination_branch_id: result[:destination_branch_id], is_returning: result[:is_returning], stored_until: result[:stored_until] } end |
#packet_tracking(packet_id) ⇒ Array<Hash>
Get full tracking history for a packet
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/spree_packeta/soap/operations.rb', line 76 def packet_tracking(packet_id) response = client.call(:packet_tracking, packet_id: packet_id) records = response.body[:packet_tracking_response][:packet_tracking_result][:record] records = [records] unless records.is_a?(Array) # Handle single record records.map do |record| { date_time: record[:date_time], status_code: record[:status_code], code_text: record[:code_text], status_text: record[:status_text], branch_id: record[:branch_id], destination_branch_id: record[:destination_branch_id] } end end |