Class: Nfe::Resources::ProductInvoiceQuery

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

Overview

Read-only queries against the NF-e distribution/query API (+https://nfe.api.nfe.io+). The version segment is embedded in the request path, 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)


55
# File 'lib/nfe/resources/product_invoice_query.rb', line 55

def api_family = :nfe_query

#api_versionString

This family's host embeds the version in the path, so no version segment is prefixed to the request path.

Returns:

  • (String)


59
# File 'lib/nfe/resources/product_invoice_query.rb', line 59

def api_version = ""

#download_pdf(access_key) ⇒ String

Download the PDF (DANFE) of a product invoice by its access key.

Parameters:

  • access_key (String)

    the 44-digit NF-e access key.

Returns:

  • (String)

    the PDF bytes (+ASCII-8BIT+).



28
29
30
31
# File 'lib/nfe/resources/product_invoice_query.rb', line 28

def download_pdf(access_key)
  key = Nfe::IdValidator.access_key(access_key)
  download("/v2/productinvoices/#{key}.pdf", headers: { "Accept" => "application/pdf" })
end

#download_xml(access_key) ⇒ String

Download the XML of a product invoice by its access key.

Parameters:

  • access_key (String)

    the 44-digit NF-e access key.

Returns:

  • (String)

    the XML bytes (+ASCII-8BIT+).



37
38
39
40
# File 'lib/nfe/resources/product_invoice_query.rb', line 37

def download_xml(access_key)
  key = Nfe::IdValidator.access_key(access_key)
  download("/v2/productinvoices/#{key}.xml", headers: { "Accept" => "application/xml" })
end

#list_events(access_key) ⇒ Nfe::ProductInvoiceEventsResponse?

List the events (eventos) associated with a product invoice by its access key.

Parameters:

  • access_key (String)

    the 44-digit NF-e access key.

Returns:



47
48
49
50
51
# File 'lib/nfe/resources/product_invoice_query.rb', line 47

def list_events(access_key)
  key = Nfe::IdValidator.access_key(access_key)
  response = get("/v2/productinvoices/events/#{key}")
  hydrate(Nfe::ProductInvoiceEventsResponse, parse_json(response.body))
end

#retrieve(access_key) ⇒ Nfe::ProductInvoiceDetails?

Fetch the details of a product invoice (NF-e) by its access key. The key is normalized to 44 digits before the request is issued (fail-fast).

Parameters:

  • access_key (String)

    the 44-digit NF-e access key.

Returns:



18
19
20
21
22
# File 'lib/nfe/resources/product_invoice_query.rb', line 18

def retrieve(access_key)
  key = Nfe::IdValidator.access_key(access_key)
  response = get("/v2/productinvoices/#{key}")
  hydrate(Nfe::ProductInvoiceDetails, parse_json(response.body))
end