Class: Nfe::Resources::TransportationInvoices
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Nfe::Resources::TransportationInvoices
- Defined in:
- lib/nfe/resources/transportation_invoices.rb,
sig/nfe/resources/transportation_invoices.rbs
Overview
Inbound CT-e (Conhecimento de Transporte Eletrônico) resource for the
:cte host family (+https://api.nfse.io+). Manages automatic CT-e fetch
via SEFAZ Distribuição DFe and reads received CT-e documents/events by
44-digit access key.
This is an inbound/query resource (settings + access-key lookups), not an
emission resource: there is no discriminated 202 +Pending+/+Issued+
contract here. The host already carries no version segment, so paths embed
/v2 literally and #api_version is "".
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #api_family ⇒ Symbol
-
#api_version ⇒ String
The
:ctehost carries no version segment;/v2is embedded per path. -
#compact(hash) ⇒ Hash[untyped, untyped]
Drop
nilvalues so optional fields are omitted from the body. -
#disable(company_id:) ⇒ Nfe::InboundSettings
Disable automatic CT-e search for a company.
-
#download_event_xml(company_id:, access_key:, event_key:) ⇒ String
Download the XML of a CT-e event.
-
#download_xml(company_id:, access_key:) ⇒ String
Download the CT-e XML by access key.
-
#enable(company_id:, start_from_nsu: nil, start_from_date: nil) ⇒ Nfe::InboundSettings
Enable automatic CT-e search for a company via Distribuição DFe.
-
#get_event(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Retrieve the metadata of an event related to a received CT-e.
-
#get_settings(company_id:) ⇒ Nfe::InboundSettings
Get the current automatic CT-e search settings.
- #json_body(data) ⇒ String
- #json_headers ⇒ Hash[String, String]
-
#retrieve(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Retrieve CT-e metadata by its 44-digit access key (normalized).
- #xml_accept ⇒ Hash[String, String]
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
29 30 31 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 29 def api_family :cte end |
#api_version ⇒ String
The :cte host carries no version segment; /v2 is embedded per path.
34 35 36 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 34 def api_version "" end |
#compact(hash) ⇒ Hash[untyped, untyped]
Drop nil values so optional fields are omitted from the body.
139 140 141 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 139 def compact(hash) hash.compact end |
#disable(company_id:) ⇒ Nfe::InboundSettings
Disable automatic CT-e search for a company.
58 59 60 61 62 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 58 def disable(company_id:) id = Nfe::IdValidator.company_id(company_id) response = delete("/v2/companies/#{id}/inbound/transportationinvoices") hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#download_event_xml(company_id:, access_key:, event_key:) ⇒ String
Download the XML of a CT-e event.
117 118 119 120 121 122 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 117 def download_event_xml(company_id:, access_key:, event_key:) id = Nfe::IdValidator.company_id(company_id) key = Nfe::IdValidator.access_key(access_key) ev = Nfe::IdValidator.event_key(event_key) download("/v2/companies/#{id}/inbound/#{key}/events/#{ev}/xml", headers: xml_accept) end |
#download_xml(company_id:, access_key:) ⇒ String
Download the CT-e XML by access key.
91 92 93 94 95 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 91 def download_xml(company_id:, access_key:) id = Nfe::IdValidator.company_id(company_id) key = Nfe::IdValidator.access_key(access_key) download("/v2/companies/#{id}/inbound/#{key}/xml", headers: xml_accept) end |
#enable(company_id:, start_from_nsu: nil, start_from_date: nil) ⇒ Nfe::InboundSettings
Enable automatic CT-e search for a company via Distribuição DFe.
46 47 48 49 50 51 52 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 46 def enable(company_id:, start_from_nsu: nil, start_from_date: nil) id = Nfe::IdValidator.company_id(company_id) body = compact("startFromNsu" => start_from_nsu, "startFromDate" => start_from_date) response = post("/v2/companies/#{id}/inbound/transportationinvoices", body: json_body(body), headers: json_headers) hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#get_event(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Retrieve the metadata of an event related to a received CT-e.
103 104 105 106 107 108 109 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 103 def get_event(company_id:, access_key:, event_key:) id = Nfe::IdValidator.company_id(company_id) key = Nfe::IdValidator.access_key(access_key) ev = Nfe::IdValidator.event_key(event_key) response = get("/v2/companies/#{id}/inbound/#{key}/events/#{ev}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_settings(company_id:) ⇒ Nfe::InboundSettings
Get the current automatic CT-e search settings.
68 69 70 71 72 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 68 def get_settings(company_id:) id = Nfe::IdValidator.company_id(company_id) response = get("/v2/companies/#{id}/inbound/transportationinvoices") hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#json_body(data) ⇒ String
130 131 132 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 130 def json_body(data) JSON.generate(data) end |
#json_headers ⇒ Hash[String, String]
126 127 128 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 126 def json_headers { "Content-Type" => "application/json" } end |
#retrieve(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Retrieve CT-e metadata by its 44-digit access key (normalized).
79 80 81 82 83 84 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 79 def retrieve(company_id:, access_key:) id = Nfe::IdValidator.company_id(company_id) key = Nfe::IdValidator.access_key(access_key) response = get("/v2/companies/#{id}/inbound/#{key}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#xml_accept ⇒ Hash[String, String]
134 135 136 |
# File 'lib/nfe/resources/transportation_invoices.rb', line 134 def xml_accept { "Accept" => "application/xml" } end |