|
| 1 | +=begin |
| 2 | +#TemplateFox API |
| 3 | +
|
| 4 | +#Generate beautiful PDFs from HTML/CSS templates with Jinja2 via API. Design once, generate thousands. |
| 5 | +
|
| 6 | +The version of the OpenAPI document: 1.5.0 |
| 7 | +
|
| 8 | +Generated by: https://openapi-generator.tech |
| 9 | +Generator version: 7.19.0 |
| 10 | +
|
| 11 | +=end |
| 12 | + |
| 13 | +require 'cgi' |
| 14 | + |
| 15 | +module TemplateFox |
| 16 | + class PDFAsyncApi |
| 17 | + attr_accessor :api_client |
| 18 | + |
| 19 | + def initialize(api_client = ApiClient.default) |
| 20 | + @api_client = api_client |
| 21 | + end |
| 22 | + # Generate PDF asynchronously |
| 23 | + # 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). |
| 24 | + # @param create_async_pdf_request [CreateAsyncPdfRequest] |
| 25 | + # @param [Hash] opts the optional parameters |
| 26 | + # @return [CreateAsyncPdfResponse] |
| 27 | + def create_pdf_async(create_async_pdf_request, opts = {}) |
| 28 | + data, _status_code, _headers = create_pdf_async_with_http_info(create_async_pdf_request, opts) |
| 29 | + data |
| 30 | + end |
| 31 | + |
| 32 | + # Generate PDF asynchronously |
| 33 | + # 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). |
| 34 | + # @param create_async_pdf_request [CreateAsyncPdfRequest] |
| 35 | + # @param [Hash] opts the optional parameters |
| 36 | + # @return [Array<(CreateAsyncPdfResponse, Integer, Hash)>] CreateAsyncPdfResponse data, response status code and response headers |
| 37 | + def create_pdf_async_with_http_info(create_async_pdf_request, opts = {}) |
| 38 | + if @api_client.config.debugging |
| 39 | + @api_client.config.logger.debug 'Calling API: PDFAsyncApi.create_pdf_async ...' |
| 40 | + end |
| 41 | + # verify the required parameter 'create_async_pdf_request' is set |
| 42 | + if @api_client.config.client_side_validation && create_async_pdf_request.nil? |
| 43 | + fail ArgumentError, "Missing the required parameter 'create_async_pdf_request' when calling PDFAsyncApi.create_pdf_async" |
| 44 | + end |
| 45 | + # resource path |
| 46 | + local_var_path = '/v1/pdf/create-async' |
| 47 | + |
| 48 | + # query parameters |
| 49 | + query_params = opts[:query_params] || {} |
| 50 | + |
| 51 | + # header parameters |
| 52 | + header_params = opts[:header_params] || {} |
| 53 | + # HTTP header 'Accept' (if needed) |
| 54 | + header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] |
| 55 | + # HTTP header 'Content-Type' |
| 56 | + content_type = @api_client.select_header_content_type(['application/json']) |
| 57 | + if !content_type.nil? |
| 58 | + header_params['Content-Type'] = content_type |
| 59 | + end |
| 60 | + |
| 61 | + # form parameters |
| 62 | + form_params = opts[:form_params] || {} |
| 63 | + |
| 64 | + # http body (model) |
| 65 | + post_body = opts[:debug_body] || @api_client.object_to_http_body(create_async_pdf_request) |
| 66 | + |
| 67 | + # return_type |
| 68 | + return_type = opts[:debug_return_type] || 'CreateAsyncPdfResponse' |
| 69 | + |
| 70 | + # auth_names |
| 71 | + auth_names = opts[:debug_auth_names] || ['ApiKeyAuth'] |
| 72 | + |
| 73 | + new_options = opts.merge( |
| 74 | + :operation => :"PDFAsyncApi.create_pdf_async", |
| 75 | + :header_params => header_params, |
| 76 | + :query_params => query_params, |
| 77 | + :form_params => form_params, |
| 78 | + :body => post_body, |
| 79 | + :auth_names => auth_names, |
| 80 | + :return_type => return_type |
| 81 | + ) |
| 82 | + |
| 83 | + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) |
| 84 | + if @api_client.config.debugging |
| 85 | + @api_client.config.logger.debug "API called: PDFAsyncApi#create_pdf_async\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" |
| 86 | + end |
| 87 | + return data, status_code, headers |
| 88 | + end |
| 89 | + |
| 90 | + # Get PDF job status |
| 91 | + # 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 |
| 92 | + # @param job_id [String] |
| 93 | + # @param [Hash] opts the optional parameters |
| 94 | + # @return [JobStatusResponse] |
| 95 | + def get_pdf_job_status(job_id, opts = {}) |
| 96 | + data, _status_code, _headers = get_pdf_job_status_with_http_info(job_id, opts) |
| 97 | + data |
| 98 | + end |
| 99 | + |
| 100 | + # Get PDF job status |
| 101 | + # 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 |
| 102 | + # @param job_id [String] |
| 103 | + # @param [Hash] opts the optional parameters |
| 104 | + # @return [Array<(JobStatusResponse, Integer, Hash)>] JobStatusResponse data, response status code and response headers |
| 105 | + def get_pdf_job_status_with_http_info(job_id, opts = {}) |
| 106 | + if @api_client.config.debugging |
| 107 | + @api_client.config.logger.debug 'Calling API: PDFAsyncApi.get_pdf_job_status ...' |
| 108 | + end |
| 109 | + # verify the required parameter 'job_id' is set |
| 110 | + if @api_client.config.client_side_validation && job_id.nil? |
| 111 | + fail ArgumentError, "Missing the required parameter 'job_id' when calling PDFAsyncApi.get_pdf_job_status" |
| 112 | + end |
| 113 | + # resource path |
| 114 | + local_var_path = '/v1/pdf/status/{job_id}'.sub('{' + 'job_id' + '}', CGI.escape(job_id.to_s)) |
| 115 | + |
| 116 | + # query parameters |
| 117 | + query_params = opts[:query_params] || {} |
| 118 | + |
| 119 | + # header parameters |
| 120 | + header_params = opts[:header_params] || {} |
| 121 | + # HTTP header 'Accept' (if needed) |
| 122 | + header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] |
| 123 | + |
| 124 | + # form parameters |
| 125 | + form_params = opts[:form_params] || {} |
| 126 | + |
| 127 | + # http body (model) |
| 128 | + post_body = opts[:debug_body] |
| 129 | + |
| 130 | + # return_type |
| 131 | + return_type = opts[:debug_return_type] || 'JobStatusResponse' |
| 132 | + |
| 133 | + # auth_names |
| 134 | + auth_names = opts[:debug_auth_names] || ['ApiKeyAuth'] |
| 135 | + |
| 136 | + new_options = opts.merge( |
| 137 | + :operation => :"PDFAsyncApi.get_pdf_job_status", |
| 138 | + :header_params => header_params, |
| 139 | + :query_params => query_params, |
| 140 | + :form_params => form_params, |
| 141 | + :body => post_body, |
| 142 | + :auth_names => auth_names, |
| 143 | + :return_type => return_type |
| 144 | + ) |
| 145 | + |
| 146 | + data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) |
| 147 | + if @api_client.config.debugging |
| 148 | + @api_client.config.logger.debug "API called: PDFAsyncApi#get_pdf_job_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" |
| 149 | + end |
| 150 | + return data, status_code, headers |
| 151 | + end |
| 152 | + |
| 153 | + # List PDF jobs |
| 154 | + # List async PDF generation jobs for your team. **Authentication:** API Key required (`x-api-key` header) Supports pagination and filtering by status. |
| 155 | + # @param [Hash] opts the optional parameters |
| 156 | + # @option opts [Integer] :limit (default to 20) |
| 157 | + # @option opts [Integer] :offset (default to 0) |
| 158 | + # @option opts [JobStatus] :status |
| 159 | + # @return [JobListResponse] |
| 160 | + def list_pdf_jobs(opts = {}) |
| 161 | + data, _status_code, _headers = list_pdf_jobs_with_http_info(opts) |
| 162 | + data |
| 163 | + end |
| 164 | + |
| 165 | + # List PDF jobs |
| 166 | + # List async PDF generation jobs for your team. **Authentication:** API Key required (`x-api-key` header) Supports pagination and filtering by status. |
| 167 | + # @param [Hash] opts the optional parameters |
| 168 | + # @option opts [Integer] :limit (default to 20) |
| 169 | + # @option opts [Integer] :offset (default to 0) |
| 170 | + # @option opts [JobStatus] :status |
| 171 | + # @return [Array<(JobListResponse, Integer, Hash)>] JobListResponse data, response status code and response headers |
| 172 | + def list_pdf_jobs_with_http_info(opts = {}) |
| 173 | + if @api_client.config.debugging |
| 174 | + @api_client.config.logger.debug 'Calling API: PDFAsyncApi.list_pdf_jobs ...' |
| 175 | + end |
| 176 | + # resource path |
| 177 | + local_var_path = '/v1/pdf/jobs' |
| 178 | + |
| 179 | + # query parameters |
| 180 | + query_params = opts[:query_params] || {} |
| 181 | + query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil? |
| 182 | + query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil? |
| 183 | + query_params[:'status'] = opts[:'status'] if !opts[:'status'].nil? |
| 184 | + |
| 185 | + # header parameters |
| 186 | + header_params = opts[:header_params] || {} |
| 187 | + # HTTP header 'Accept' (if needed) |
| 188 | + header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] |
| 189 | + |
| 190 | + # form parameters |
| 191 | + form_params = opts[:form_params] || {} |
| 192 | + |
| 193 | + # http body (model) |
| 194 | + post_body = opts[:debug_body] |
| 195 | + |
| 196 | + # return_type |
| 197 | + return_type = opts[:debug_return_type] || 'JobListResponse' |
| 198 | + |
| 199 | + # auth_names |
| 200 | + auth_names = opts[:debug_auth_names] || ['ApiKeyAuth'] |
| 201 | + |
| 202 | + new_options = opts.merge( |
| 203 | + :operation => :"PDFAsyncApi.list_pdf_jobs", |
| 204 | + :header_params => header_params, |
| 205 | + :query_params => query_params, |
| 206 | + :form_params => form_params, |
| 207 | + :body => post_body, |
| 208 | + :auth_names => auth_names, |
| 209 | + :return_type => return_type |
| 210 | + ) |
| 211 | + |
| 212 | + data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) |
| 213 | + if @api_client.config.debugging |
| 214 | + @api_client.config.logger.debug "API called: PDFAsyncApi#list_pdf_jobs\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" |
| 215 | + end |
| 216 | + return data, status_code, headers |
| 217 | + end |
| 218 | + end |
| 219 | +end |
0 commit comments