Class: PoliPage::Resources::Render
- Inherits:
-
Object
- Object
- PoliPage::Resources::Render
- Defined in:
- lib/poli_page/render.rb
Overview
‘client.render` namespace. Each method captures a back-reference to the parent `PoliPage::Client` and delegates HTTP execution through it (sdk-ruby-plan.md §3.1).
Instance Method Summary collapse
-
#document(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ PoliPage::DocumentDescriptor
POST /v1/render — render and store the document, returning a ‘PoliPage::DocumentDescriptor` with the client back-reference attached so that `#download_pdf` works.
-
#initialize(client) ⇒ Render
constructor
A new instance of Render.
-
#pdf(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ String
Two-hop: render the document, then fetch the presigned PDF URL and return the raw bytes (binary-encoded String).
-
#pdf_stream(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) {|chunk| ... } ⇒ Enumerator?
Streaming form of ‘#pdf`.
-
#preview(template:, data:, project: nil, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ PoliPage::PreviewResult
POST /v1/render/preview — render and return the HTML, total page count, and the environment (“sandbox” / “live”) inferred from the API key.
Constructor Details
#initialize(client) ⇒ Render
Returns a new instance of Render.
12 13 14 |
# File 'lib/poli_page/render.rb', line 12 def initialize(client) @client = client end |
Instance Method Details
#document(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ PoliPage::DocumentDescriptor
POST /v1/render — render and store the document, returning a ‘PoliPage::DocumentDescriptor` with the client back-reference attached so that `#download_pdf` works. Project mode only.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/poli_page/render.rb', line 74 def document(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) validate_render_kwargs!(format: format, orientation: orientation) body = { project: project, template: template, data: data, version: version, format: format, orientation: orientation, locale: locale, metadata: }.compact parsed = @client.execute_post(Internal::Constants::PATH_RENDER, body: body, idempotency_key: idempotency_key) parsed[:metadata] ||= {} PoliPage::DocumentDescriptor.new(**parsed, _client: @client) end |
#pdf(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ String
Two-hop: render the document, then fetch the presigned PDF URL and return the raw bytes (binary-encoded String). The presigned fetch is unauthenticated and NOT subject to the retry policy.
99 100 101 102 103 104 105 |
# File 'lib/poli_page/render.rb', line 99 def pdf(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) desc = document(project: project, template: template, data: data, version: version, format: format, orientation: orientation, locale: locale, metadata: , idempotency_key: idempotency_key) desc.download_pdf end |
#pdf_stream(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) {|chunk| ... } ⇒ Enumerator?
Streaming form of ‘#pdf`. With a block, yields raw chunks (binary bytes) as they arrive. Without a block, returns an `Enumerator` so the caller can `.each`, `.first(n)`, pipe into `Enumerable` chains, etc.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/poli_page/render.rb', line 128 def pdf_stream(project:, template:, data:, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil, &block) unless block return Enumerator.new do |yielder| pdf_stream(project: project, template: template, data: data, version: version, format: format, orientation: orientation, locale: locale, metadata: , idempotency_key: idempotency_key) { |chunk| yielder << chunk } end end desc = document(project: project, template: template, data: data, version: version, format: format, orientation: orientation, locale: locale, metadata: , idempotency_key: idempotency_key) @client.stream_bytes(desc.presigned_pdf_url, &block) end |
#preview(template:, data:, project: nil, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) ⇒ PoliPage::PreviewResult
POST /v1/render/preview — render and return the HTML, total page count, and the environment (“sandbox” / “live”) inferred from the API key. Accepts both project mode and inline mode (the only render-* method that does).
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/poli_page/render.rb', line 47 def preview(template:, data:, project: nil, version: nil, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) validate_render_kwargs!(format: format, orientation: orientation) body = { project: project, template: template, data: data, version: version, format: format, orientation: orientation, locale: locale, metadata: }.compact parsed = @client.execute_post(Internal::Constants::PATH_RENDER_PREVIEW, body: body, idempotency_key: idempotency_key) PoliPage::PreviewResult.new(**parsed) end |