apiverve_pdftoimage 1.2.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a8d15a50920cef9be6484fecff244a5ca5688b13fcd42d5d46ff2119b03256b3
4
+ data.tar.gz: 303b9f71b2a9078b1050b1da74f4eca82503857df890e953d68274979b76d582
5
+ SHA512:
6
+ metadata.gz: f515044b7e90fe372811e8f40571a04b6a3b153f8bf12b23f28fdeb4fc391dc9f6b1e14c83dd3a3d1c5ad83f31160c7ce6e096b099c8ab733250831514214dae
7
+ data.tar.gz: fd8ca10983adc66bc329b34b463e2b3844925904a958245ba2f64da9ac512a16d32ec41d27a4f590f51438ae2117203098c428298426b168e2441db90b5425c0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 APIVerve and EvlarSoft LLC
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,129 @@
1
+ # PDF to Image API - Ruby Gem
2
+
3
+ PDF to Image renders the pages you choose from a PDF, uploaded or fetched from a URL, as PNG or JPG images and returns a download link for each, valid for 2 days, with its pixel size. The Free plan renders one page per call at 150 dpi; paid plans render up to 10 pages per call and can set the resolution from 72 to 300 dpi.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_pdftoimage'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install apiverve_pdftoimage
23
+ ```
24
+
25
+ ## Getting Started
26
+
27
+ Get your API key at [APIVerve](https://apiverve.com)
28
+
29
+ ### Basic Usage
30
+
31
+ ```ruby
32
+ require 'apiverve_pdftoimage'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Pdftoimage::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
+ response = client.execute({
39
+ pdf: "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf",
40
+ pages: "1-2",
41
+ format: "png"
42
+ })
43
+
44
+ # Print the response
45
+ puts response
46
+ ```
47
+
48
+ ### File Upload
49
+
50
+ ```ruby
51
+ # Upload a file
52
+ response = client.execute_with_file("/path/to/file.jpg")
53
+
54
+ # Or use a URL
55
+ response = client.execute_with_url("https://example.com/image.jpg")
56
+ ```
57
+
58
+ ### Error Handling
59
+
60
+ ```ruby
61
+ begin
62
+ response = client.execute({ pdf: "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf", pages: "1-2", format: "png" })
63
+ puts response["data"]
64
+ rescue APIVerve::Pdftoimage::ValidationError => e
65
+ puts "Validation error: #{e.errors.join(', ')}"
66
+ rescue APIVerve::Pdftoimage::APIError => e
67
+ puts "API error: #{e.message}"
68
+ puts "Status code: #{e.status_code}"
69
+ end
70
+ ```
71
+
72
+ ### Debug Mode
73
+
74
+ ```ruby
75
+ # Enable debug logging
76
+ client = APIVerve::Pdftoimage::Client.new(
77
+ api_key: "YOUR_API_KEY",
78
+ debug: true
79
+ )
80
+ ```
81
+
82
+ ## Example Response
83
+
84
+ ```json
85
+ {
86
+ "status": "ok",
87
+ "error": null,
88
+ "data": {
89
+ "pageCount": 14,
90
+ "format": "png",
91
+ "dpi": 150,
92
+ "imageCount": 2,
93
+ "expires": 1792400000000,
94
+ "images": [
95
+ {
96
+ "page": 1,
97
+ "imageName": "3b7e9d21-4c5a-4f80-a1d6-9e2c8b7f5a34-1.png",
98
+ "width": 1275,
99
+ "height": 1650,
100
+ "dpi": 150,
101
+ "size": 214533,
102
+ "downloadURL": "https://storage.googleapis.com/apiverve/APIData/pdftoimage/3b7e9d21-4c5a-4f80-a1d6-9e2c8b7f5a34-1.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1792400000&Signature=SAMPLE"
103
+ },
104
+ {
105
+ "page": 2,
106
+ "imageName": "3b7e9d21-4c5a-4f80-a1d6-9e2c8b7f5a34-2.png",
107
+ "width": 1275,
108
+ "height": 1650,
109
+ "dpi": 150,
110
+ "size": 198207,
111
+ "downloadURL": "https://storage.googleapis.com/apiverve/APIData/pdftoimage/3b7e9d21-4c5a-4f80-a1d6-9e2c8b7f5a34-2.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1792400000&Signature=SAMPLE"
112
+ }
113
+ ]
114
+ }
115
+ }
116
+ ```
117
+
118
+ ## Documentation
119
+
120
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/pdftoimage?utm_source=rubygems&utm_medium=referral&utm_content=readme).
121
+
122
+ ## Support
123
+
124
+ - Website: [https://apiverve.com/marketplace/pdftoimage?utm_source=ruby&utm_medium=referral&utm_content=readme](https://apiverve.com/marketplace/pdftoimage?utm_source=ruby&utm_medium=referral&utm_content=readme)
125
+ - Email: hello@apiverve.com
126
+
127
+ ## License
128
+
129
+ This gem is available under the [MIT License](LICENSE).
@@ -0,0 +1,238 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Pdftoimage
9
+ # Client for the PDF to Image API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Pdftoimage::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ pdf: "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf", pages: "1-2", format: "png" })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/pdftoimage?utm_source=ruby&utm_medium=referral&utm_content=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/pdftoimage"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = { 'pdf' => { type: 'string', required: false }, 'pages' => { type: 'string', required: false, max_length: 100 }, 'format' => { type: 'string', required: false }, 'quality' => { type: 'integer', required: false, min: 1, max: 100 }, 'dpi' => { type: 'integer', required: false, min: 72, max: 300 } }
23
+
24
+ # Format validation patterns
25
+ FORMAT_PATTERNS = {
26
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
27
+ 'url' => /^https?:\/\/.+/,
28
+ 'ip' => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
29
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
30
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
31
+ }.freeze
32
+
33
+ # Initialize the client
34
+ #
35
+ # @param api_key [String] Your APIVerve API key
36
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
37
+ # @param debug [Boolean] Enable debug logging (default: false)
38
+ # @raise [ArgumentError] If API key is invalid
39
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
40
+ validate_api_key!(api_key)
41
+
42
+ @api_key = api_key
43
+ @timeout = timeout
44
+ @debug = debug
45
+
46
+ @connection = Faraday.new(url: BASE_URL) do |conn|
47
+ conn.request :multipart
48
+ conn.request :url_encoded
49
+ conn.adapter Faraday.default_adapter
50
+ conn.options.timeout = @timeout
51
+ conn.headers["x-api-key"] = @api_key
52
+ conn.headers["auth-mode"] = "rubygems-package"
53
+ conn.headers["Content-Type"] = "application/json"
54
+ end
55
+ end
56
+
57
+ # Execute the API request
58
+ #
59
+ # @param params [Hash] Query parameters or request body
60
+ # @return [Hash] API response
61
+ # @raise [APIError] If the request fails
62
+ # @raise [ValidationError] If parameter validation fails
63
+ def execute(params = {})
64
+ validate_params!(params)
65
+
66
+ log("Making POST request to #{BASE_URL}")
67
+ log("Parameters: #{params.inspect}") if params.any?
68
+
69
+ response = @connection.post do |req|
70
+ req.body = params.to_json
71
+ end
72
+
73
+ handle_response(response)
74
+ end
75
+
76
+ # Execute the API request with a file upload
77
+ #
78
+ # @param file_path [String] Path to the file to upload
79
+ # @param params [Hash] Additional parameters
80
+ # @return [Hash] API response
81
+ # @raise [APIError] If the request fails
82
+ # @raise [ArgumentError] If the file doesn't exist
83
+ def execute_with_file(file_path, params = {})
84
+ raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path)
85
+
86
+ log("Uploading file: #{file_path}")
87
+
88
+ payload = {
89
+ "pdf" => Faraday::Multipart::FilePart.new(
90
+ file_path,
91
+ mime_type_for(file_path),
92
+ File.basename(file_path)
93
+ )
94
+ }
95
+ payload.merge!(params.transform_keys(&:to_s))
96
+
97
+ response = @connection.post do |req|
98
+ req.headers.delete("Content-Type") # Let Faraday set it
99
+ req.body = payload
100
+ end
101
+
102
+ handle_response(response)
103
+ end
104
+
105
+ # Execute the API request with a file URL
106
+ #
107
+ # @param url [String] URL of the file to process
108
+ # @param params [Hash] Additional parameters
109
+ # @return [Hash] API response
110
+ # @raise [APIError] If the request fails
111
+ def execute_with_url(url, params = {})
112
+ raise ArgumentError, "URL must be a string" unless url.is_a?(String)
113
+ raise ArgumentError, "Invalid URL format" unless url.match?(/^https?:\/\/.+/)
114
+
115
+ execute(params.merge(url: url))
116
+ end
117
+
118
+ private
119
+
120
+ def mime_type_for(file_path)
121
+ ext = File.extname(file_path).downcase
122
+ case ext
123
+ when ".jpg", ".jpeg" then "image/jpeg"
124
+ when ".png" then "image/png"
125
+ when ".gif" then "image/gif"
126
+ when ".webp" then "image/webp"
127
+ when ".pdf" then "application/pdf"
128
+ else "application/octet-stream"
129
+ end
130
+ end
131
+
132
+ def validate_api_key!(api_key)
133
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
134
+
135
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
136
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
137
+ end
138
+ end
139
+
140
+ def validate_params!(params)
141
+ return if VALIDATION_RULES.empty?
142
+
143
+ errors = []
144
+
145
+ VALIDATION_RULES.each do |param_name, rules|
146
+ value = params[param_name.to_sym] || params[param_name]
147
+
148
+ # Check required
149
+ if rules[:required] && (value.nil? || value.to_s.empty?)
150
+ errors << "Required parameter [#{param_name}] is missing."
151
+ next
152
+ end
153
+
154
+ next if value.nil?
155
+
156
+ case rules[:type]
157
+ when "integer", "number"
158
+ begin
159
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
160
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
161
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
162
+ rescue ArgumentError, TypeError
163
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
164
+ end
165
+ when "string"
166
+ unless value.is_a?(String)
167
+ errors << "Parameter [#{param_name}] must be a string."
168
+ next
169
+ end
170
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
171
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
172
+
173
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
174
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
175
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
176
+ end
177
+ end
178
+ when "boolean"
179
+ unless [true, false, "true", "false"].include?(value)
180
+ errors << "Parameter [#{param_name}] must be a boolean."
181
+ end
182
+ end
183
+
184
+ # Enum validation
185
+ if rules[:enum] && !rules[:enum].include?(value)
186
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
187
+ end
188
+ end
189
+
190
+ raise ValidationError, errors unless errors.empty?
191
+ end
192
+
193
+ def handle_response(response)
194
+ log("Response status: #{response.status}")
195
+
196
+ data = JSON.parse(response.body)
197
+
198
+ if data["status"] == "error"
199
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
200
+ end
201
+
202
+ unless response.success?
203
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
204
+ end
205
+
206
+ log("Request successful")
207
+ data
208
+ rescue JSON::ParserError => e
209
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
210
+ end
211
+
212
+ def log(message)
213
+ puts "[APIVerve::Pdftoimage] #{message}" if @debug
214
+ end
215
+ end
216
+
217
+ # Custom error class for API errors
218
+ class APIError < StandardError
219
+ attr_reader :status_code, :response
220
+
221
+ def initialize(message, status_code = nil, response = nil)
222
+ @status_code = status_code
223
+ @response = response
224
+ super(message)
225
+ end
226
+ end
227
+
228
+ # Custom error class for validation errors
229
+ class ValidationError < StandardError
230
+ attr_reader :errors
231
+
232
+ def initialize(errors)
233
+ @errors = errors
234
+ super("Validation failed: #{errors.join(' ')}")
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apiverve_pdftoimage/client"
4
+
5
+ module APIVerve
6
+ module Pdftoimage
7
+ VERSION = "1.2.2"
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiverve_pdftoimage
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.2
5
+ platform: ruby
6
+ authors:
7
+ - APIVerve
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday-multipart
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ description: PDF to Image renders the pages you choose from a PDF, uploaded or fetched
62
+ from a URL, as PNG or JPG images and returns a download link for each, valid for
63
+ 2 days, with its pixel size. The Free plan renders one page per call at 150 dpi;
64
+ paid plans render up to 10 pages per call and can set the resolution from 72 to
65
+ 300 dpi.
66
+ email:
67
+ - hello@apiverve.com
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - LICENSE
73
+ - README.md
74
+ - lib/apiverve_pdftoimage.rb
75
+ - lib/apiverve_pdftoimage/client.rb
76
+ homepage: https://apiverve.com/marketplace/pdftoimage?utm_source=ruby&utm_medium=referral&utm_content=homepage
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://apiverve.com/marketplace/pdftoimage?utm_source=ruby&utm_medium=referral&utm_content=homepage
81
+ source_code_uri: https://github.com/apiverve/pdftoimage-API/tree/main/ruby
82
+ changelog_uri: https://apiverve.com/changelog
83
+ documentation_uri: https://docs.apiverve.com/ref/pdftoimage
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.7.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: PDF to Image API - Ruby Client
103
+ test_files: []