Class: Deliveries::Couriers::CorreosExpress::Pickups::CutoffTime
- Inherits:
-
Object
- Object
- Deliveries::Couriers::CorreosExpress::Pickups::CutoffTime
- Includes:
- HTTParty
- Defined in:
- lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb,
lib/deliveries/couriers/correos_express/pickups/cutoff_time/format_params.rb
Defined Under Namespace
Classes: FormatParams
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#postcode ⇒ Object
Returns the value of attribute postcode.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(country:, postcode:) ⇒ CutoffTime
constructor
A new instance of CutoffTime.
Constructor Details
#initialize(country:, postcode:) ⇒ CutoffTime
Returns a new instance of CutoffTime.
12 13 14 15 |
# File 'lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb', line 12 def initialize(country:, postcode:) self.country = country self.postcode = postcode end |
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
10 11 12 |
# File 'lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb', line 10 def country @country end |
#postcode ⇒ Object
Returns the value of attribute postcode.
10 11 12 |
# File 'lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb', line 10 def postcode @postcode end |
Instance Method Details
#execute ⇒ Object
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 |
# File 'lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb', line 17 def execute auth = { username: CorreosExpress.config(:username), password: CorreosExpress.config(:password) } params = FormatParams.new( country: country, postcode: postcode ).execute response = self.class.post( api_endpoint, basic_auth: auth, body: params, headers: headers, debug_output: Deliveries.debug ? Deliveries.logger : nil ) raise Deliveries::Error unless response.success? parsed_response = JSON.parse(response.body, symbolize_names: true) if (parsed_response[:codError]).zero? && parsed_response[:horaCorte].present? parsed_response[:horaCorte] else raise Deliveries::APIError.new( parsed_response[:mensError], parsed_response[:codError] ) end end |