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