Class: BrZipCode::Service
- Inherits:
-
Object
- Object
- BrZipCode::Service
- Defined in:
- lib/br_zip_code/service.rb,
lib/br_zip_code/service/viacep.rb,
lib/br_zip_code/service/postmon.rb,
lib/br_zip_code/service/cep_livre.rb,
lib/br_zip_code/service/correio_control.rb,
lib/br_zip_code/service/republica_virtual.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CepLivre, CorreioControl, Postmon, RepublicaVirtual, Viacep
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#zip_code ⇒ Object
Returns the value of attribute zip_code.
Instance Method Summary collapse
- #basic_valid? ⇒ Boolean
-
#initialize(zip_code, no_timeout = false) ⇒ Service
constructor
A new instance of Service.
- #valid? ⇒ Boolean
Constructor Details
#initialize(zip_code, no_timeout = false) ⇒ Service
Returns a new instance of Service.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/br_zip_code/service.rb', line 5 def initialize zip_code, no_timeout = false @zip_code = BrZipCode.strip(zip_code) return unless self.basic_valid? if no_timeout @response = HTTParty.get(final_url) else @response = HTTParty.get(final_url, timeout: BrZipCode.timeout) end @response_body = @response.response.body if self.valid? @response_body = JSON.parse(@response_body) end end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/br_zip_code/service.rb', line 3 def response @response end |
#response_body ⇒ Object
Returns the value of attribute response_body.
3 4 5 |
# File 'lib/br_zip_code/service.rb', line 3 def response_body @response_body end |
#zip_code ⇒ Object
Returns the value of attribute zip_code.
3 4 5 |
# File 'lib/br_zip_code/service.rb', line 3 def zip_code @zip_code end |
Instance Method Details
#basic_valid? ⇒ Boolean
23 24 25 |
# File 'lib/br_zip_code/service.rb', line 23 def basic_valid? @zip_code.length == 8 end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/br_zip_code/service.rb', line 27 def valid? not self.response.nil? and not self.response_body.nil? and not zip_code.nil? end |