Class: TemplateFox::PDFAsyncApi

Inherits:
Object
  • Object
show all
Defined in:
lib/templatefox/api/pdf_async_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ PDFAsyncApi

Returns a new instance of PDFAsyncApi.



19
20
21
# File 'lib/templatefox/api/pdf_async_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/templatefox/api/pdf_async_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#create_pdf_async(create_async_pdf_request, opts = {}) ⇒ CreateAsyncPdfResponse

Generate PDF asynchronously Queue a PDF generation job for async processing. Authentication: API Key required (‘x-api-key` header) ## How It Works 1. Submit a job with template and data 2. Receive a `job_id` immediately 3. Poll `/v1/pdf/status/job_id` for completion 4. Optionally receive a webhook notification ## When to Use Async Use async generation when: - Processing large documents or batches - You can’t wait for synchronous response - You want webhook notifications ## Webhooks If ‘webhook_url` is provided, we’ll POST to it when the job completes or fails: “‘json { "event": "pdf.completed", "job_id": "…", "status": "completed", "result": { "url": "https://…", "filename": "invoice.pdf" } } “` Webhooks include HMAC-SHA256 signature in `X-TemplateFox-Signature` header if you provide a `webhook_secret`. Credits: 1 credit deducted immediately (refunded if job fails permanently).

Parameters:

  • create_async_pdf_request (CreateAsyncPdfRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



27
28
29
30
# File 'lib/templatefox/api/pdf_async_api.rb', line 27

def create_pdf_async(create_async_pdf_request, opts = {})
  data, _status_code, _headers = create_pdf_async_with_http_info(create_async_pdf_request, opts)
  data
end

#create_pdf_async_with_http_info(create_async_pdf_request, opts = {}) ⇒ Array<(CreateAsyncPdfResponse, Integer, Hash)>

Generate PDF asynchronously Queue a PDF generation job for async processing. Authentication: API Key required (&#x60;x-api-key&#x60; header) ## How It Works 1. Submit a job with template and data 2. Receive a &#x60;job_id&#x60; immediately 3. Poll &#x60;/v1/pdf/status/job_id&#x60; for completion 4. Optionally receive a webhook notification ## When to Use Async Use async generation when: - Processing large documents or batches - You can&#39;t wait for synchronous response - You want webhook notifications ## Webhooks If &#x60;webhook_url&#x60; is provided, we&#39;ll POST to it when the job completes or fails: &#x60;&#x60;&#x60;json { &quot;event&quot;: &quot;pdf.completed&quot;, &quot;job_id&quot;: &quot;…&quot;, &quot;status&quot;: &quot;completed&quot;, &quot;result&quot;: { &quot;url&quot;: &quot;https://…&quot;, &quot;filename&quot;: &quot;invoice.pdf&quot; } } &#x60;&#x60;&#x60; Webhooks include HMAC-SHA256 signature in &#x60;X-TemplateFox-Signature&#x60; header if you provide a &#x60;webhook_secret&#x60;. Credits: 1 credit deducted immediately (refunded if job fails permanently).

Parameters:

  • create_async_pdf_request (CreateAsyncPdfRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(CreateAsyncPdfResponse, Integer, Hash)>)

    CreateAsyncPdfResponse data, response status code and response headers



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/templatefox/api/pdf_async_api.rb', line 37

def create_pdf_async_with_http_info(create_async_pdf_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: PDFAsyncApi.create_pdf_async ...'
  end
  # verify the required parameter 'create_async_pdf_request' is set
  if @api_client.config.client_side_validation && create_async_pdf_request.nil?
    fail ArgumentError, "Missing the required parameter 'create_async_pdf_request' when calling PDFAsyncApi.create_pdf_async"
  end
  # resource path
  local_var_path = '/v1/pdf/create-async'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(create_async_pdf_request)

  # return_type
  return_type = opts[:debug_return_type] || 'CreateAsyncPdfResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"PDFAsyncApi.create_pdf_async",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: PDFAsyncApi#create_pdf_async\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_pdf_job(job_id, opts = {}) ⇒ JobStatusResponse

Get PDF job status Get the current status of an async PDF generation job. Authentication: API Key required (‘x-api-key` header) ## Status Values | Status | Description | |——–|————-| | `pending` | Job is queued, waiting to be processed | | `processing` | Job is being processed | | `completed` | PDF generated successfully | | `failed` | Job failed (check error_message) | ## Polling Recommendations - Poll every 1-2 seconds for small documents - Poll every 5-10 seconds for large documents - Consider using webhooks instead of polling

