Class: PoliPage::Resources::Documents
- Inherits:
-
Object
- Object
- PoliPage::Resources::Documents
- Defined in:
- lib/poli_page/documents.rb
Overview
‘client.documents` namespace (sdk-ruby-plan.md §13 Phase 4, port of sdk-node/src/documents.ts).
Instance Method Summary collapse
-
#delete(id) ⇒ nil
DELETE /v1/documents/:id — returns nil.
-
#get(id) ⇒ PoliPage::DocumentDescriptor
GET /v1/documents/:id — returns a ‘DocumentDescriptor` with the client back-reference attached so `#download_pdf` works.
-
#initialize(client) ⇒ Documents
constructor
A new instance of Documents.
-
#preview(id) ⇒ PoliPage::DocumentPreviewResult
GET /v1/documents/:id/preview — returns the stored paginated HTML plus the page count carried by the ‘X-Document-Page-Count` response header.
-
#thumbnails(id, **options) ⇒ Array<PoliPage::Thumbnail>
POST /v1/documents/:id/thumbnails — the deployed API expects the options nested under a ‘thumbnails` key.
Constructor Details
#initialize(client) ⇒ Documents
Returns a new instance of Documents.
14 15 16 |
# File 'lib/poli_page/documents.rb', line 14 def initialize(client) @client = client end |
Instance Method Details
#delete(id) ⇒ nil
DELETE /v1/documents/:id — returns nil. Re-deleting an already-deleted document surfaces as ‘PoliPage::GoneError` (HTTP 410) — no special handling here.
88 89 90 91 |
# File 'lib/poli_page/documents.rb', line 88 def delete(id) @client.execute_delete(path_for(id)) nil end |
#get(id) ⇒ PoliPage::DocumentDescriptor
GET /v1/documents/:id — returns a ‘DocumentDescriptor` with the client back-reference attached so `#download_pdf` works.
29 30 31 32 33 |
# File 'lib/poli_page/documents.rb', line 29 def get(id) parsed = @client.execute_get(path_for(id)) parsed[:metadata] ||= {} PoliPage::DocumentDescriptor.new(**parsed, _client: @client) end |
#preview(id) ⇒ PoliPage::DocumentPreviewResult
GET /v1/documents/:id/preview — returns the stored paginated HTML plus the page count carried by the ‘X-Document-Page-Count` response header. The body is `text/html`, NOT a JSON envelope. No engine work — this is a snapshot read of the stored document.
47 48 49 50 51 52 |
# File 'lib/poli_page/documents.rb', line 47 def preview(id) response = @client.execute_get_raw("#{path_for(id)}/preview") page_count_header = response.headers[Internal::Constants::HEADER_DOCUMENT_PAGE_COUNT] page_count = page_count_header.to_s.match?(/\A\d+\z/) ? page_count_header.to_i : 0 PoliPage::DocumentPreviewResult.new(html: response.body.to_s, page_count: page_count) end |
#thumbnails(id, **options) ⇒ Array<PoliPage::Thumbnail>
POST /v1/documents/:id/thumbnails — the deployed API expects the options nested under a ‘thumbnails` key. The response envelope `{ thumbnails: […] }` is unwrapped here. Returns an Array of `PoliPage::Thumbnail`; each carries base64-encoded image bytes in `data` (decode with `Base64.decode64(thumb.data)`).
71 72 73 74 75 76 |
# File 'lib/poli_page/documents.rb', line 71 def thumbnails(id, **) () body = { thumbnails: .compact } parsed = @client.execute_post("#{path_for(id)}/thumbnails", body: body) parsed[:thumbnails].map { |t| PoliPage::Thumbnail.new(**t) } end |