Class: Ksef::Invoices::Client
- Inherits:
-
Object
- Object
- Ksef::Invoices::Client
- Defined in:
- lib/ksef/invoices/client.rb
Overview
GET /invoices/ksef/{ksefNumber} — retrieve an invoice KSeF has accepted.
Mind the hourly budget
8 req/s but only 64 req/h (§6.1), which is one of the tightest ceilings in the
API — after POST /invoices/exports at 20/h. It is a per-document fetch, not a bulk
one: pulling a month of invoices this way will exhaust the budget long before the
per-second limit ever bites. The package export of 0.2 is the bulk route.
Requires the InvoiceRead permission, which is one of the two rake auth:bootstrap
requests for the integration suite.
Instance Method Summary collapse
-
#download(ksef_number) ⇒ String
The invoice as KSeF holds it, returned as the exact bytes received.
-
#initialize(connection, credential) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(connection, credential) ⇒ Client
Returns a new instance of Client.
23 24 25 26 |
# File 'lib/ksef/invoices/client.rb', line 23 def initialize(connection, credential) @connection = connection @credential = credential end |
Instance Method Details
#download(ksef_number) ⇒ String
The invoice as KSeF holds it, returned as the exact bytes received.
Verbatim for the same reason a UPO is (§12): this is the archived original of a
legal document, and the response is application/xml — the connection's JSON
middleware matches on content type, so nothing parses or re-encodes it here. Parse
a copy with FA3 if you need to read it.
This route declares x-ms-meta-hash too (§5.5 — four 200 responses carry it), so
the bytes are checked against it when it is present. An archived invoice is a legal
document; a free integrity check on it is worth taking.
43 44 45 46 47 48 49 50 51 |
# File 'lib/ksef/invoices/client.rb', line 43 def download(ksef_number) number = KsefNumber.parse(ksef_number) response = @connection.get("invoices/ksef/#{number}") do |request| request.headers["Authorization"] = "Bearer #{bearer}" end verify!(response) response.body.to_s end |