Class: Deliveries::Couriers::CorreosExpress::CollectionPoints::Search
- Inherits:
-
Object
- Object
- Deliveries::Couriers::CorreosExpress::CollectionPoints::Search
- Includes:
- HTTParty
- Defined in:
- lib/deliveries/couriers/correos_express/collection_points/search.rb,
lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb
Defined Under Namespace
Classes: FormatResponse
Instance Attribute Summary collapse
-
#postcode ⇒ Object
Returns the value of attribute postcode.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(postcode:) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(postcode:) ⇒ Search
Returns a new instance of Search.
12 13 14 |
# File 'lib/deliveries/couriers/correos_express/collection_points/search.rb', line 12 def initialize(postcode:) self.postcode = postcode end |
Instance Attribute Details
#postcode ⇒ Object
Returns the value of attribute postcode.
10 11 12 |
# File 'lib/deliveries/couriers/correos_express/collection_points/search.rb', line 10 def postcode @postcode 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 |
# File 'lib/deliveries/couriers/correos_express/collection_points/search.rb', line 16 def execute auth = { username: CorreosExpress.config(:username), password: CorreosExpress.config(:password) } headers = { 'Content-Type' => 'application/json;charset=UTF-8', 'Accept' => 'application/json' } response = self.class.post( api_endpoint, basic_auth: auth, body: { cod_postal: postcode }.to_json, headers: headers, debug_output: Deliveries.debug ? Deliveries.logger : nil ) parsed_response = JSON.parse(response.body) if parsed_response['tipoRespuesta'] == 'KO' raise Deliveries::APIError.new( parsed_response['listaErrores'].first['descError'], parsed_response['listaErrores'].first['codError'] ) end parsed_response['oficinas'] end |