Class: Deliveries::Couriers::CorreosExpress::Shipments::Create::FormatParams
- Inherits:
-
Object
- Object
- Deliveries::Couriers::CorreosExpress::Shipments::Create::FormatParams
- Defined in:
- lib/deliveries/couriers/correos_express/shipments/create/format_params.rb
Constant Summary collapse
- NATIONAL_COUNTRY =
:es
Instance Attribute Summary collapse
-
#collection_point ⇒ Object
Returns the value of attribute collection_point.
-
#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.
-
#remarks ⇒ Object
Returns the value of attribute remarks.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#shipment_date ⇒ Object
Returns the value of attribute shipment_date.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(sender:, receiver:, collection_point:, parcels:, reference_code:, shipment_date:, remarks:) ⇒ FormatParams
constructor
A new instance of FormatParams.
Constructor Details
#initialize(sender:, receiver:, collection_point:, parcels:, reference_code:, shipment_date:, remarks:) ⇒ FormatParams
Returns a new instance of FormatParams.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 12 def initialize(sender:, receiver:, collection_point:, parcels:, reference_code:, shipment_date:, remarks:) self.sender = sender self.receiver = receiver self.collection_point = collection_point self.parcels = parcels self.reference_code = reference_code self.shipment_date = shipment_date self.remarks = remarks end |
Instance Attribute Details
#collection_point ⇒ Object
Returns the value of attribute collection_point.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 7 def collection_point @collection_point end |
#parcels ⇒ Object
Returns the value of attribute parcels.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/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/correos_express/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/correos_express/shipments/create/format_params.rb', line 7 def reference_code @reference_code end |
#remarks ⇒ Object
Returns the value of attribute remarks.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 7 def remarks @remarks end |
#sender ⇒ Object
Returns the value of attribute sender.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 7 def sender @sender end |
#shipment_date ⇒ Object
Returns the value of attribute shipment_date.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 7 def shipment_date @shipment_date end |
Instance Method Details
#execute ⇒ Object
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 72 73 74 |
# File 'lib/deliveries/couriers/correos_express/shipments/create/format_params.rb', line 23 def execute params = { solicitante: CorreosExpress.config(:client_code), codRte: sender.address_id || CorreosExpress.config(:shipment_sender_code), ref: reference_code, fecha: format_date(shipment_date), nomRte: sender.name, dirRte: sender.street, pobRte: sender.city, paisISORte: sender.country.to_s, contacRte: sender.name, telefRte: sender.phone, emailRte: sender.email, codDest: receiver.address_id || '', nomDest: receiver.name, dirDest: receiver.street, pobDest: receiver.city, paisISODest: receiver.country.to_s, contacDest: receiver.name, telefDest: receiver.phone, emailDest: receiver.email, numBultos: parcels.to_s, observac: remarks&.truncate(50, omission: '') } if collection_point.present? params = params.merge( codDirecDestino: collection_point.point_id ) end params = if national_country?(sender.country) params.merge(codPosNacRte: format_postcode(sender.postcode, sender.country)) else params.merge(codPosIntRte: format_postcode(sender.postcode, sender.country)) end params = if national_country?(receiver.country) params.merge(codPosNacDest: format_postcode(receiver.postcode, receiver.country)) else params.merge(codPosIntDest: format_postcode(receiver.postcode, receiver.country)) end unless CorreosExpress.test? custom_product = CorreosExpress.config("countries.#{receiver.country.to_s.downcase}.product") params[:producto] = custom_product if custom_product end defaults = Defaults::PARAMS defaults.merge(params).to_json end |