Parameters:

  • job_id (String)

    Async job ID (UUID returned by the create-async endpoint)

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



95
96
97
98
# File 'lib/templatefox/api/pdf_async_api.rb', line 95

def get_pdf_job(job_id, opts = {})
  data, _status_code, _headers = get_pdf_job_with_http_info(job_id, opts)
  data
end

#get_pdf_job_with_http_info(job_id, opts = {}) ⇒ Array<(JobStatusResponse, Integer, Hash)>

Get PDF job status Get the current status of an async PDF generation job. Authentication: API Key required (&#x60;x-api-key&#x60; header) ## Status Values | Status | Description | |——–|————-| | &#x60;pending&#x60; | Job is queued, waiting to be processed | | &#x60;processing&#x60; | Job is being processed | | &#x60;completed&#x60; | PDF generated successfully | | &#x60;failed&#x60; | Job failed (check error_message) | ## Polling Recommendations - Poll every 1-2 seconds for small documents - Poll every 5-10 seconds for large documents - Consider using webhooks instead of polling

Parameters:

  • job_id (String)

    Async job ID (UUID returned by the create-async endpoint)

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(JobStatusResponse, Integer, Hash)>)

    JobStatusResponse data, response status code and response headers



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/templatefox/api/pdf_async_api.rb', line 105

def get_pdf_job_with_http_info(job_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: PDFAsyncApi.get_pdf_job ...'
  end
  # verify the required parameter 'job_id' is set
  if @api_client.config.client_side_validation && job_id.nil?
    fail ArgumentError, "Missing the required parameter 'job_id' when calling PDFAsyncApi.get_pdf_job"
  end
  # resource path
  local_var_path = '/v1/pdf/jobs/{job_id}'.sub('{' + 'job_id' + '}', CGI.escape(job_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'JobStatusResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"PDFAsyncApi.get_pdf_job",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: PDFAsyncApi#get_pdf_job\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#list_pdf_jobs(opts = {}) ⇒ JobListResponse

List PDF jobs List async PDF generation jobs for your team. Authentication: API Key required (‘x-api-key` header) Supports pagination and filtering by status.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :limit (Integer)

    Maximum number of results to return (default to 20)

  • :offset (Integer)

    Number of results to skip (for pagination) (default to 0)

  • :status (JobStatus)

    Filter jobs by status

Returns:



160
161
162
163
# File 'lib/templatefox/api/pdf_async_api.rb', line 160

def list_pdf_jobs(opts = {})
  data, _status_code, _headers = list_pdf_jobs_with_http_info(opts)
  data
end

#list_pdf_jobs_with_http_info(opts = {}) ⇒ Array<(JobListResponse, Integer, Hash)>

List PDF jobs List async PDF generation jobs for your team. Authentication: API Key required (&#x60;x-api-key&#x60; header) Supports pagination and filtering by status.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :limit (Integer)

    Maximum number of results to return (default to 20)

  • :offset (Integer)

    Number of results to skip (for pagination) (default to 0)

  • :status (JobStatus)

    Filter jobs by status

Returns:

  • (Array<(JobListResponse, Integer, Hash)>)

    JobListResponse data, response status code and response headers



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/templatefox/api/pdf_async_api.rb', line 172

def list_pdf_jobs_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: PDFAsyncApi.list_pdf_jobs ...'
  end
  # resource path
  local_var_path = '/v1/pdf/jobs'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
  query_params[:'status'] = opts[:'status'] if !opts[:'status'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'JobListResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"PDFAsyncApi.list_pdf_jobs",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: PDFAsyncApi#list_pdf_jobs\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end