Class: Deliveries::Couriers::Spring::Shipments::Create::FormatParams
- Inherits:
-
Object
- Object
- Deliveries::Couriers::Spring::Shipments::Create::FormatParams
- Defined in:
- lib/deliveries/couriers/spring/shipments/create/format_params.rb
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:) ⇒ FormatParams
constructor
A new instance of FormatParams.
Constructor Details
#initialize(sender:, receiver:, parcels:, reference_code:) ⇒ FormatParams
Returns a new instance of FormatParams.
9 10 11 12 13 14 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 9 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.
7 8 9 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 7 def parcels @parcels end |
#receiver ⇒ Object
Returns the value of attribute receiver.
7 8 9 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 7 def receiver @receiver end |
#reference_code ⇒ Object
Returns the value of attribute reference_code.
7 8 9 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 7 def reference_code @reference_code end |
#sender ⇒ Object
Returns the value of attribute sender.
7 8 9 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 7 def sender @sender end |
Instance Method Details
#execute ⇒ Object
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/deliveries/couriers/spring/shipments/create/format_params.rb', line 16 def execute shipment = { ShipperReference: reference_code, Service: Deliveries::Couriers::Spring.config("countries.#{receiver.country.downcase.to_sym}.service") } # Consignor address (from). shipment[:ConsignorAddress] = { Name: sender.name, Company: sender.name, AddressLine1: sender.street, AddressLine2: sender.street2, AddressLine3: sender.street3, City: sender.city, State: sender.state, Zip: sender.postcode, Country: sender.country, Phone: sender.phone, Email: sender.email } # Consignee address (to). shipment[:ConsigneeAddress] = { Name: receiver.name, Company: '', AddressLine1: receiver.street, AddressLine2: receiver.street2, AddressLine3: receiver.street3, City: receiver.city, State: receiver.state, Zip: receiver.postcode, Country: receiver.country, Phone: receiver.phone, Email: receiver.email } # Products collection. shipment[:Products] = 1.upto(parcels).map do { Description: Deliveries::Couriers::Spring.config('default_product.description'), Sku: '', HsCode: Deliveries::Couriers::Spring.config('default_product.hs_code'), OriginCountry: Deliveries::Couriers::Spring.config('default_product.origin_country'), PurchaseUrl: '', Quantity: Deliveries::Couriers::Spring.config('default_product.quantity'), Value: Deliveries::Couriers::Spring.config('default_product.value') } end params = { Apikey: Deliveries::Couriers::Spring.config(:api_key), Shipment: shipment } Defaults::PARAMS.deep_merge(params) end |