templatefox 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/LICENSE +21 -0
  4. data/README.md +206 -0
  5. data/Rakefile +10 -0
  6. data/docs/AccountApi.md +152 -0
  7. data/docs/AccountInfoResponse.md +20 -0
  8. data/docs/CreatePdfRequest.md +32 -0
  9. data/docs/CreatePdfResponse.md +24 -0
  10. data/docs/ExportType.md +15 -0
  11. data/docs/HTTPValidationError.md +18 -0
  12. data/docs/IntegrationsApi.md +286 -0
  13. data/docs/LocationInner.md +15 -0
  14. data/docs/PDFApi.md +79 -0
  15. data/docs/S3ConfigRequest.md +26 -0
  16. data/docs/S3ConfigResponse.md +28 -0
  17. data/docs/S3SuccessResponse.md +18 -0
  18. data/docs/S3TestResponse.md +20 -0
  19. data/docs/TemplateField.md +26 -0
  20. data/docs/TemplateListItem.md +24 -0
  21. data/docs/TemplatesApi.md +148 -0
  22. data/docs/TemplatesListResponse.md +18 -0
  23. data/docs/Transaction.md +28 -0
  24. data/docs/TransactionsResponse.md +24 -0
  25. data/docs/ValidationError.md +22 -0
  26. data/git_push.sh +57 -0
  27. data/lib/templatefox/api/account_api.rb +154 -0
  28. data/lib/templatefox/api/integrations_api.rb +261 -0
  29. data/lib/templatefox/api/pdf_api.rb +90 -0
  30. data/lib/templatefox/api/templates_api.rb +142 -0
  31. data/lib/templatefox/api_client.rb +397 -0
  32. data/lib/templatefox/api_error.rb +58 -0
  33. data/lib/templatefox/api_model_base.rb +88 -0
  34. data/lib/templatefox/configuration.rb +308 -0
  35. data/lib/templatefox/models/account_info_response.rb +176 -0
  36. data/lib/templatefox/models/create_pdf_request.rb +414 -0
  37. data/lib/templatefox/models/create_pdf_response.rb +247 -0
  38. data/lib/templatefox/models/export_type.rb +40 -0
  39. data/lib/templatefox/models/http_validation_error.rb +149 -0
  40. data/lib/templatefox/models/location_inner.rb +103 -0
  41. data/lib/templatefox/models/s3_config_request.rb +372 -0
  42. data/lib/templatefox/models/s3_config_response.rb +301 -0
  43. data/lib/templatefox/models/s3_success_response.rb +166 -0
  44. data/lib/templatefox/models/s3_test_response.rb +193 -0
  45. data/lib/templatefox/models/template_field.rb +227 -0
  46. data/lib/templatefox/models/template_list_item.rb +247 -0
  47. data/lib/templatefox/models/templates_list_response.rb +167 -0
  48. data/lib/templatefox/models/transaction.rb +267 -0
  49. data/lib/templatefox/models/transactions_response.rb +248 -0
  50. data/lib/templatefox/models/validation_error.rb +218 -0
  51. data/lib/templatefox/version.rb +15 -0
  52. data/lib/templatefox.rb +60 -0
  53. data/spec/api/account_api_spec.rb +59 -0
  54. data/spec/api/integrations_api_spec.rb +80 -0
  55. data/spec/api/pdf_api_spec.rb +47 -0
  56. data/spec/api/templates_api_spec.rb +58 -0
  57. data/spec/models/account_info_response_spec.rb +42 -0
  58. data/spec/models/create_pdf_request_spec.rb +78 -0
  59. data/spec/models/create_pdf_response_spec.rb +54 -0
  60. data/spec/models/export_type_spec.rb +30 -0
  61. data/spec/models/http_validation_error_spec.rb +36 -0
  62. data/spec/models/location_inner_spec.rb +21 -0
  63. data/spec/models/s3_config_request_spec.rb +60 -0
  64. data/spec/models/s3_config_response_spec.rb +66 -0
  65. data/spec/models/s3_success_response_spec.rb +36 -0
  66. data/spec/models/s3_test_response_spec.rb +42 -0
  67. data/spec/models/template_field_spec.rb +60 -0
  68. data/spec/models/template_list_item_spec.rb +54 -0
  69. data/spec/models/templates_list_response_spec.rb +36 -0
  70. data/spec/models/transaction_spec.rb +66 -0
  71. data/spec/models/transactions_response_spec.rb +54 -0
  72. data/spec/models/validation_error_spec.rb +48 -0
  73. data/spec/spec_helper.rb +111 -0
  74. data/templatefox.gemspec +39 -0
  75. metadata +177 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f13c971118753912fec80249e281bd9626bdd7def6aed8262ac20dc9d5743898
