Class: ViaCep::SearchByAddress
- Defined in:
- lib/via_cep/search_by_address.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#street ⇒ Object
readonly
Returns the value of attribute street.
Instance Method Summary collapse
-
#initialize(state:, city:, street:) ⇒ SearchByAddress
constructor
Initialize an instance of ViaCep::SearchByAddress and retrieve the CEP using the ViaCep WS API.
Methods inherited from Instance
Constructor Details
#initialize(state:, city:, street:) ⇒ SearchByAddress
Initialize an instance of ViaCep::SearchByAddress and retrieve the CEP using the ViaCep WS API.
Search for a zipcode through the address
ViaCep::SearchByAddress.new(state: 'SP', city: 'Sao Paulo', street: 'Praca da Se')
#=> #<ViaCep::SearchByAddress:0x000055e542d90210 @state="SP", @city="Sao Paulo", @street="Praca da Se",
@zipcode="01001-000", @complement="lado impar", @neighborhood="Se", @ibge="3550308", @gia="1004", @error=nil>
raise [ViaCep::Errors::InvalidAddressFormat] Error raised when there is any address field empty. raise [ViaCep::Errors::InvalidStateFormat] Error raised when the state is not a valid one
return [ViaCep::SearchByAddress]
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/via_cep/search_by_address.rb', line 21 def initialize(state:, city:, street:) @state = state @city = city @street = street valid? call_service rescue JSON::ParserError, Net::HTTPBadRequest raise ViaCep::Errors::AddressNotFound end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
5 6 7 |
# File 'lib/via_cep/search_by_address.rb', line 5 def city @city end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/via_cep/search_by_address.rb', line 5 def state @state end |
#street ⇒ Object (readonly)
Returns the value of attribute street.
5 6 7 |
# File 'lib/via_cep/search_by_address.rb', line 5 def street @street end |