apiverve_objectdetector 1.2.6

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: ea7d6bab7b8413a9e5982aad11f55b8af45e8f8b248fba79b9e3a9ff9dc012dd
4
+ data.tar.gz: 4e84425777ef3572709a303345dec3175da82705363b6dfe123b1cf9032ec54d
5
+ SHA512:
6
+ metadata.gz: 12c922be5ea8d0333054c78c834fdd6baadd2bd5d731db670677736c22a0e70fb336a65199ae6382ee26504e679e296de4a86adcef601982916d63319744a4dc
7
+ data.tar.gz: b41ebba7e483bb5026e0e158087ffea33bcb12771c632304e0826ac7e0090277a4cc2cb666cd2657bcaa41a13bb5216d1d7cffe5060ecf0f704c25dce9b5bd4a
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,195 @@
1
+ # Object Detector API - Ruby Gem
2
+
3
+ Object Detector finds the objects in an image, from people, cars and traffic lights to dogs, laptops and cups, and returns each one's label, a numeric confidence and its bounding box in pixels and as fractions of the image, plus a count per label. Filter by minimum confidence or by the labels you care about.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_objectdetector'
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_objectdetector
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_objectdetector'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Objectdetector::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
+ response = client.execute({
39
+ image: "http://images.cocodataset.org/val2017/000000039769.jpg",
40
+ minConfidence: 0.5
41
+ })
42
+
43
+ # Print the response
44
+ puts response
45
+ ```
46
+
47
+ ### File Upload
48
+
49
+ ```ruby
50
+ # Upload a file
51
+ response = client.execute_with_file("/path/to/file.jpg")
52
+
53
+ # Or use a URL
54
+ response = client.execute_with_url("https://example.com/image.jpg")
55
+ ```
56
+
57
+ ### Error Handling
58
+
59
+ ```ruby
60
+ begin
61
+ response = client.execute({ image: "http://images.cocodataset.org/val2017/000000039769.jpg", minConfidence: 0.5 })
62
+ puts response["data"]
63
+ rescue APIVerve::Objectdetector::ValidationError => e
64
+ puts "Validation error: #{e.errors.join(', ')}"
65
+ rescue APIVerve::Objectdetector::APIError => e
66
+ puts "API error: #{e.message}"
67
+ puts "Status code: #{e.status_code}"
68
+ end
69
+ ```
70
+
71
+ ### Debug Mode
72
+
73
+ ```ruby
74
+ # Enable debug logging
75
+ client = APIVerve::Objectdetector::Client.new(
76
+ api_key: "YOUR_API_KEY",
77
+ debug: true
78
+ )
79
+ ```
80
+
81
+ ## Example Response
82
+
83
+ ```json
84
+ {
85
+ "status": "ok",
86
+ "error": null,
87
+ "data": {
88
+ "imageWidth": 640,
89
+ "imageHeight": 480,
90
+ "objectCount": 5,
91
+ "counts": {
92
+ "cat": 2,
93
+ "remote": 2,
94
+ "couch": 1
95
+ },
96
+ "objects": [
97
+ {
98
+ "label": "cat",
99
+ "confidence": 0.999,
100
+ "box": {
101
+ "x": 4,
102
+ "y": 51,
103
+ "width": 320,
104
+ "height": 417
105
+ },
106
+ "normalizedBox": {
107
+ "x": 0.0063,
108
+ "y": 0.1062,
109
+ "width": 0.5,
110
+ "height": 0.8688
111
+ }
112
+ },
113
+ {
114
+ "label": "cat",
115
+ "confidence": 0.9987,
116
+ "box": {
117
+ "x": 331,
118
+ "y": 20,
119
+ "width": 309,
120
+ "height": 350
121
+ },
122
+ "normalizedBox": {
123
+ "x": 0.5172,
124
+ "y": 0.0417,
125
+ "width": 0.4828,
126
+ "height": 0.7292
127
+ }
128
+ },
129
+ {
130
+ "label": "remote",
131
+ "confidence": 0.9984,
132
+ "box": {
133
+ "x": 329,
134
+ "y": 67,
135
+ "width": 42,
136
+ "height": 128
137
+ },
138
+ "normalizedBox": {
139
+ "x": 0.5141,
140
+ "y": 0.1396,
141
+ "width": 0.0656,
142
+ "height": 0.2667
143
+ }
144
+ },
145
+ {
146
+ "label": "remote",
147
+ "confidence": 0.9975,
148
+ "box": {
149
+ "x": 29,
150
+ "y": 68,
151
+ "width": 160,
152
+ "height": 50
153
+ },
154
+ "normalizedBox": {
155
+ "x": 0.0453,
156
+ "y": 0.1417,
157
+ "width": 0.25,
158
+ "height": 0.1042
159
+ }
160
+ },
161
+ {
162
+ "label": "couch",
163
+ "confidence": 0.9961,
164
+ "box": {
165
+ "x": 0,
166
+ "y": 0,
167
+ "width": 636,
168
+ "height": 472
169
+ },
170
+ "normalizedBox": {
171
+ "x": 0,
172
+ "y": 0,
173
+ "width": 0.9938,
174
+ "height": 0.9833
175
+ }
176
+ }
177
+ ],
178
+ "minConfidence": 0.5,
179
+ "labels": null
180
+ }
181
+ }
182
+ ```
183
+
184
+ ## Documentation
185
+
186
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/objectdetector?utm_source=rubygems&utm_medium=referral&utm_content=readme).
187
+
188
+ ## Support
189
+
190
+ - Website: [https://apiverve.com/marketplace/objectdetector?utm_source=ruby&utm_medium=referral&utm_content=readme](https://apiverve.com/marketplace/objectdetector?utm_source=ruby&utm_medium=referral&utm_content=readme)
191
+ - Email: hello@apiverve.com
192
+
193
+ ## License
194
+
195
+ 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 Objectdetector
9
+ # Client for the Object Detector API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Objectdetector::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ image: "http://images.cocodataset.org/val2017/000000039769.jpg", minConfidence: 0.5 })
14
+ # puts response
15
+ #
16
+ # @see https://apiverve.com/marketplace/objectdetector?utm_source=ruby&utm_medium=referral&utm_content=readme
17
+ class Client
18
+ BASE_URL = "https://api.apiverve.com/v1/objectdetector"
19
+ DEFAULT_TIMEOUT = 30
20
+
21
+ # Validation rules for parameters
22
+ VALIDATION_RULES = { 'image' => { type: 'string', required: false }, 'minConfidence' => { type: 'number', required: false, min: 0.05, max: 1 }, 'labels' => { type: 'string', required: false, max_length: 500 } }
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::Objectdetector] #{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_objectdetector/client"
4
+
5
+ module APIVerve
6
+ module Objectdetector
7
+ VERSION = "1.2.6"
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiverve_objectdetector
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.6
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: Object Detector finds the objects in an image, from people, cars and
61
+ traffic lights to dogs, laptops and cups, and returns each one's label, a numeric
62
+ confidence and its bounding box in pixels and as fractions of the image, plus a
63
+ count per label. Filter by minimum confidence or by the labels you care about.
64
+ email:
65
+ - hello@apiverve.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - LICENSE
71
+ - README.md
72
+ - lib/apiverve_objectdetector.rb
73
+ - lib/apiverve_objectdetector/client.rb
74
+ homepage: https://apiverve.com/marketplace/objectdetector?utm_source=ruby&utm_medium=referral&utm_content=homepage
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://apiverve.com/marketplace/objectdetector?utm_source=ruby&utm_medium=referral&utm_content=homepage
79
+ source_code_uri: https://github.com/apiverve/objectdetector-API/tree/main/ruby
80
+ changelog_uri: https://apiverve.com/changelog
81
+ documentation_uri: https://docs.apiverve.com/ref/objectdetector
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: 4.0.23
97
+ specification_version: 4
98
+ summary: Object Detector API - Ruby Client
99
+ test_files: []