apiverve_spellingbee 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: 788a66d5dc95ffbac6cfe1659270783ae42b236f478b4163c722c301ccba18c5
4
+ data.tar.gz: 8d48d180a7b16cc9b6cc13f5dd1c6d68cf8b986819eb189b802873a3ab340c8a
5
+ SHA512:
6
+ metadata.gz: 0f6c0628a244b8074d193d3d3466d4550ee26448f1f54027a69584c02f83c0ded32aa560b741e0e9a2bc33712abc371292a2cfea0bee7aa8ecde7fd13fb0661e
7
+ data.tar.gz: 5a179ae0179b211aa04e3b903bb4023420590bb20b4bc09565f3078755679aad1f633308fb32e6fdcdb39e9fa7b704d3fc25c96fdf091f4efa05e8063df1451c
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,390 @@
1
+ # Spelling Bee Generator API - Ruby Gem
2
+
3
+ Spelling Bee Generator creates word puzzles with 7 letters where players form words using a required center letter.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_spellingbee'
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_spellingbee
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_spellingbee'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Spellingbee::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
+ response = client.execute({
39
+ difficulty: "medium",
40
+ image: true
41
+ })
42
+
43
+ # Print the response
44
+ puts response
45
+ ```
46
+
47
+
48
+ ### Error Handling
49
+
50
+ ```ruby
51
+ begin
52
+ response = client.execute({ difficulty: "medium", image: true })
53
+ puts response["data"]
54
+ rescue APIVerve::Spellingbee::ValidationError => e
55
+ puts "Validation error: #{e.errors.join(', ')}"
56
+ rescue APIVerve::Spellingbee::APIError => e
57
+ puts "API error: #{e.message}"
58
+ puts "Status code: #{e.status_code}"
59
+ end
60
+ ```
61
+
62
+ ### Debug Mode
63
+
64
+ ```ruby
65
+ # Enable debug logging
66
+ client = APIVerve::Spellingbee::Client.new(
67
+ api_key: "YOUR_API_KEY",
68
+ debug: true
69
+ )
70
+ ```
71
+
72
+ ## Example Response
73
+
74
+ ```json
75
+ {
76
+ "status": "ok",
77
+ "error": null,
78
+ "data": {
79
+ "centerLetter": "A",
80
+ "outerLetters": [
81
+ "C",
82
+ "H",
83
+ "E",
84
+ "J",
85
+ "O",
86
+ "D"
87
+ ],
88
+ "allLetters": [
89
+ "A",
90
+ "C",
91
+ "H",
92
+ "E",
93
+ "J",
94
+ "O",
95
+ "D"
96
+ ],
97
+ "difficulty": "medium",
98
+ "wordCount": 53,
99
+ "pangramCount": 0,
100
+ "maxPoints": 200,
101
+ "words": [
102
+ {
103
+ "word": "DEADHEADED",
104
+ "points": 10,
105
+ "isPangram": false
106
+ },
107
+ {
108
+ "word": "COHEADED",
109
+ "points": 8,
110
+ "isPangram": false
111
+ },
112
+ {
113
+ "word": "DEADHEAD",
114
+ "points": 8,
115
+ "isPangram": false
116
+ },
117
+ {
118
+ "word": "HEADACHE",
119
+ "points": 8,
120
+ "isPangram": false
121
+ },
122
+ {
123
+ "word": "ACCEDED",
124
+ "points": 7,
125
+ "isPangram": false
126
+ },
127
+ {
128
+ "word": "COACHED",
129
+ "points": 7,
130
+ "isPangram": false
131
+ },
132
+ {
133
+ "word": "ACCEDE",
134
+ "points": 6,
135
+ "isPangram": false
136
+ },
137
+ {
138
+ "word": "AHCHOO",
139
+ "points": 6,
140
+ "isPangram": false
141
+ },
142
+ {
143
+ "word": "CACHED",
144
+ "points": 6,
145
+ "isPangram": false
146
+ },
147
+ {
148
+ "word": "COHEAD",
149
+ "points": 6,
150
+ "isPangram": false
151
+ },
152
+ {
153
+ "word": "DADOED",
154
+ "points": 6,
155
+ "isPangram": false
156
+ },
157
+ {
158
+ "word": "DECADE",
159
+ "points": 6,
160
+ "isPangram": false
161
+ },
162
+ {
163
+ "word": "DOODAD",
164
+ "points": 6,
165
+ "isPangram": false
166
+ },
167
+ {
168
+ "word": "HADJEE",
169
+ "points": 6,
170
+ "isPangram": false
171
+ },
172
+ {
173
+ "word": "HEADED",
174
+ "points": 6,
175
+ "isPangram": false
176
+ },
177
+ {
178
+ "word": "AAHED",
179
+ "points": 5,
180
+ "isPangram": false
181
+ },
182
+ {
183
+ "word": "ACHED",
184
+ "points": 5,
185
+ "isPangram": false
186
+ },
187
+ {
188
+ "word": "ACHOO",
189
+ "points": 5,
190
+ "isPangram": false
191
+ },
192
+ {
193
+ "word": "ADDED",
194
+ "points": 5,
195
+ "isPangram": false
196
+ },
197
+ {
198
+ "word": "AHEAD",
199
+ "points": 5,
200
+ "isPangram": false
201
+ },
202
+ {
203
+ "word": "CACAO",
204
+ "points": 5,
205
+ "isPangram": false
206
+ },
207
+ {
208
+ "word": "CACHE",
209
+ "points": 5,
210
+ "isPangram": false
211
+ },
212
+ {
213
+ "word": "CAECA",
214
+ "points": 5,
215
+ "isPangram": false
216
+ },
217
+ {
218
+ "word": "COACH",
219
+ "points": 5,
220
+ "isPangram": false
221
+ },
222
+ {
223
+ "word": "COCOA",
224
+ "points": 5,
225
+ "isPangram": false
226
+ },
227
+ {
228
+ "word": "DACHA",
229
+ "points": 5,
230
+ "isPangram": false
231
+ },
232
+ {
233
+ "word": "HADED",
234
+ "points": 5,
235
+ "isPangram": false
236
+ },
237
+ {
238
+ "word": "HODAD",
239
+ "points": 5,
240
+ "isPangram": false
241
+ },
242
+ {
243
+ "word": "JADED",
244
+ "points": 5,
245
+ "isPangram": false
246
+ },
247
+ {
248
+ "word": "JEHAD",
249
+ "points": 5,
250
+ "isPangram": false
251
+ },
252
+ {
253
+ "word": "ACED",
254
+ "points": 1,
255
+ "isPangram": false
256
+ },
257
+ {
258
+ "word": "ACHE",
259
+ "points": 1,
260
+ "isPangram": false
261
+ },
262
+ {
263
+ "word": "AHED",
264
+ "points": 1,
265
+ "isPangram": false
266
+ },
267
+ {
268
+ "word": "AJEE",
269
+ "points": 1,
270
+ "isPangram": false
271
+ },
272
+ {
273
+ "word": "CACA",
274
+ "points": 1,
275
+ "isPangram": false
276
+ },
277
+ {
278
+ "word": "CADE",
279
+ "points": 1,
280
+ "isPangram": false
281
+ },
282
+ {
283
+ "word": "CECA",
284
+ "points": 1,
285
+ "isPangram": false
286
+ },
287
+ {
288
+ "word": "CHAD",
289
+ "points": 1,
290
+ "isPangram": false
291
+ },
292
+ {
293
+ "word": "CHAO",
294
+ "points": 1,
295
+ "isPangram": false
296
+ },
297
+ {
298
+ "word": "COCA",
299
+ "points": 1,
300
+ "isPangram": false
301
+ },
302
+ {
303
+ "word": "CODA",
304
+ "points": 1,
305
+ "isPangram": false
306
+ },
307
+ {
308
+ "word": "DACE",
309
+ "points": 1,
310
+ "isPangram": false
311
+ },
312
+ {
313
+ "word": "DADA",
314
+ "points": 1,
315
+ "isPangram": false
316
+ },
317
+ {
318
+ "word": "DADO",
319
+ "points": 1,
320
+ "isPangram": false
321
+ },
322
+ {
323
+ "word": "DEAD",
324
+ "points": 1,
325
+ "isPangram": false
326
+ },
327
+ {
328
+ "word": "EACH",
329
+ "points": 1,
330
+ "isPangram": false
331
+ },
332
+ {
333
+ "word": "HADE",
334
+ "points": 1,
335
+ "isPangram": false
336
+ },
337
+ {
338
+ "word": "HADJ",
339
+ "points": 1,
340
+ "isPangram": false
341
+ },
342
+ {
343
+ "word": "HAED",
344
+ "points": 1,
345
+ "isPangram": false
346
+ },
347
+ {
348
+ "word": "HAHA",
349
+ "points": 1,
350
+ "isPangram": false
351
+ },
352
+ {
353
+ "word": "HAJJ",
354
+ "points": 1,
355
+ "isPangram": false
356
+ },
357
+ {
358
+ "word": "HEAD",
359
+ "points": 1,
360
+ "isPangram": false
361
+ },
362
+ {
363
+ "word": "JADE",
364
+ "points": 1,
365
+ "isPangram": false
366
+ }
367
+ ],
368
+ "html": "<html><head><title>Spelling Bee</title><style>body {font-family: Arial, sans-serif; padding: 20px; max-width: 500px; margin: 0 auto; text-align: center;}h1 {color: #F9A825;}.honeycomb {display: flex; flex-wrap: wrap; justify-content: center; max-width: 200px; margin: 30px auto;}.hex {width: 60px; height: 52px; background: #E0E0E0; margin: 2px; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: bold; clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);}.hex.center {background: #F9A825; color: white;}.stats {margin: 20px 0; font-size: 14px; color: #666;}.rules {text-align: left; background: #FFF8E1; padding: 15px; border-radius: 10px; margin-top: 20px;}.rules h3 {margin-top: 0; color: #F9A825;}.rules ul {margin: 0; padding-left: 20px;}</style></head><body><h1>Spelling Bee</h1><div class='honeycomb'><div class='hex center'>A</div><div class='hex'>C</div><div class='hex'>H</div><div class='hex'>E</div><div class='hex'>J</div><div class='hex'>O</div><div class='hex'>D</div></div><div class='stats'>53 words | 200 possible points</div><div class='rules'><h3>How to Play:</h3><ul><li>Create words using the letters shown</li><li>Words must contain the center letter (yellow)</li><li>Words must be at least 4 letters long</li><li>Letters can be used more than once</li><li>4-letter words = 1 point</li><li>Longer words = 1 point per letter</li><li>Pangrams (use all 7 letters) = +7 bonus points</li></ul></div></body></html>",
369
+ "image": {
370
+ "imageName": "0f8f8f2c-ac7d-46f9-b5fc-e2d777117f13.png",
371
+ "format": ".png",
372
+ "downloadURL": "https://storage.googleapis.com/apiverve/APIData/spellingbee/0f8f8f2c-ac7d-46f9-b5fc-e2d777117f13.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1766010561&Signature=cHvKHU7wb0RwJKVI6FGIS8%2B8%2BencmsoWEuH%2FT2cQsUjPTY%2FFLhSzipEyHex5HCEg5q8jEiRB3wZDXF9lyONQTVSNdZp0Xpm6Fw69tZZDvCeHePwa1v0h0rktZ6PLSbRswtr0vlHDZL3JPBl7i%2FsxM8QxTdGDOs7cyULy3d9qEyuPPIEDkOF1cnQce2qThIhZ%2BHieQNsBVX193NhyeCrgfRVQVPiFYo4ngSbOrMJKpVm2aSbtykG6Hyw%2B8RnQqkBqA5JB8XaB2ESBg0ZU8ldZUNoHd4cMoC2Oz4rI5FkLuQ2tzju9FVsxsCXiVvJCPd9jsWOlhQ7T1NVp%2FwV107k38w%3D%3D",
373
+ "expires": 1766010561052
374
+ }
375
+ }
376
+ }
377
+ ```
378
+
379
+ ## Documentation
380
+
381
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/spellingbee?utm_source=rubygems&utm_medium=readme).
382
+
383
+ ## Support
384
+
385
+ - Website: [https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=readme](https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=readme)
386
+ - Email: hello@apiverve.com
387
+
388
+ ## License
389
+
390
+ 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 Spellingbee
9
+ # Client for the Spelling Bee Generator API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Spellingbee::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ difficulty: "medium", image: true })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/spellingbee"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = { 'difficulty' => { type: 'string', required: false }, 'image' => { 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::Spellingbee] #{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,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Spellingbee
9
+ # Client for the Spelling Bee Generator API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Spellingbee::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ difficulty: "medium" })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/spellingbee"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = {
23
+ 'difficulty' => { type: 'string', required: false }
24
+ }
25
+
26
+ # Format validation patterns
27
+ FORMAT_PATTERNS = {
28
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
29
+ 'url' => /^https?:\/\/.+/,
30
+ '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}$/,
31
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
32
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
33
+ }.freeze
34
+
35
+ # Initialize the client
36
+ #
37
+ # @param api_key [String] Your APIVerve API key
38
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
39
+ # @param debug [Boolean] Enable debug logging (default: false)
40
+ # @raise [ArgumentError] If API key is invalid
41
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
42
+ validate_api_key!(api_key)
43
+
44
+ @api_key = api_key
45
+ @timeout = timeout
46
+ @debug = debug
47
+
48
+ @connection = Faraday.new(url: BASE_URL) do |conn|
49
+ conn.request :multipart
50
+ conn.request :url_encoded
51
+ conn.adapter Faraday.default_adapter
52
+ conn.options.timeout = @timeout
53
+ conn.headers["x-api-key"] = @api_key
54
+ conn.headers["auth-mode"] = "rubygems-package"
55
+ conn.headers["Content-Type"] = "application/json"
56
+ end
57
+ end
58
+
59
+ # Execute the API request
60
+ #
61
+ # @param params [Hash] Query parameters or request body
62
+ # @return [Hash] API response
63
+ # @raise [APIError] If the request fails
64
+ # @raise [ValidationError] If parameter validation fails
65
+ def execute(params = {})
66
+ validate_params!(params)
67
+
68
+ log("Making GET request to #{BASE_URL}")
69
+ log("Parameters: #{params.inspect}") if params.any?
70
+
71
+ response = @connection.get do |req|
72
+ params.each { |k, v| req.params[k.to_s] = v }
73
+ end
74
+
75
+ handle_response(response)
76
+ end
77
+
78
+ private
79
+
80
+ def validate_api_key!(api_key)
81
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
82
+
83
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
84
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
85
+ end
86
+ end
87
+
88
+ def validate_params!(params)
89
+ return if VALIDATION_RULES.empty?
90
+
91
+ errors = []
92
+
93
+ VALIDATION_RULES.each do |param_name, rules|
94
+ value = params[param_name.to_sym] || params[param_name]
95
+
96
+ # Check required
97
+ if rules[:required] && (value.nil? || value.to_s.empty?)
98
+ errors << "Required parameter [#{param_name}] is missing."
99
+ next
100
+ end
101
+
102
+ next if value.nil?
103
+
104
+ case rules[:type]
105
+ when "integer", "number"
106
+ begin
107
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
108
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
109
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
110
+ rescue ArgumentError, TypeError
111
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
112
+ end
113
+ when "string"
114
+ unless value.is_a?(String)
115
+ errors << "Parameter [#{param_name}] must be a string."
116
+ next
117
+ end
118
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
119
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
120
+
121
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
122
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
123
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
124
+ end
125
+ end
126
+ when "boolean"
127
+ unless [true, false, "true", "false"].include?(value)
128
+ errors << "Parameter [#{param_name}] must be a boolean."
129
+ end
130
+ end
131
+
132
+ # Enum validation
133
+ if rules[:enum] && !rules[:enum].include?(value)
134
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
135
+ end
136
+ end
137
+
138
+ raise ValidationError, errors unless errors.empty?
139
+ end
140
+
141
+ def handle_response(response)
142
+ log("Response status: #{response.status}")
143
+
144
+ data = JSON.parse(response.body)
145
+
146
+ if data["status"] == "error"
147
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
148
+ end
149
+
150
+ unless response.success?
151
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
152
+ end
153
+
154
+ log("Request successful")
155
+ data
156
+ rescue JSON::ParserError => e
157
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
158
+ end
159
+
160
+ def log(message)
161
+ puts "[APIVerve::Spellingbee] #{message}" if @debug
162
+ end
163
+ end
164
+
165
+ # Custom error class for API errors
166
+ class APIError < StandardError
167
+ attr_reader :status_code, :response
168
+
169
+ def initialize(message, status_code = nil, response = nil)
170
+ @status_code = status_code
171
+ @response = response
172
+ super(message)
173
+ end
174
+ end
175
+
176
+ # Custom error class for validation errors
177
+ class ValidationError < StandardError
178
+ attr_reader :errors
179
+
180
+ def initialize(errors)
181
+ @errors = errors
182
+ super("Validation failed: #{errors.join(' ')}")
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apiverve_spellingbee/client"
4
+
5
+ module APIVerve
6
+ module Spellingbee
7
+ VERSION = "1.2.0"
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiverve_spellingbee
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: Spelling Bee Generator creates word puzzles with 7 letters where players
61
+ form words using a required center letter.
62
+ email:
63
+ - hello@apiverve.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE
69
+ - README.md
70
+ - lib/apiverve/client.rb
71
+ - lib/apiverve_spellingbee.rb
72
+ - lib/apiverve_spellingbee/client.rb
73
+ homepage: https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=homepage
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://apiverve.com/marketplace/spellingbee?utm_source=ruby&utm_medium=homepage
78
+ source_code_uri: https://github.com/apiverve/spellingbee-API/tree/main/ruby
79
+ changelog_uri: https://apiverve.com/changelog
80
+ documentation_uri: https://docs.apiverve.com/ref/spellingbee
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.7.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.6.9
96
+ specification_version: 4
97
+ summary: Spelling Bee Generator API - Ruby Client
98
+ test_files: []