Module: Pictify
- Defined in:
- lib/pictify.rb,
lib/pictify/types.rb,
lib/pictify/client.rb,
lib/pictify/errors.rb,
lib/pictify/version.rb
Overview
Pictify Ruby SDK
Official SDK for generating images, PDFs, and GIFs from raw HTML, live URLs, and reusable templates using the Pictify API.
Defined Under Namespace
Classes: AuthenticationError, BatchItemStatus, BatchRenderResult, BatchResults, Client, Error, GifRenderResult, ImageResult, ListTemplatesResult, NetworkError, Pagination, QuotaExceededError, RateLimitError, RenderError, RenderErrorEntry, RenderResult, RenderResultItem, ServerError, Template, TemplateNotFoundError, TemplateVariableDefinition, TimeoutError
Constant Summary collapse
- FORMATS =
Image output formats supported by Pictify renders.
The
/imageendpoint accepts these viaformat(mapped tofileExtension); template renders accept them viaformat(includingpdf). %i[png jpg jpeg webp pdf].freeze
- GIF_QUALITIES =
GIF quality presets accepted by the
/gifendpoint. %i[low medium high].freeze
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.error_from_response(status_code, body) ⇒ Object
Map an HTTP error response to a typed Pictify error.
Class Method Details
.error_from_response(status_code, body) ⇒ Object
Map an HTTP error response to a typed Pictify error.
The Pictify API has no unified error envelope: image/GIF endpoints return { error, code } while template/CRUD endpoints return { message } or { message, errors }. Message precedence is error then message then a fallback.
Status mapping:
- 401 -> AuthenticationError
- 402 -> QuotaExceededError
- 404 -> TemplateNotFoundError
- 422 -> RenderError (validation; includes +errors+)
- 429 -> QuotaExceededError when code == "quota_exceeded", else RateLimitError
- other 4xx -> RenderError
- 5xx -> ServerError
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/pictify/errors.rb', line 143 def self.error_from_response(status_code, body) body ||= {} = body["error"] || body["message"] || "An unexpected error occurred" case status_code when 401 AuthenticationError.new(, status_code: status_code, response_body: body) when 402 QuotaExceededError.new(, status_code: status_code, response_body: body) when 404 TemplateNotFoundError.new(, status_code: status_code, response_body: body) when 422 RenderError.new(, status_code: status_code, response_body: body, errors: body["errors"]) when 429 if body["code"] == "quota_exceeded" QuotaExceededError.new(, status_code: status_code, response_body: body) else RateLimitError.new(, status_code: status_code, response_body: body, retry_after: body["retry_after"]) end else if status_code >= 500 ServerError.new(, status_code: status_code, response_body: body) else RenderError.new(, status_code: status_code, response_body: body, errors: body["errors"]) end end end |