Class: Deliveries::Couriers::Spring::Shipments::Create
- Inherits:
-
Object
- Object
- Deliveries::Couriers::Spring::Shipments::Create
- Defined in:
- lib/deliveries/couriers/spring/shipments/create.rb,
lib/deliveries/couriers/spring/shipments/create/defaults.rb,
lib/deliveries/couriers/spring/shipments/create/format_params.rb
Defined Under Namespace
Modules: Defaults Classes: FormatParams
Instance Attribute Summary collapse
-
#parcels ⇒ Object
Returns the value of attribute parcels.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
-
#reference_code ⇒ Object
Returns the value of attribute reference_code.
-
#sender ⇒ Object
Returns the value of attribute sender.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(sender:, receiver:, parcels:, reference_code:) ⇒ Create
constructor
A new instance of Create.
Constructor Details
#initialize(sender:, receiver:, parcels:, reference_code:) ⇒ Create
Returns a new instance of Create.
8 9 10 11 12 13 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 8 def initialize(sender:, receiver:, parcels:, reference_code:) self.sender = sender self.receiver = receiver self.parcels = parcels self.reference_code = reference_code end |
Instance Attribute Details
#parcels ⇒ Object
Returns the value of attribute parcels.
6 7 8 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 6 def parcels @parcels end |
#receiver ⇒ Object
Returns the value of attribute receiver.
6 7 8 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 6 def receiver @receiver end |
#reference_code ⇒ Object
Returns the value of attribute reference_code.
6 7 8 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 6 def reference_code @reference_code end |
#sender ⇒ Object
Returns the value of attribute sender.
6 7 8 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 6 def sender @sender end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deliveries/couriers/spring/shipments/create.rb', line 15 def execute params = Deliveries::Couriers::Spring::Shipments::Create::FormatParams.new( sender: sender.courierize(:spring), receiver: receiver.courierize(:spring), parcels: parcels, reference_code: reference_code ).execute response = Deliveries::Couriers::Spring::Request.execute(params: params) tracking_code = response[:Shipment][:TrackingNumber] label = Label.new( url: response[:Shipment][:CarrierTrackingUrl], raw: Base64.decode64(response[:Shipment][:LabelImage]).force_encoding('binary') ) Deliveries::Delivery.new( courier_id: Deliveries::Couriers::Spring::COURIER_ID, sender: sender, receiver: receiver, parcels: parcels, reference_code: reference_code, tracking_code: tracking_code, label: label ) end |