Class: Nfe::Resources::LegalEntityLookup

Inherits:
AbstractResource show all
Defined in:
lib/nfe/resources/legal_entity_lookup.rb,
sig/nfe/resources/legal_entity_lookup.rbs

Overview

Legal-entity (pessoa jurídica) lookup against the :legal_entity data family (+legalentity.api.nfe.io+). The version segment is embedded in each request path (+/v2/legalentities/...+), so #api_version is "".

Instance Attribute Summary

Attributes inherited from AbstractResource

#client

Instance Method Summary collapse

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_familySymbol

Returns:

  • (Symbol)


67
68
69
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 67

def api_family
  :legal_entity
end

#api_versionString

The version segment is embedded in each request path, so no version prefix is added by AbstractResource#full_path.

Returns:

  • (String)


73
74
75
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 73

def api_version
  ""
end

#get_basic_info(federal_tax_number, update_address: nil, update_city_code: nil) ⇒ Nfe::LegalEntityBasicInfoResponse

Retrieve basic registration info for a CNPJ.

Parameters:

  • federal_tax_number (String)

    CNPJ in any format.

  • update_address (Boolean, nil) (defaults to: nil)

    forwarded as updateAddress when set.

  • update_city_code (Boolean, nil) (defaults to: nil)

    forwarded as updateCityCode when set.

  • update_address: (Object) (defaults to: nil)
  • update_city_code: (Object) (defaults to: nil)

Returns:

Raises:



19
20
21
22
23
24
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 19

def get_basic_info(federal_tax_number, update_address: nil, update_city_code: nil)
  cnpj = Nfe::IdValidator.cnpj(federal_tax_number)
  query = { "updateAddress" => update_address, "updateCityCode" => update_city_code }.compact
  response = get("/v2/legalentities/basicInfo/#{cnpj}", query: query)
  hydrate(Nfe::LegalEntityBasicInfoResponse, parse_json(response.body))
end

#get_state_tax_for_invoice(state, federal_tax_number) ⇒ Nfe::LegalEntityStateTaxForInvoiceResponse

Retrieve the state-tax info suitable for invoicing.

Parameters:

  • state (String)

    UF (case-insensitive).

  • federal_tax_number (String)

    CNPJ in any format.

Returns:

Raises:



45
46
47
48
49
50
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 45

def get_state_tax_for_invoice(state, federal_tax_number)
  uf = Nfe::IdValidator.state(state)
  cnpj = Nfe::IdValidator.cnpj(federal_tax_number)
  response = get("/v2/legalentities/stateTaxForInvoice/#{uf}/#{cnpj}")
  hydrate(Nfe::LegalEntityStateTaxForInvoiceResponse, parse_json(response.body))
end

#get_state_tax_info(state, federal_tax_number) ⇒ Nfe::LegalEntityStateTaxResponse

Retrieve state-tax registration info for a state + CNPJ.

Parameters:

  • state (String)

    UF (case-insensitive).

  • federal_tax_number (String)

    CNPJ in any format.

Returns:

Raises:



32
33
34
35
36
37
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 32

def get_state_tax_info(state, federal_tax_number)
  uf = Nfe::IdValidator.state(state)
  cnpj = Nfe::IdValidator.cnpj(federal_tax_number)
  response = get("/v2/legalentities/stateTaxInfo/#{uf}/#{cnpj}")
  hydrate(Nfe::LegalEntityStateTaxResponse, parse_json(response.body))
end

#get_suggested_state_tax_for_invoice(state, federal_tax_number) ⇒ Nfe::LegalEntityStateTaxForInvoiceResponse

Retrieve the suggested state-tax info for invoicing.

Parameters:

  • state (String)

    UF (case-insensitive).

  • federal_tax_number (String)

    CNPJ in any format.

Returns:

Raises:



58
59
60
61
62
63
# File 'lib/nfe/resources/legal_entity_lookup.rb', line 58

def get_suggested_state_tax_for_invoice(state, federal_tax_number)
  uf = Nfe::IdValidator.state(state)
  cnpj = Nfe::IdValidator.cnpj(federal_tax_number)
  response = get("/v2/legalentities/stateTaxSuggestedForInvoice/#{uf}/#{cnpj}")
  hydrate(Nfe::LegalEntityStateTaxForInvoiceResponse, parse_json(response.body))
end