Class: Nfe::Resources::StateTaxes
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Nfe::Resources::StateTaxes
- Defined in:
- lib/nfe/resources/state_taxes.rb,
sig/nfe/resources/state_taxes.rbs
Overview
Company state-tax (Inscrição Estadual) registrations for the :cte host
family (+https://api.nfse.io/v2/companies/companyId/statetaxes+). Exposes
the full CRUD: list (cursor-style), create, retrieve, update and delete.
The API wraps single state-tax objects in a {"stateTax" => <object>}
envelope (and the list in {"stateTaxes" => [...]}), transparently
unwrapped here before hydrating NfeStateTax.
Constant Summary collapse
- ENVELOPE =
Envelope key for a single state-tax object.
"stateTax"- LIST_ENVELOPE =
Wrapper key for the list envelope.
"stateTaxes"
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #api_family ⇒ Symbol
-
#api_version ⇒ String
The
:ctehost (+api.nfse.io+) does not bake in a version; the/v2segment is carried in the base path instead. - #base_path(company_id) ⇒ String
-
#create(company_id, data) ⇒ Nfe::NfeStateTax
Create a state-tax registration.
-
#delete(company_id, state_tax_id) ⇒ nil
Delete a state-tax registration.
- #json_headers ⇒ Hash[String, String]
-
#list(company_id, starting_after: nil, ending_before: nil, limit: nil) ⇒ Nfe::ListResponse
List a company's state-tax registrations (cursor-style pagination).
-
#retrieve(company_id, state_tax_id) ⇒ Nfe::NfeStateTax
Retrieve a single state-tax registration.
-
#update(company_id, state_tax_id, data) ⇒ Nfe::NfeStateTax
Update a state-tax registration.
Methods inherited from AbstractResource
#build_list_page, #build_multipart_body, #cursor_list_page, #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
28 29 30 |
# File 'lib/nfe/resources/state_taxes.rb', line 28 def api_family :cte end |
#api_version ⇒ String
The :cte host (+api.nfse.io+) does not bake in a version; the /v2
segment is carried in the base path instead.
34 35 36 |
# File 'lib/nfe/resources/state_taxes.rb', line 34 def api_version "" end |
#base_path(company_id) ⇒ String
109 110 111 |
# File 'lib/nfe/resources/state_taxes.rb', line 109 def base_path(company_id) "/v2/companies/#{company_id}/statetaxes" end |
#create(company_id, data) ⇒ Nfe::NfeStateTax
Create a state-tax registration.
62 63 64 65 66 67 |
# File 'lib/nfe/resources/state_taxes.rb', line 62 def create(company_id, data) cid = Nfe::IdValidator.company_id(company_id) response = post(base_path(cid), body: JSON.generate({ ENVELOPE => data }), headers: json_headers) hydrate(Nfe::NfeStateTax, unwrap(parse_json(response.body), ENVELOPE)) end |
#delete(company_id, state_tax_id) ⇒ nil
Delete a state-tax registration.
100 101 102 103 104 105 |
# File 'lib/nfe/resources/state_taxes.rb', line 100 def delete(company_id, state_tax_id) cid = Nfe::IdValidator.company_id(company_id) sid = Nfe::IdValidator.state_tax_id(state_tax_id) super("#{base_path(cid)}/#{sid}") nil end |
#json_headers ⇒ Hash[String, String]
113 114 115 |
# File 'lib/nfe/resources/state_taxes.rb', line 113 def json_headers { "Content-Type" => "application/json" } end |
#list(company_id, starting_after: nil, ending_before: nil, limit: nil) ⇒ Nfe::ListResponse
List a company's state-tax registrations (cursor-style pagination).
47 48 49 50 51 52 53 54 55 |
# File 'lib/nfe/resources/state_taxes.rb', line 47 def list(company_id, starting_after: nil, ending_before: nil, limit: nil) cid = Nfe::IdValidator.company_id(company_id) query = {} #: Hash[String, untyped] query["startingAfter"] = starting_after unless starting_after.nil? query["endingBefore"] = ending_before unless ending_before.nil? query["limit"] = limit unless limit.nil? response = get(base_path(cid), query: query) hydrate_list(Nfe::NfeStateTax, parse_json(response.body), wrapper_key: LIST_ENVELOPE) end |
#retrieve(company_id, state_tax_id) ⇒ Nfe::NfeStateTax
Retrieve a single state-tax registration.
74 75 76 77 78 79 |
# File 'lib/nfe/resources/state_taxes.rb', line 74 def retrieve(company_id, state_tax_id) cid = Nfe::IdValidator.company_id(company_id) sid = Nfe::IdValidator.state_tax_id(state_tax_id) response = get("#{base_path(cid)}/#{sid}") hydrate(Nfe::NfeStateTax, unwrap(parse_json(response.body), ENVELOPE)) end |
#update(company_id, state_tax_id, data) ⇒ Nfe::NfeStateTax
Update a state-tax registration.
87 88 89 90 91 92 93 |
# File 'lib/nfe/resources/state_taxes.rb', line 87 def update(company_id, state_tax_id, data) cid = Nfe::IdValidator.company_id(company_id) sid = Nfe::IdValidator.state_tax_id(state_tax_id) response = put("#{base_path(cid)}/#{sid}", body: JSON.generate({ ENVELOPE => data }), headers: json_headers) hydrate(Nfe::NfeStateTax, unwrap(parse_json(response.body), ENVELOPE)) end |