4
+ data.tar.gz: a8517386bda455fcab289a7c3a5c26ade53957f9023488da5a31092afb558aeb
5
+ SHA512:
6
+ metadata.gz: 5dbf4e06a398eb74463480ef86c7e67849656da385d6cc56fe277f1008617a03eaca736831794cbce96fabf316cc7e3ef402049f92068acf5eb3906809fd3db5
7
+ data.tar.gz: 77205cb17f8d2e5fcbd07ece7eff9d4cbe3d8f81a4db72f68f62c5ea2d512ce9bc85dd0f7bac62d3b7afee4d62fb78e44d6952f8d81fb4691c6ef2416145ed6a
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rake', '~> 13.0.1'
7
+ gem 'pry-byebug'
8
+ gem 'rubocop', '~> 0.66.0'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 TemplateFox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # TemplateFox Ruby SDK
2
+
3
+ Official Ruby SDK for [TemplateFox](https://pdftemplateapi.com) - Generate PDFs from HTML templates via API.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/templatefox.svg)](https://rubygems.org/gems/templatefox)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ Add to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'templatefox'
14
+ ```
15
+
16
+ Then run:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ Or install directly:
23
+
24
+ ```bash
25
+ gem install templatefox
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```ruby
31
+ require 'templatefox'
32
+
33
+ # Initialize the client
34
+ TemplateFox.configure do |config|
35
+ config.api_key['ApiKeyAuth'] = 'your-api-key'
36
+ end
37
+
38
+ api = TemplateFox::PDFApi.new
39
+
40
+ # Generate a PDF
41
+ request = TemplateFox::CreatePdfRequest.new(
42
+ template_id: 'YOUR_TEMPLATE_ID',
43
+ data: {
44
+ name: 'John Doe',
45
+ invoice_number: 'INV-001',
46
+ total_amount: 150.00
47
+ }
48
+ )
49
+
50
+ begin
51
+ response = api.create_pdf(request)
52
+ puts "PDF URL: #{response.url}"
53
+ puts "Credits remaining: #{response.credits_remaining}"
54
+ rescue TemplateFox::ApiError => e
55
+ puts "Error: #{e.message}"
56
+ end
57
+ ```
58
+
59
+ ## Features
60
+
61
+ - **Template-based PDF generation** - Create templates with dynamic variables, generate PDFs with your data
62
+ - **Multiple export options** - Get a signed URL (default) or raw binary PDF
63
+ - **S3 integration** - Upload generated PDFs directly to your own S3-compatible storage
64
+ - **Ruby 2.7+** - Compatible with Ruby 2.7 and above
65
+
66
+ ## API Methods
67
+
68
+ ### PDF Generation
69
+
70
+ ```ruby
71
+ request = TemplateFox::CreatePdfRequest.new(
72
+ template_id: 'TEMPLATE_ID',
73
+ data: { name: 'John Doe' },
74
+ export_type: 'url', # 'url' or 'binary'
75
+ expiration: 86400, # URL expiration in seconds
76
+ filename: 'invoice-001' # Custom filename
77
+ )
78
+
79
+ response = api.create_pdf(request)
80
+ ```
81
+
82
+ ### Templates
83
+
84
+ ```ruby
85
+ templates_api = TemplateFox::TemplatesApi.new
86
+
87
+ # List all templates
88
+ templates = templates_api.list_templates
89
+ templates.templates.each do |template|
90
+ puts "#{template.id}: #{template.name}"
91
+ end
92
+
93
+ # Get template fields
94
+ fields = templates_api.get_template_fields('TEMPLATE_ID')
95
+ fields.each do |field|
96
+ puts "#{field.key}: #{field.type} (required: #{field.required})"
97
+ end
98
+ ```
99
+
100
+ ### Account
101
+
102
+ ```ruby
103
+ account_api = TemplateFox::AccountApi.new
104
+
105
+ # Get account info
106
+ account = account_api.get_account
107
+ puts "Credits: #{account.credits}"
108
+ puts "Email: #{account.email}"
109
+
110
+ # List transactions
111
+ transactions = account_api.list_transactions(limit: 100, offset: 0)
112
+ transactions.transactions.each do |tx|
113
+ puts "#{tx.transaction_type}: #{tx.credits} credits"
114
+ end
115
+ ```
116
+
117
+ ### S3 Integration
118
+
119
+ ```ruby
120
+ integrations_api = TemplateFox::IntegrationsApi.new
121
+
122
+ # Save S3 configuration
123
+ s3_config = TemplateFox::S3ConfigRequest.new(
124
+ endpoint_url: 'https://s3.amazonaws.com',
125
+ access_key_id: 'AKIAIOSFODNN7EXAMPLE',
126
+ secret_access_key: 'your-secret-key',
127
+ bucket_name: 'my-pdf-bucket',
128
+ default_prefix: 'generated/pdfs/'
129
+ )
130
+
131
+ integrations_api.save_s3_config(s3_config)
132
+
133
+ # Test connection
134
+ test = integrations_api.test_s3_connection
135
+ puts "Connection: #{test.success ? 'OK' : 'Failed'}"
136
+ ```
137
+
138
+ ## Configuration
139
+
140
+ ```ruby
141
+ TemplateFox.configure do |config|
142
+ config.host = 'https://api.pdftemplateapi.com' # Default API URL
143
+ config.api_key['ApiKeyAuth'] = ENV['TEMPLATEFOX_API_KEY']
144
+
145
+ # Optional: Enable debugging
146
+ config.debugging = true
147
+ end
148
+ ```
149
+
150
+ ## Error Handling
151
+
152
+ ```ruby
153
+ begin
154
+ response = api.create_pdf(request)
155
+ rescue TemplateFox::ApiError => e
156
+ case e.code
157
+ when 402
158
+ puts 'Insufficient credits'
159
+ when 403
160
+ puts 'Access denied - check your API key'
161
+ when 404
162
+ puts 'Template not found'
163
+ else
164
+ puts "Error: #{e.message}"
165
+ end
166
+ end
167
+ ```
168
+
169
+ ## Rails Integration
170
+
171
+ ```ruby
172
+ # config/initializers/templatefox.rb
173
+ TemplateFox.configure do |config|
174
+ config.api_key['ApiKeyAuth'] = Rails.application.credentials.templatefox_api_key
175
+ end
176
+
177
+ # app/services/pdf_generator.rb
178
+ class PdfGenerator
179
+ def initialize
180
+ @api = TemplateFox::PDFApi.new
181
+ end
182
+
183
+ def generate_invoice(invoice)
184
+ request = TemplateFox::CreatePdfRequest.new(
185
+ template_id: ENV['INVOICE_TEMPLATE_ID'],
186
+ data: invoice.to_template_data
187
+ )
188
+ @api.create_pdf(request)
189
+ end
190
+ end
191
+ ```
192
+
193
+ ## Documentation
194
+
195
+ - [API Documentation](https://pdftemplateapi.com/docs)
196
+ - [Swagger UI](https://api.pdftemplateapi.com/docs)
197
+ - [Dashboard](https://pdftemplateapi.com/dashboard)
198
+
199
+ ## Support
200
+
201
+ - Email: support@pdftemplateapi.com
202
+ - Issues: [GitHub Issues](https://github.com/TemplateFoxPDF/rubysdk/issues)
203
+
204
+ ## License
205
+
206
+ MIT License - see [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
8
+ rescue LoadError
9
+ # no rspec available
10
+ end
@@ -0,0 +1,152 @@
1
+ # TemplateFox::AccountApi
2
+
3
+ All URIs are relative to *https://api.pdftemplateapi.com*
4
+
5
+ | Method | HTTP request | Description |
6
+ | ------ | ------------ | ----------- |
7
+ | [**get_account**](AccountApi.md#get_account) | **GET** /v1/account | Get account info |
8
+ | [**list_transactions**](AccountApi.md#list_transactions) | **GET** /v1/account/transactions | List transactions |
9
+
10
+
11
+ ## get_account
12
+
13
+ > <AccountInfoResponse> get_account
14
+
15
+ Get account info
16
+
17
+ Get account information including remaining credits. **Authentication:** API Key required (`x-api-key` header) or JWT token **Usage:** Check credit balance before performing operations. **No credits consumed:** This is a read-only endpoint.
18
+
19
+ ### Examples
20
+
21
+ ```ruby
22
+ require 'time'
23
+ require 'templatefox'
24
+ # setup authorization
25
+ TemplateFox.configure do |config|
26
+ # Configure API key authorization: ApiKeyAuth
27
+ config.api_key['x-api-key'] = 'YOUR API KEY'
28
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
29
+ # config.api_key_prefix['x-api-key'] = 'Bearer'
30
+ end
31
+
32
+ api_instance = TemplateFox::AccountApi.new
33
+
34
+ begin
35
+ # Get account info
36
+ result = api_instance.get_account
37
+ p result
38
+ rescue TemplateFox::ApiError => e
39
+ puts "Error when calling AccountApi->get_account: #{e}"
40
+ end
41
+ ```
42
+
43
+ #### Using the get_account_with_http_info variant
44
+
45
+ This returns an Array which contains the response data, status code and headers.
46
+
47
+ > <Array(<AccountInfoResponse>, Integer, Hash)> get_account_with_http_info
48
+
49
+ ```ruby
50
+ begin
51
+ # Get account info
52
+ data, status_code, headers = api_instance.get_account_with_http_info
53
+ p status_code # => 2xx
54
+ p headers # => { ... }
55
+ p data # => <AccountInfoResponse>
56
+ rescue TemplateFox::ApiError => e
57
+ puts "Error when calling AccountApi->get_account_with_http_info: #{e}"
58
+ end
59
+ ```
60
+
61
+ ### Parameters
62
+
63
+ This endpoint does not need any parameter.
64
+
65
+ ### Return type
66
+
67
+ [**AccountInfoResponse**](AccountInfoResponse.md)
68
+
69
+ ### Authorization
70
+
71
+ [ApiKeyAuth](../README.md#ApiKeyAuth)
72
+
73
+ ### HTTP request headers
74
+
75
+ - **Content-Type**: Not defined
76
+ - **Accept**: application/json
77
+
78
+
79
+ ## list_transactions
80
+
81
+ > <TransactionsResponse> list_transactions(opts)
82
+
83
+ List transactions
84
+
85
+ List transaction history for the authenticated user. **Authentication:** API Key required (`x-api-key` header) or JWT token **Pagination:** Use `limit` and `offset` query parameters. **Transaction types:** - `PDFGEN`: PDF generation (consumes credits) - `REFUND`: Credit refund (on failed generation) - `PURCHASE`: Credit purchase - `BONUS`: Bonus credits **Credits field:** - Positive value = credits consumed - Negative value = credits added **No credits consumed:** This is a read-only endpoint.
86
+
87
+ ### Examples
88
+
89
+ ```ruby
90
+ require 'time'
91
+ require 'templatefox'
92
+ # setup authorization
93
+ TemplateFox.configure do |config|
94
+ # Configure API key authorization: ApiKeyAuth
95
+ config.api_key['x-api-key'] = 'YOUR API KEY'
96
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
97
+ # config.api_key_prefix['x-api-key'] = 'Bearer'
98
+ end
99
+
100
+ api_instance = TemplateFox::AccountApi.new
101
+ opts = {
102
+ limit: 56, # Integer | Number of records to return
103
+ offset: 56 # Integer | Number of records to skip
104
+ }
105
+
106
+ begin
107
+ # List transactions
108
+ result = api_instance.list_transactions(opts)
109
+ p result
110
+ rescue TemplateFox::ApiError => e
111
+ puts "Error when calling AccountApi->list_transactions: #{e}"
112
+ end
113
+ ```
114
+
115
+ #### Using the list_transactions_with_http_info variant
116
+
117
+ This returns an Array which contains the response data, status code and headers.
118
+
119
+ > <Array(<TransactionsResponse>, Integer, Hash)> list_transactions_with_http_info(opts)
120
+
121
+ ```ruby
122
+ begin
123
+ # List transactions
124
+ data, status_code, headers = api_instance.list_transactions_with_http_info(opts)
125
+ p status_code # => 2xx
126
+ p headers # => { ... }
127
+ p data # => <TransactionsResponse>
128
+ rescue TemplateFox::ApiError => e
129
+ puts "Error when calling AccountApi->list_transactions_with_http_info: #{e}"
130
+ end
131
+ ```
132
+
133
+ ### Parameters
134
+
135
+ | Name | Type | Description | Notes |
136
+ | ---- | ---- | ----------- | ----- |
137
+ | **limit** | **Integer** | Number of records to return | [optional][default to 300] |
138
+ | **offset** | **Integer** | Number of records to skip | [optional][default to 0] |
139
+
140
+ ### Return type
141
+
142
+ [**TransactionsResponse**](TransactionsResponse.md)
143
+
144
+ ### Authorization
145
+
146
+ [ApiKeyAuth](../README.md#ApiKeyAuth)
147
+
148
+ ### HTTP request headers
149
+
150
+ - **Content-Type**: Not defined
151
+ - **Accept**: application/json
152
+
@@ -0,0 +1,20 @@
1
+ # TemplateFox::AccountInfoResponse
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+ | **credits** | **Integer** | Remaining credits | |
8
+ | **email** | **String** | | [optional] |
9
+
10
+ ## Example
11
+
12
+ ```ruby
13
+ require 'templatefox'
14
+
15
+ instance = TemplateFox::AccountInfoResponse.new(
16
+ credits: null,
17
+ email: null
18
+ )
19
+ ```
20
+
@@ -0,0 +1,32 @@
1
+ # TemplateFox::CreatePdfRequest
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+ | **template_id** | **String** | **Required.** Template short ID (12 characters) | |
8
+ | **data** | **Hash&lt;String, Object&gt;** | **Required.** Key-value data to render in the template. Keys must match template variables. | |
9
+ | **export_type** | [**ExportType**](ExportType.md) | Export format: &#x60;url&#x60; uploads to CDN and returns URL, &#x60;binary&#x60; returns raw PDF bytes | [optional] |
10
+ | **expiration** | **Integer** | URL expiration in seconds. Min: 60 (1 min), Max: 604800 (7 days). Only applies to &#x60;url&#x60; export type. | [optional][default to 86400] |
11
+ | **filename** | **String** | | [optional] |
12
+ | **store_s3** | **Boolean** | Upload to your configured S3 bucket instead of CDN | [optional][default to false] |
13
+ | **s3_filepath** | **String** | | [optional] |
14
+ | **s3_bucket** | **String** | | [optional] |
15
+
16
+ ## Example
17
+
18
+ ```ruby
19
+ require 'templatefox'
20
+
21
+ instance = TemplateFox::CreatePdfRequest.new(
22
+ template_id: null,
23
+ data: null,
24
+ export_type: null,
25
+ expiration: null,
26
+ filename: null,
27
+ store_s3: null,
28
+ s3_filepath: null,
29
+ s3_bucket: null
30
+ )
31
+ ```
32
+
@@ -0,0 +1,24 @@
1
+ # TemplateFox::CreatePdfResponse
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+ | **url** | **String** | Signed URL to download the PDF (expires after specified time) | |
8
+ | **filename** | **String** | Filename of the generated PDF | |
9
+ | **credits_remaining** | **Integer** | Remaining credits after this request | |
10
+ | **expires_in** | **Integer** | Seconds until URL expires | |
11
+
12
+ ## Example
13
+
14
+ ```ruby
15
+ require 'templatefox'
16
+
17
+ instance = TemplateFox::CreatePdfResponse.new(
18
+ url: null,
19
+ filename: null,
20
+ credits_remaining: null,
21
+ expires_in: null
22
+ )
23
+ ```
24
+
@@ -0,0 +1,15 @@
1
+ # TemplateFox::ExportType
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+
8
+ ## Example
9
+
10
+ ```ruby
11
+ require 'templatefox'
12
+
13
+ instance = TemplateFox::ExportType.new()
14
+ ```
15
+
@@ -0,0 +1,18 @@
1
+ # TemplateFox::HTTPValidationError
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+ | **detail** | [**Array&lt;ValidationError&gt;**](ValidationError.md) | | [optional] |
8
+
9
+ ## Example
10
+
11
+ ```ruby
12
+ require 'templatefox'
13
+
14
+ instance = TemplateFox::HTTPValidationError.new(
15
+ detail: null
16
+ )
17
+ ```
18
+