Class: Deliveries::Couriers::CorreosExpress::Pickups::Create::FormatParams
- Inherits:
-
Object
- Object
- Deliveries::Couriers::CorreosExpress::Pickups::Create::FormatParams
- Defined in:
- lib/deliveries/couriers/correos_express/pickups/create/format_params.rb
Instance Attribute Summary collapse
-
#parcels ⇒ Object
Returns the value of attribute parcels.
-
#pickup_date ⇒ Object
Returns the value of attribute pickup_date.
-
#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.
-
#time_interval ⇒ Object
Returns the value of attribute time_interval.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(sender:, receiver:, parcels:, reference_code:, pickup_date:, remarks:, time_interval: nil) ⇒ FormatParams
constructor
A new instance of FormatParams.
Constructor Details
#initialize(sender:, receiver:, parcels:, reference_code:, pickup_date:, remarks:, time_interval: nil) ⇒ FormatParams
Returns a new instance of FormatParams.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/deliveries/couriers/correos_express/pickups/create/format_params.rb', line 10 def initialize(sender:, receiver:, parcels:, reference_code:, pickup_date:, remarks:, time_interval: nil) self.sender = sender self.receiver = receiver self.parcels = parcels self.reference_code = reference_code self.pickup_date = pickup_date self.remarks = remarks self.time_interval = time_interval end |
Instance Attribute Details
#parcels ⇒ Object
Returns the value of attribute parcels.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/pickups/create/format_params.rb', line 7 def parcels @parcels end |
#pickup_date ⇒ Object
Returns the value of attribute pickup_date.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/pickups/create/format_params.rb', line 7 def pickup_date @pickup_date end |
#receiver ⇒ Object
Returns the value of attribute receiver.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/pickups/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/pickups/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/pickups/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/pickups/create/format_params.rb', line 7 def sender @sender end |
#time_interval ⇒ Object
Returns the value of attribute time_interval.
7 8 9 |
# File 'lib/deliveries/couriers/correos_express/pickups/create/format_params.rb', line 7 def time_interval @time_interval end |
Instance Method Details
#execute ⇒ Object
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 72 73 74 75 76 77 78 79 |
# File 'lib/deliveries/couriers/correos_express/pickups/create/format_params.rb', line 21 def execute postcode = format_postcode(sender.postcode, sender.country) params = { solicitante: CorreosExpress.config(:client_code), refRecogida: reference_code, fechaRecogida: pickup_date&.strftime('%d%m%Y') || '', clienteRecogida: receiver.address_id || CorreosExpress.config(:pickup_receiver_code), codRemit: sender.address_id || '', nomRemit: sender.name, nifRemit: '', dirRecog: sender.street, poblRecog: sender.city, cpRecog: postcode, contRecog: sender.name, tlfnoRecog: sender.phone, emailRecog: sender.email, codDest: receiver.address_id || CorreosExpress.config(:pickup_receiver_code), nomDest: receiver.name, dirDest: receiver.street, pobDest: receiver.city, cpDest: receiver.postcode, paisDest: receiver.country, contactoDest: receiver.name, tlfnoDest: receiver.phone, emailDest: receiver.email, bultos: parcels.to_s } unless CorreosExpress.test? custom_product = CorreosExpress.config("countries.#{sender.country.to_s.downcase}.product") params[:producto] = custom_product if custom_product end defaults = Defaults::PARAMS defaults = defaults.merge(params) if time_interval defaults[:horaDesde1] = format '%02d:00', time_interval.first defaults[:horaHasta1] = format '%02d:00', time_interval.last else # Try to set cutoff time for the sender postal code. begin cutoff_time = CutoffTime.new(country: sender.country, postcode: postcode).execute # Set only when cuttoff time is less than 19:00 (the default cutoff time in correos express) if cutoff_time.to_i < 19 defaults[:horaHasta1] = cutoff_time # Update start hour if the period if smaller than 2 hours min_start_hour = cutoff_time.to_i - 2 defaults[:horaDesde1] = format('%02d:00', min_start_hour) if defaults[:horaDesde1].to_i > min_start_hour end rescue Deliveries::Error => e Deliveries.logger&.error "Cannot obtain cutoff time: #{e.}" end end defaults.to_json end |