labnocturne 1.0.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 +7 -0
- data/README.md +236 -0
- data/lib/labnocturne/client.rb +94 -0
- data/lib/labnocturne/version.rb +5 -0
- data/lib/labnocturne.rb +9 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c22619ebcde6bea55bc871e925c79661506e9f64c122e7f5b0a5edddef062efb
|
|
4
|
+
data.tar.gz: 73c5e715acc5221b8228faf9d440d0c8a64d5b652784acf4ecd3448b3d32e6d6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '08adb6d061294c0e56c2667758129bebda060ac685b744f17d41e02809068e4b8e65a1a9ebe0df8f30edfc569e8ee88f3ab471070e99544500891eca6ac626fd'
|
|
7
|
+
data.tar.gz: eaaa2cc0abfb8684c29407b3ef2530ecfe59edb24666f9e17cca6666e18f3a399853a852f67db71008aaa9436876961baf3edabd18f959d90b93c5c8d3766ad6
|
data/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Lab Nocturne Images - Ruby Client
|
|
2
|
+
|
|
3
|
+
Ruby client library for the [Lab Nocturne Images API](https://images.labnocturne.com).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'labnocturne',
|
|
11
|
+
git: 'https://github.com/jjenkins/labnocturne-image-client',
|
|
12
|
+
glob: 'ruby/*.gemspec'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Ruby 2.7+
|
|
24
|
+
- No external dependencies (uses standard library only)
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'labnocturne'
|
|
30
|
+
|
|
31
|
+
# Generate a test API key
|
|
32
|
+
api_key = LabNocturne::Client.generate_test_key
|
|
33
|
+
puts "API Key: #{api_key}"
|
|
34
|
+
|
|
35
|
+
# Create client
|
|
36
|
+
client = LabNocturne::Client.new(api_key)
|
|
37
|
+
|
|
38
|
+
# Upload an image
|
|
39
|
+
result = client.upload('photo.jpg')
|
|
40
|
+
puts "Image URL: #{result['url']}"
|
|
41
|
+
puts "Image ID: #{result['id']}"
|
|
42
|
+
|
|
43
|
+
# List files
|
|
44
|
+
files = client.list_files(limit: 10)
|
|
45
|
+
puts "Total files: #{files['pagination']['total']}"
|
|
46
|
+
|
|
47
|
+
# Get usage stats
|
|
48
|
+
stats = client.get_stats
|
|
49
|
+
puts "Storage: #{stats['storage_used_mb'].round(2)} MB / #{stats['quota_mb']} MB"
|
|
50
|
+
|
|
51
|
+
# Delete a file
|
|
52
|
+
client.delete_file(result['id'])
|
|
53
|
+
puts "File deleted"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### `LabNocturne::Client.new(api_key, base_url = 'https://images.labnocturne.com')`
|
|
59
|
+
|
|
60
|
+
Create a new client instance.
|
|
61
|
+
|
|
62
|
+
**Parameters:**
|
|
63
|
+
- `api_key` (String): Your API key
|
|
64
|
+
- `base_url` (String, optional): Base URL for the API
|
|
65
|
+
|
|
66
|
+
### Class Methods
|
|
67
|
+
|
|
68
|
+
#### `.generate_test_key(base_url = 'https://images.labnocturne.com')`
|
|
69
|
+
|
|
70
|
+
Generate a test API key for development.
|
|
71
|
+
|
|
72
|
+
**Returns:** API key string
|
|
73
|
+
|
|
74
|
+
**Example:**
|
|
75
|
+
```ruby
|
|
76
|
+
api_key = LabNocturne::Client.generate_test_key
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Instance Methods
|
|
80
|
+
|
|
81
|
+
#### `#upload(file_path)`
|
|
82
|
+
|
|
83
|
+
Upload an image file.
|
|
84
|
+
|
|
85
|
+
**Parameters:**
|
|
86
|
+
- `file_path` (String): Path to the image file
|
|
87
|
+
|
|
88
|
+
**Returns:** Hash with `:id`, `:url`, `:size`, `:mime_type`, `:created_at`
|
|
89
|
+
|
|
90
|
+
**Example:**
|
|
91
|
+
```ruby
|
|
92
|
+
result = client.upload('photo.jpg')
|
|
93
|
+
puts result['url']
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### `#list_files(page: 1, limit: 50, sort: 'created_desc')`
|
|
97
|
+
|
|
98
|
+
List uploaded files with pagination.
|
|
99
|
+
|
|
100
|
+
**Parameters:**
|
|
101
|
+
- `page` (Integer): Page number (default: 1)
|
|
102
|
+
- `limit` (Integer): Files per page (default: 50)
|
|
103
|
+
- `sort` (String): Sort order - `created_desc`, `created_asc`, `size_desc`, `size_asc`, `name_asc`, `name_desc`
|
|
104
|
+
|
|
105
|
+
**Returns:** Hash with `files` array and `pagination` info
|
|
106
|
+
|
|
107
|
+
**Example:**
|
|
108
|
+
```ruby
|
|
109
|
+
files = client.list_files(page: 1, limit: 10, sort: 'size_desc')
|
|
110
|
+
files['files'].each do |file|
|
|
111
|
+
puts "#{file['id']}: #{file['size']} bytes"
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### `#get_stats`
|
|
116
|
+
|
|
117
|
+
Get usage statistics for your account.
|
|
118
|
+
|
|
119
|
+
**Returns:** Hash with `storage_used_bytes`, `storage_used_mb`, `file_count`, `quota_bytes`, `quota_mb`, `usage_percent`
|
|
120
|
+
|
|
121
|
+
**Example:**
|
|
122
|
+
```ruby
|
|
123
|
+
stats = client.get_stats
|
|
124
|
+
puts "Using #{stats['usage_percent'].round(1)}% of quota"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `#delete_file(image_id)`
|
|
128
|
+
|
|
129
|
+
Delete an image (soft delete).
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `image_id` (String): The image ID
|
|
133
|
+
|
|
134
|
+
**Returns:** Hash with success status
|
|
135
|
+
|
|
136
|
+
**Example:**
|
|
137
|
+
```ruby
|
|
138
|
+
client.delete_file('img_01jcd8x9k2n...')
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Error Handling
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
begin
|
|
145
|
+
result = client.upload('photo.jpg')
|
|
146
|
+
puts "Success: #{result['url']}"
|
|
147
|
+
rescue Errno::ENOENT
|
|
148
|
+
puts "Error: File not found"
|
|
149
|
+
rescue StandardError => e
|
|
150
|
+
case e.message
|
|
151
|
+
when /file_too_large/
|
|
152
|
+
puts "Error: File is too large for your account tier"
|
|
153
|
+
when /unauthorized/
|
|
154
|
+
puts "Error: Invalid API key"
|
|
155
|
+
else
|
|
156
|
+
puts "Error: #{e.message}"
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Complete Example
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
require 'labnocturne'
|
|
165
|
+
|
|
166
|
+
# Generate test API key
|
|
167
|
+
puts "Generating test API key..."
|
|
168
|
+
api_key = LabNocturne::Client.generate_test_key
|
|
169
|
+
puts "API Key: #{api_key}\n\n"
|
|
170
|
+
|
|
171
|
+
# Create client
|
|
172
|
+
client = LabNocturne::Client.new(api_key)
|
|
173
|
+
|
|
174
|
+
begin
|
|
175
|
+
# Upload an image
|
|
176
|
+
puts "Uploading image..."
|
|
177
|
+
upload_result = client.upload('photo.jpg')
|
|
178
|
+
puts "Uploaded: #{upload_result['url']}"
|
|
179
|
+
puts "Image ID: #{upload_result['id']}"
|
|
180
|
+
puts "Size: #{(upload_result['size'] / 1024.0).round(2)} KB\n\n"
|
|
181
|
+
|
|
182
|
+
# List all files
|
|
183
|
+
puts "Listing files..."
|
|
184
|
+
files_result = client.list_files(limit: 10)
|
|
185
|
+
puts "Total files: #{files_result['pagination']['total']}"
|
|
186
|
+
files_result['files'].each do |file|
|
|
187
|
+
puts " - #{file['id']}: #{(file['size'] / 1024.0).round(2)} KB"
|
|
188
|
+
end
|
|
189
|
+
puts
|
|
190
|
+
|
|
191
|
+
# Get usage stats
|
|
192
|
+
puts "Usage statistics:"
|
|
193
|
+
stats = client.get_stats
|
|
194
|
+
puts " Storage: #{stats['storage_used_mb'].round(2)} MB / #{stats['quota_mb']} MB"
|
|
195
|
+
puts " Files: #{stats['file_count']}"
|
|
196
|
+
puts " Usage: #{stats['usage_percent'].round(2)}%\n\n"
|
|
197
|
+
|
|
198
|
+
# Delete the uploaded file
|
|
199
|
+
puts "Deleting image..."
|
|
200
|
+
client.delete_file(upload_result['id'])
|
|
201
|
+
puts "Deleted successfully"
|
|
202
|
+
|
|
203
|
+
rescue StandardError => e
|
|
204
|
+
puts "Error: #{e.message}"
|
|
205
|
+
end
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Development
|
|
209
|
+
|
|
210
|
+
Install development dependencies:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
bundle install
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Run tests:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
rspec
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Lint code:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
rubocop
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT License - See [LICENSE](../LICENSE) for details.
|
|
231
|
+
|
|
232
|
+
## Links
|
|
233
|
+
|
|
234
|
+
- [Main Repository](https://github.com/jjenkins/labnocturne-image-client)
|
|
235
|
+
- [API Documentation](https://images.labnocturne.com/docs)
|
|
236
|
+
- [Other Language Clients](https://github.com/jjenkins/labnocturne-image-client#readme)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
module LabNocturne
|
|
8
|
+
# Client for Lab Nocturne Images API
|
|
9
|
+
class Client
|
|
10
|
+
attr_reader :api_key, :base_url
|
|
11
|
+
|
|
12
|
+
def initialize(api_key, base_url = 'https://images.labnocturne.com')
|
|
13
|
+
@api_key = api_key
|
|
14
|
+
@base_url = base_url
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Upload an image file
|
|
18
|
+
def upload(file_path)
|
|
19
|
+
uri = URI.parse("#{@base_url}/upload")
|
|
20
|
+
|
|
21
|
+
request = Net::HTTP::Post.new(uri)
|
|
22
|
+
request['Authorization'] = "Bearer #{@api_key}"
|
|
23
|
+
|
|
24
|
+
form_data = [['file', File.open(file_path)]]
|
|
25
|
+
request.set_form form_data, 'multipart/form-data'
|
|
26
|
+
|
|
27
|
+
response = make_request(uri, request)
|
|
28
|
+
handle_response(response)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# List uploaded files
|
|
32
|
+
def list_files(page: 1, limit: 50, sort: 'created_desc')
|
|
33
|
+
uri = URI.parse("#{@base_url}/files")
|
|
34
|
+
uri.query = URI.encode_www_form(page: page, limit: limit, sort: sort)
|
|
35
|
+
|
|
36
|
+
request = Net::HTTP::Get.new(uri)
|
|
37
|
+
request['Authorization'] = "Bearer #{@api_key}"
|
|
38
|
+
|
|
39
|
+
response = make_request(uri, request)
|
|
40
|
+
handle_response(response)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Get usage statistics
|
|
44
|
+
def get_stats
|
|
45
|
+
uri = URI.parse("#{@base_url}/stats")
|
|
46
|
+
|
|
47
|
+
request = Net::HTTP::Get.new(uri)
|
|
48
|
+
request['Authorization'] = "Bearer #{@api_key}"
|
|
49
|
+
|
|
50
|
+
response = make_request(uri, request)
|
|
51
|
+
handle_response(response)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Delete an image (soft delete)
|
|
55
|
+
def delete_file(image_id)
|
|
56
|
+
uri = URI.parse("#{@base_url}/i/#{image_id}")
|
|
57
|
+
|
|
58
|
+
request = Net::HTTP::Delete.new(uri)
|
|
59
|
+
request['Authorization'] = "Bearer #{@api_key}"
|
|
60
|
+
|
|
61
|
+
response = make_request(uri, request)
|
|
62
|
+
handle_response(response)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Generate a test API key
|
|
66
|
+
def self.generate_test_key(base_url = 'https://images.labnocturne.com')
|
|
67
|
+
uri = URI.parse("#{base_url}/key")
|
|
68
|
+
response = Net::HTTP.get_response(uri)
|
|
69
|
+
|
|
70
|
+
raise "Failed to generate key: #{response.code}" unless response.code == '200'
|
|
71
|
+
|
|
72
|
+
result = JSON.parse(response.body)
|
|
73
|
+
result['api_key']
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def make_request(uri, request)
|
|
79
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
80
|
+
http.request(request)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def handle_response(response)
|
|
85
|
+
unless response.code.start_with?('2')
|
|
86
|
+
error_data = JSON.parse(response.body) rescue {}
|
|
87
|
+
error_msg = error_data.dig('error', 'message') || 'Unknown error'
|
|
88
|
+
raise "API Error: #{error_msg}"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
JSON.parse(response.body)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/labnocturne.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: labnocturne
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Lab Nocturne
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-12-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.12'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rubocop
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.50'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.50'
|
|
41
|
+
description: A simple Ruby client library for uploading and managing images with the
|
|
42
|
+
Lab Nocturne Images API
|
|
43
|
+
email:
|
|
44
|
+
- support@labnocturne.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- README.md
|
|
50
|
+
- lib/labnocturne.rb
|
|
51
|
+
- lib/labnocturne/client.rb
|
|
52
|
+
- lib/labnocturne/version.rb
|
|
53
|
+
homepage: https://github.com/jjenkins/labnocturne-image-client
|
|
54
|
+
licenses:
|
|
55
|
+
- MIT
|
|
56
|
+
metadata:
|
|
57
|
+
homepage_uri: https://github.com/jjenkins/labnocturne-image-client
|
|
58
|
+
source_code_uri: https://github.com/jjenkins/labnocturne-image-client/tree/main/ruby
|
|
59
|
+
bug_tracker_uri: https://github.com/jjenkins/labnocturne-image-client/issues
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.7.0
|
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
requirements: []
|
|
75
|
+
rubygems_version: 3.0.3.1
|
|
76
|
+
signing_key:
|
|
77
|
+
specification_version: 4
|
|
78
|
+
summary: Ruby client for Lab Nocturne Images API
|
|
79
|
+
test_files: []
|