Class: Nfe::Resources::Addresses
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Nfe::Resources::Addresses
- Defined in:
- lib/nfe/resources/addresses.rb,
sig/nfe/resources/addresses.rbs
Overview
Address lookup against the :addresses data family
(+address.api.nfe.io/v2+). The host already embeds the API version, so
#api_version is "" and request paths are used verbatim.
All three lookups return an AddressLookupResponse wrapping the API
addresses array.
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #api_family ⇒ Symbol
-
#api_version ⇒ String
This family's host already embeds the API version, so no version segment is prefixed to the request path.
-
#lookup_by_postal_code(postal_code) ⇒ Nfe::AddressLookupResponse
Look up addresses by Brazilian postal code (CEP).
-
#lookup_by_term(term) ⇒ Nfe::AddressLookupResponse
Look up addresses by a free-text term.
-
#search(filter: nil) ⇒ Nfe::AddressLookupResponse
Search addresses with an opaque OData
$filterexpression.
Methods inherited from AbstractResource
#build_list_page, #build_multipart_body, #cursor_list_page, #delete, #dig_key, #download, #extract_invoice_id, #full_path, #get, #handle_async_response, #hydrate, #hydrate_list, #initialize, #multipart_part, #page_list_page, #parse_json, #post, #put, #unwrap, #upload_multipart
Constructor Details
This class inherits a constructor from Nfe::Resources::AbstractResource
Instance Method Details
#api_family ⇒ Symbol
52 53 54 |
# File 'lib/nfe/resources/addresses.rb', line 52 def api_family :addresses end |
#api_version ⇒ String
This family's host already embeds the API version, so no version segment is prefixed to the request path.
58 59 60 |
# File 'lib/nfe/resources/addresses.rb', line 58 def api_version "" end |
#lookup_by_postal_code(postal_code) ⇒ Nfe::AddressLookupResponse
Look up addresses by Brazilian postal code (CEP).
21 22 23 24 25 |
# File 'lib/nfe/resources/addresses.rb', line 21 def lookup_by_postal_code(postal_code) cep = Nfe::IdValidator.cep(postal_code) response = get("/addresses/#{cep}") hydrate(Nfe::AddressLookupResponse, parse_json(response.body)) end |
#lookup_by_term(term) ⇒ Nfe::AddressLookupResponse
Look up addresses by a free-text term.
43 44 45 46 47 48 |
# File 'lib/nfe/resources/addresses.rb', line 43 def lookup_by_term(term) raise Nfe::InvalidRequestError, "termo (term) não pode ser vazio" if term.to_s.strip.empty? response = get("/addresses/#{CGI.escape(term.strip)}") hydrate(Nfe::AddressLookupResponse, parse_json(response.body)) end |
#search(filter: nil) ⇒ Nfe::AddressLookupResponse
Search addresses with an opaque OData $filter expression.
31 32 33 34 35 36 |
# File 'lib/nfe/resources/addresses.rb', line 31 def search(filter: nil) query = {} #: Hash[String, untyped] query["$filter"] = filter unless filter.nil? response = get("/addresses", query: query) hydrate(Nfe::AddressLookupResponse, parse_json(response.body)) end |