apiverve_colorpalette 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: 2942768cb138595eb38237312f840ea68e11c9232a69bc0879b2fd7bbe99281e
4
+ data.tar.gz: 3edfa907d04557c345580eee3f11b366bcd4b3aacabf5e58a3e17efeb751b6a7
5
+ SHA512:
6
+ metadata.gz: 87e7dca3dc09fce85be47bab853abaa954390ad19f23c0ade7ba725db280f35e1fc0108490006232e58d9f23095f2ceffef297c0bad1985b9c6a940964fe1409
7
+ data.tar.gz: 6a412cbd0686fa995dc1a28ebd54231c8ffcf04b5679d335f43c9f740a9785e849dfe8a3253147ea0733afcfc1b38a6ce9d75d482b4f3292ad9c37706d4155b2
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,242 @@
1
+ # Color Palette Generator API - Ruby Gem
2
+
3
+ Color Palette is a powerful tool for generating harmonious color palettes. Generate color schemes (mono, contrast, triade, tetrade, analogic) with accessibility data, CSS exports, and palette images.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_colorpalette'
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_colorpalette
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_colorpalette'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Colorpalette::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
+ response = client.execute({
39
+ color: "FF5733",
40
+ scheme: "triade",
41
+ variation: "default",
42
+ count: 5,
43
+ distance: 0.5,
44
+ addComplement: true,
45
+ webSafe:
46
+ })
47
+
48
+ # Print the response
49
+ puts response
50
+ ```
51
+
52
+
53
+ ### Error Handling
54
+
55
+ ```ruby
56
+ begin
57
+ response = client.execute({ color: "FF5733", scheme: "triade", variation: "default", count: 5, distance: 0.5, addComplement: true, webSafe: })
58
+ puts response["data"]
59
+ rescue APIVerve::Colorpalette::ValidationError => e
60
+ puts "Validation error: #{e.errors.join(', ')}"
61
+ rescue APIVerve::Colorpalette::APIError => e
62
+ puts "API error: #{e.message}"
63
+ puts "Status code: #{e.status_code}"
64
+ end
65
+ ```
66
+
67
+ ### Debug Mode
68
+
69
+ ```ruby
70
+ # Enable debug logging
71
+ client = APIVerve::Colorpalette::Client.new(
72
+ api_key: "YOUR_API_KEY",
73
+ debug: true
74
+ )
75
+ ```
76
+
77
+ ## Example Response
78
+
79
+ ```json
80
+ {
81
+ "status": "ok",
82
+ "error": null,
83
+ "data": {
84
+ "source": "#FF5733",
85
+ "sourceName": "Outrageous Orange",
86
+ "hue": 11,
87
+ "scheme": "triade",
88
+ "variation": "soft",
89
+ "distance": 0.5,
90
+ "colorCount": 5,
91
+ "colorPalette": [
92
+ {
93
+ "hex": "#CC988F",
94
+ "name": "Oriental Pink",
95
+ "rgb": {
96
+ "r": 204,
97
+ "g": 152,
98
+ "b": 143
99
+ },
100
+ "hsl": {
101
+ "h": 9,
102
+ "s": 37,
103
+ "l": 68
104
+ },
105
+ "luminance": 0.373,
106
+ "isDark": true,
107
+ "textColor": "#FFFFFF",
108
+ "accessibility": {
109
+ "contrastWithWhite": 2.48,
110
+ "contrastWithBlack": 8.46,
111
+ "wcagAANormal": false,
112
+ "wcagAALarge": false,
113
+ "wcagAAA": false
114
+ }
115
+ },
116
+ {
117
+ "hex": "#805F59",
118
+ "name": "Russett",
119
+ "rgb": {
120
+ "r": 128,
121
+ "g": 95,
122
+ "b": 89
123
+ },
124
+ "hsl": {
125
+ "h": 9,
126
+ "s": 18,
127
+ "l": 43
128
+ },
129
+ "luminance": 0.135,
130
+ "isDark": true,
131
+ "textColor": "#FFFFFF",
132
+ "accessibility": {
133
+ "contrastWithWhite": 5.68,
134
+ "contrastWithBlack": 3.7,
135
+ "wcagAANormal": true,
136
+ "wcagAALarge": true,
137
+ "wcagAAA": false
138
+ }
139
+ },
140
+ {
141
+ "hex": "#E6D2CF",
142
+ "name": "Dust Storm",
143
+ "rgb": {
144
+ "r": 230,
145
+ "g": 210,
146
+ "b": 207
147
+ },
148
+ "hsl": {
149
+ "h": 8,
150
+ "s": 32,
151
+ "l": 86
152
+ },
153
+ "luminance": 0.674,
154
+ "isDark": false,
155
+ "textColor": "#000000",
156
+ "accessibility": {
157
+ "contrastWithWhite": 1.45,
158
+ "contrastWithBlack": 14.48,
159
+ "wcagAANormal": true,
160
+ "wcagAALarge": true,
161
+ "wcagAAA": true
162
+ }
163
+ },
164
+ {
165
+ "hex": "#BF6E60",
166
+ "name": "Contessa",
167
+ "rgb": {
168
+ "r": 191,
169
+ "g": 110,
170
+ "b": 96
171
+ },
172
+ "hsl": {
173
+ "h": 9,
174
+ "s": 43,
175
+ "l": 56
176
+ },
177
+ "luminance": 0.231,
178
+ "isDark": true,
179
+ "textColor": "#FFFFFF",
180
+ "accessibility": {
181
+ "contrastWithWhite": 3.74,
182
+ "contrastWithBlack": 5.61,
183
+ "wcagAANormal": false,
184
+ "wcagAALarge": true,
185
+ "wcagAAA": false
186
+ }
187
+ },
188
+ {
189
+ "hex": "#A2CC8F",
190
+ "name": "Pine Glade",
191
+ "rgb": {
192
+ "r": 162,
193
+ "g": 204,
194
+ "b": 143
195
+ },
196
+ "hsl": {
197
+ "h": 101,
198
+ "s": 37,
199
+ "l": 68
200
+ },
201
+ "luminance": 0.529,
202
+ "isDark": false,
203
+ "textColor": "#000000",
204
+ "accessibility": {
205
+ "contrastWithWhite": 1.82,
206
+ "contrastWithBlack": 11.57,
207
+ "wcagAANormal": true,
208
+ "wcagAALarge": true,
209
+ "wcagAAA": true
210
+ }
211
+ }
212
+ ],
213
+ "colorPaletteRaw": [
214
+ "cc988f",
215
+ "805f59",
216
+ "e6d2cf",
217
+ "bf6e60",
218
+ "a2cc8f"
219
+ ],
220
+ "css": ":root {\n --primary: #CC988F;\n --primary-rgb: 204, 152, 143;\n --secondary: #805F59;\n --secondary-rgb: 128, 95, 89;\n --tertiary: #E6D2CF;\n --tertiary-rgb: 230, 210, 207;\n --quaternary: #BF6E60;\n --quaternary-rgb: 191, 110, 96;\n --quinary: #A2CC8F;\n --quinary-rgb: 162, 204, 143;\n}",
221
+ "image": {
222
+ "imageName": "6ee29826-a52f-4c87-86f5-bef3b49f0dbb_palette.png",
223
+ "format": ".png",
224
+ "downloadURL": "https://storage.googleapis.com/apiverve/APIData/colorpalette/6ee29826-a52f-4c87-86f5-bef3b49f0dbb_palette.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1766010083&Signature=Boef5OapaNmcyp0F8bGmf%2BVfQk3zQkiWcw1THBfbsevtYGZnOuzr7xKDRlk9FYiHidSoMz6wjody2ymL7GzUoHkDvA8PEdSERhAq2z9St5yWlaX1c87KoNh%2FtCQEJqHixYk039NuYyb%2FhJu18JFY1RNrOfo8OPZEn9a3ICQdTDL0fYQEZEBxnDuc%2B7wvn4q9UFWhCJcf302HcoZoCw76AzrgVRu%2FazuahqHdVWMR1K5QTV3U51lSoqC23ERHjRZ6uZB8W0bCO65qBFrRNzWEPSVCC%2F8oafvvitZwB1YCG674q3MbtRhWXIhX2zdoPCT%2BgxL7E4fgIyXDtDLm5%2Bm%2Fsg%3D%3D",
225
+ "expires": 1766010083748
226
+ }
227
+ }
228
+ }
229
+ ```
230
+
231
+ ## Documentation
232
+
233
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/colorpalette?utm_source=rubygems&utm_medium=readme).
234
+
235
+ ## Support
236
+
237
+ - Website: [https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=readme](https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=readme)
238
+ - Email: hello@apiverve.com
239
+
240
+ ## License
241
+
242
+ This gem is available under the [MIT License](LICENSE).
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Colorpalette
9
+ # Client for the Color Palette Generator API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Colorpalette::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ color: "FF5733", scheme: "triade", variation: "default", count: 5, distance: 0.5, addComplement: true, webSafe: })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/colorpalette"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = { 'color' => { type: 'string', required: true, format: 'hexColor' }, 'scheme' => { type: 'string', required: false }, 'variation' => { type: 'string', required: false }, 'count' => { type: 'integer', required: false, min: 1, max: 16 }, 'distance' => { type: 'number', required: false, min: 0, max: 1 }, 'addComplement' => { type: 'boolean', required: false }, 'webSafe' => { type: 'boolean', required: false } }
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 GET request to #{BASE_URL}")
67
+ log("Parameters: #{params.inspect}") if params.any?
68
+
69
+ response = @connection.get do |req|
70
+ params.each { |k, v| req.params[k.to_s] = v }
71
+ end
72
+
73
+ handle_response(response)
74
+ end
75
+
76
+ private
77
+
78
+ def validate_api_key!(api_key)
79
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
80
+
81
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
82
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
83
+ end
84
+ end
85
+
86
+ def validate_params!(params)
87
+ return if VALIDATION_RULES.empty?
88
+
89
+ errors = []
90
+
91
+ VALIDATION_RULES.each do |param_name, rules|
92
+ value = params[param_name.to_sym] || params[param_name]
93
+
94
+ # Check required
95
+ if rules[:required] && (value.nil? || value.to_s.empty?)
96
+ errors << "Required parameter [#{param_name}] is missing."
97
+ next
98
+ end
99
+
100
+ next if value.nil?
101
+
102
+ case rules[:type]
103
+ when "integer", "number"
104
+ begin
105
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
106
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
107
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
108
+ rescue ArgumentError, TypeError
109
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
110
+ end
111
+ when "string"
112
+ unless value.is_a?(String)
113
+ errors << "Parameter [#{param_name}] must be a string."
114
+ next
115
+ end
116
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
117
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
118
+
119
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
120
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
121
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
122
+ end
123
+ end
124
+ when "boolean"
125
+ unless [true, false, "true", "false"].include?(value)
126
+ errors << "Parameter [#{param_name}] must be a boolean."
127
+ end
128
+ end
129
+
130
+ # Enum validation
131
+ if rules[:enum] && !rules[:enum].include?(value)
132
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
133
+ end
134
+ end
135
+
136
+ raise ValidationError, errors unless errors.empty?
137
+ end
138
+
139
+ def handle_response(response)
140
+ log("Response status: #{response.status}")
141
+
142
+ data = JSON.parse(response.body)
143
+
144
+ if data["status"] == "error"
145
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
146
+ end
147
+
148
+ unless response.success?
149
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
150
+ end
151
+
152
+ log("Request successful")
153
+ data
154
+ rescue JSON::ParserError => e
155
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
156
+ end
157
+
158
+ def log(message)
159
+ puts "[APIVerve::Colorpalette] #{message}" if @debug
160
+ end
161
+ end
162
+
163
+ # Custom error class for API errors
164
+ class APIError < StandardError
165
+ attr_reader :status_code, :response
166
+
167
+ def initialize(message, status_code = nil, response = nil)
168
+ @status_code = status_code
169
+ @response = response
170
+ super(message)
171
+ end
172
+ end
173
+
174
+ # Custom error class for validation errors
175
+ class ValidationError < StandardError
176
+ attr_reader :errors
177
+
178
+ def initialize(errors)
179
+ @errors = errors
180
+ super("Validation failed: #{errors.join(' ')}")
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Colorpalette
9
+ # Client for the Color Palette Generator API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Colorpalette::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ color: "FF5733", scheme: "triade", variation: "default", count: 5, distance: 0.5, addComplement: true, webSafe: })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/colorpalette"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = {
23
+ 'color' => { type: 'string', required: true, format: 'hexColor' },
24
+ 'scheme' => { type: 'string', required: false },
25
+ 'variation' => { type: 'string', required: false },
26
+ 'count' => { type: 'integer', required: false, min: 1, max: 16 },
27
+ 'distance' => { type: 'number', required: false, min: 0, max: 1 },
28
+ 'addComplement' => { type: 'boolean', required: false },
29
+ 'webSafe' => { type: 'boolean', required: false }
30
+ }
31
+
32
+ # Format validation patterns
33
+ FORMAT_PATTERNS = {
34
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
35
+ 'url' => /^https?:\/\/.+/,
36
+ '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}$/,
37
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
38
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
39
+ }.freeze
40
+
41
+ # Initialize the client
42
+ #
43
+ # @param api_key [String] Your APIVerve API key
44
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
45
+ # @param debug [Boolean] Enable debug logging (default: false)
46
+ # @raise [ArgumentError] If API key is invalid
47
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
48
+ validate_api_key!(api_key)
49
+
50
+ @api_key = api_key
51
+ @timeout = timeout
52
+ @debug = debug
53
+
54
+ @connection = Faraday.new(url: BASE_URL) do |conn|
55
+ conn.request :multipart
56
+ conn.request :url_encoded
57
+ conn.adapter Faraday.default_adapter
58
+ conn.options.timeout = @timeout
59
+ conn.headers["x-api-key"] = @api_key
60
+ conn.headers["auth-mode"] = "rubygems-package"
61
+ conn.headers["Content-Type"] = "application/json"
62
+ end
63
+ end
64
+
65
+ # Execute the API request
66
+ #
67
+ # @param params [Hash] Query parameters or request body
68
+ # @return [Hash] API response
69
+ # @raise [APIError] If the request fails
70
+ # @raise [ValidationError] If parameter validation fails
71
+ def execute(params = {})
72
+ validate_params!(params)
73
+
74
+ log("Making GET request to #{BASE_URL}")
75
+ log("Parameters: #{params.inspect}") if params.any?
76
+
77
+ response = @connection.get do |req|
78
+ params.each { |k, v| req.params[k.to_s] = v }
79
+ end
80
+
81
+ handle_response(response)
82
+ end
83
+
84
+ private
85
+
86
+ def validate_api_key!(api_key)
87
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
88
+
89
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
90
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
91
+ end
92
+ end
93
+
94
+ def validate_params!(params)
95
+ return if VALIDATION_RULES.empty?
96
+
97
+ errors = []
98
+
99
+ VALIDATION_RULES.each do |param_name, rules|
100
+ value = params[param_name.to_sym] || params[param_name]
101
+
102
+ # Check required
103
+ if rules[:required] && (value.nil? || value.to_s.empty?)
104
+ errors << "Required parameter [#{param_name}] is missing."
105
+ next
106
+ end
107
+
108
+ next if value.nil?
109
+
110
+ case rules[:type]
111
+ when "integer", "number"
112
+ begin
113
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
114
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
115
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
116
+ rescue ArgumentError, TypeError
117
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
118
+ end
119
+ when "string"
120
+ unless value.is_a?(String)
121
+ errors << "Parameter [#{param_name}] must be a string."
122
+ next
123
+ end
124
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
125
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
126
+
127
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
128
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
129
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
130
+ end
131
+ end
132
+ when "boolean"
133
+ unless [true, false, "true", "false"].include?(value)
134
+ errors << "Parameter [#{param_name}] must be a boolean."
135
+ end
136
+ end
137
+
138
+ # Enum validation
139
+ if rules[:enum] && !rules[:enum].include?(value)
140
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
141
+ end
142
+ end
143
+
144
+ raise ValidationError, errors unless errors.empty?
145
+ end
146
+
147
+ def handle_response(response)
148
+ log("Response status: #{response.status}")
149
+
150
+ data = JSON.parse(response.body)
151
+
152
+ if data["status"] == "error"
153
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
154
+ end
155
+
156
+ unless response.success?
157
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
158
+ end
159
+
160
+ log("Request successful")
161
+ data
162
+ rescue JSON::ParserError => e
163
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
164
+ end
165
+
166
+ def log(message)
167
+ puts "[APIVerve::Colorpalette] #{message}" if @debug
168
+ end
169
+ end
170
+
171
+ # Custom error class for API errors
172
+ class APIError < StandardError
173
+ attr_reader :status_code, :response
174
+
175
+ def initialize(message, status_code = nil, response = nil)
176
+ @status_code = status_code
177
+ @response = response
178
+ super(message)
179
+ end
180
+ end
181
+
182
+ # Custom error class for validation errors
183
+ class ValidationError < StandardError
184
+ attr_reader :errors
185
+
186
+ def initialize(errors)
187
+ @errors = errors
188
+ super("Validation failed: #{errors.join(' ')}")
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apiverve_colorpalette/client"
4
+
5
+ module APIVerve
6
+ module Colorpalette
7
+ VERSION = "1.2.0"
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiverve_colorpalette
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: Color Palette is a powerful tool for generating harmonious color palettes.
61
+ Generate color schemes (mono, contrast, triade, tetrade, analogic) with accessibility
62
+ data, CSS exports, and palette 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_colorpalette.rb
73
+ - lib/apiverve_colorpalette/client.rb
74
+ homepage: https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=homepage
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://apiverve.com/marketplace/colorpalette?utm_source=ruby&utm_medium=homepage
79
+ source_code_uri: https://github.com/apiverve/colorpalette-API/tree/main/ruby
80
+ changelog_uri: https://apiverve.com/changelog
81
+ documentation_uri: https://docs.apiverve.com/ref/colorpalette
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: Color Palette Generator API - Ruby Client
99
+ test_files: []