renamed 0.1.0.beta.2 → 0.1.0.beta.4
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 +4 -4
- data/README.md +31 -2
- data/lib/renamed/async_job.rb +7 -0
- data/lib/renamed/client.rb +82 -3
- data/lib/renamed/version.rb +1 -1
- data/lib/renamed.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31508e35ffefb256df91e86574f12f02184fb5bc5d22fed0f0616375aa9d93cc
|
|
4
|
+
data.tar.gz: b138aec5441a1ea62da85eadbe4fc140835142c5c129d72022bbaf20fd351c6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17b2a9745e9af5ad31ed190406dbc74429b5a300cbb9f46a248b5bed44b0a1d1fd51372f200bc6a8a160babc379f35f129892aeb4a64302815d1a079bf22f0f7
|
|
7
|
+
data.tar.gz: e3ae05db5bd86e6d22a83ee90ce5a08e7eb48e8e4018cc8ef235f9211a9c2f4c2789a6591e1b4dbe9301a47e654eefb6ccc2cb7ba095292aaea361b542fffcdc
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Renamed Ruby SDK
|
|
2
2
|
|
|
3
|
-
Official Ruby SDK for the [renamed.to](https://renamed.to) API. Rename files intelligently using AI, split PDFs, and extract structured data from documents.
|
|
3
|
+
Official Ruby SDK for the [renamed.to](https://www.renamed.to) API. Rename files intelligently using AI, split PDFs, and extract structured data from documents.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -36,6 +36,10 @@ puts result.suggested_filename # => "2025-01-15_AcmeCorp_INV-12345.pdf"
|
|
|
36
36
|
puts result.folder_path # => "Invoices/2025/January"
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
See runnable examples in the SDK repo: [examples/ruby](https://github.com/renamed-to/renamed-sdk/tree/main/examples/ruby) (`basic_usage.rb`).
|
|
42
|
+
|
|
39
43
|
## Features
|
|
40
44
|
|
|
41
45
|
### Rename Files
|
|
@@ -135,10 +139,35 @@ client = Renamed::Client.new(
|
|
|
135
139
|
api_key: 'rt_your_api_key',
|
|
136
140
|
base_url: 'https://www.renamed.to/api/v1', # Default
|
|
137
141
|
timeout: 30, # Request timeout in seconds
|
|
138
|
-
max_retries: 2
|
|
142
|
+
max_retries: 2, # Number of retries for failed requests
|
|
143
|
+
debug: true, # Enable debug logging
|
|
144
|
+
logger: Logger.new($stderr) # Custom logger (optional)
|
|
139
145
|
)
|
|
140
146
|
```
|
|
141
147
|
|
|
148
|
+
## Debug Logging
|
|
149
|
+
|
|
150
|
+
Enable debug logging to see HTTP request details for troubleshooting:
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
client = Renamed::Client.new(api_key: 'rt_...', debug: true)
|
|
154
|
+
|
|
155
|
+
# Output:
|
|
156
|
+
# [Renamed] POST /rename -> 200 (234ms)
|
|
157
|
+
# [Renamed] Upload: document.pdf (1.2 MB)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Use Ruby's standard `Logger` for custom logging:
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
require 'logger'
|
|
164
|
+
|
|
165
|
+
logger = Logger.new('renamed.log')
|
|
166
|
+
logger.level = Logger::DEBUG
|
|
167
|
+
|
|
168
|
+
client = Renamed::Client.new(api_key: 'rt_...', logger: logger)
|
|
169
|
+
```
|
|
170
|
+
|
|
142
171
|
## Error Handling
|
|
143
172
|
|
|
144
173
|
The SDK provides specific error classes for different error conditions:
|
data/lib/renamed/async_job.rb
CHANGED
|
@@ -48,6 +48,7 @@ module Renamed
|
|
|
48
48
|
while attempts < @max_attempts
|
|
49
49
|
current_status = status
|
|
50
50
|
|
|
51
|
+
log_job_status(current_status)
|
|
51
52
|
yield current_status if block_given?
|
|
52
53
|
|
|
53
54
|
if current_status.status == "completed" && current_status.result
|
|
@@ -64,5 +65,11 @@ module Renamed
|
|
|
64
65
|
|
|
65
66
|
raise JobError.new("Job polling timeout exceeded")
|
|
66
67
|
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def log_job_status(job_status)
|
|
72
|
+
@client.send(:log_job_status, job_status.job_id, job_status.status, job_status.progress)
|
|
73
|
+
end
|
|
67
74
|
end
|
|
68
75
|
end
|
data/lib/renamed/client.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require "faraday"
|
|
4
4
|
require "faraday/multipart"
|
|
5
5
|
require "json"
|
|
6
|
+
require "logger"
|
|
7
|
+
require "uri"
|
|
6
8
|
|
|
7
9
|
require_relative "errors"
|
|
8
10
|
require_relative "models"
|
|
@@ -31,13 +33,16 @@ module Renamed
|
|
|
31
33
|
# @param base_url [String] Base URL for the API
|
|
32
34
|
# @param timeout [Integer] Request timeout in seconds
|
|
33
35
|
# @param max_retries [Integer] Maximum number of retries for failed requests
|
|
34
|
-
|
|
36
|
+
# @param debug [Boolean] Enable debug logging to stderr
|
|
37
|
+
# @param logger [Logger, nil] Custom logger instance (overrides debug flag)
|
|
38
|
+
def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, debug: false, logger: nil)
|
|
35
39
|
raise AuthenticationError, "API key is required" if api_key.nil? || api_key.empty?
|
|
36
40
|
|
|
37
41
|
@api_key = api_key
|
|
38
42
|
@base_url = base_url.chomp("/")
|
|
39
43
|
@timeout = timeout
|
|
40
44
|
@max_retries = max_retries
|
|
45
|
+
@logger = setup_logger(debug, logger)
|
|
41
46
|
|
|
42
47
|
@connection = build_connection
|
|
43
48
|
end
|
|
@@ -181,7 +186,9 @@ module Renamed
|
|
|
181
186
|
|
|
182
187
|
while attempts <= @max_retries
|
|
183
188
|
begin
|
|
189
|
+
start_time = monotonic_time
|
|
184
190
|
response = @connection.send(method, url, options[:body], options[:headers])
|
|
191
|
+
log_request(method, path, response.status, start_time)
|
|
185
192
|
return handle_response(response)
|
|
186
193
|
rescue Faraday::ConnectionFailed => e
|
|
187
194
|
last_error = NetworkError.new(e.message)
|
|
@@ -195,7 +202,11 @@ module Renamed
|
|
|
195
202
|
end
|
|
196
203
|
|
|
197
204
|
attempts += 1
|
|
198
|
-
|
|
205
|
+
if attempts <= @max_retries
|
|
206
|
+
backoff_ms = (2**attempts * 100).to_i
|
|
207
|
+
log_retry(attempts, @max_retries, backoff_ms)
|
|
208
|
+
sleep(backoff_ms / 1000.0)
|
|
209
|
+
end
|
|
199
210
|
end
|
|
200
211
|
|
|
201
212
|
raise last_error || NetworkError.new
|
|
@@ -229,6 +240,8 @@ module Renamed
|
|
|
229
240
|
def upload_file(path, file, additional_fields: {})
|
|
230
241
|
filename, content, mime_type = prepare_file(file)
|
|
231
242
|
|
|
243
|
+
log_upload(filename, content.bytesize)
|
|
244
|
+
|
|
232
245
|
payload = {}
|
|
233
246
|
payload[:file] = Faraday::Multipart::FilePart.new(
|
|
234
247
|
StringIO.new(content),
|
|
@@ -246,7 +259,9 @@ module Renamed
|
|
|
246
259
|
|
|
247
260
|
while attempts <= @max_retries
|
|
248
261
|
begin
|
|
262
|
+
start_time = monotonic_time
|
|
249
263
|
response = @connection.post(url, payload)
|
|
264
|
+
log_request(:post, path, response.status, start_time)
|
|
250
265
|
return handle_response(response)
|
|
251
266
|
rescue Faraday::ConnectionFailed => e
|
|
252
267
|
last_error = NetworkError.new(e.message)
|
|
@@ -259,7 +274,11 @@ module Renamed
|
|
|
259
274
|
end
|
|
260
275
|
|
|
261
276
|
attempts += 1
|
|
262
|
-
|
|
277
|
+
if attempts <= @max_retries
|
|
278
|
+
backoff_ms = (2**attempts * 100).to_i
|
|
279
|
+
log_retry(attempts, @max_retries, backoff_ms)
|
|
280
|
+
sleep(backoff_ms / 1000.0)
|
|
281
|
+
end
|
|
263
282
|
end
|
|
264
283
|
|
|
265
284
|
raise last_error || NetworkError.new
|
|
@@ -286,5 +305,65 @@ module Renamed
|
|
|
286
305
|
ext = File.extname(filename).downcase
|
|
287
306
|
MIME_TYPES[ext] || "application/octet-stream"
|
|
288
307
|
end
|
|
308
|
+
|
|
309
|
+
# Logging helpers
|
|
310
|
+
|
|
311
|
+
def setup_logger(debug, logger)
|
|
312
|
+
return logger if logger
|
|
313
|
+
|
|
314
|
+
return nil unless debug
|
|
315
|
+
|
|
316
|
+
new_logger = Logger.new($stderr)
|
|
317
|
+
new_logger.level = Logger::DEBUG
|
|
318
|
+
new_logger.formatter = proc { |_severity, _datetime, _progname, msg| "#{msg}\n" }
|
|
319
|
+
new_logger
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def log_debug(message)
|
|
323
|
+
@logger&.debug(message)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def log_request(method, path, status, start_time)
|
|
327
|
+
return unless @logger
|
|
328
|
+
|
|
329
|
+
elapsed_ms = ((monotonic_time - start_time) * 1000).round
|
|
330
|
+
# Normalize path to just the path portion (not full URL)
|
|
331
|
+
display_path = path.start_with?("http") ? URI.parse(path).path : path
|
|
332
|
+
log_debug("[Renamed] #{method.to_s.upcase} #{display_path} -> #{status} (#{elapsed_ms}ms)")
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def log_retry(attempt, max_retries, backoff_ms)
|
|
336
|
+
log_debug("[Renamed] Retry attempt #{attempt}/#{max_retries}, waiting #{backoff_ms}ms")
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def log_upload(filename, size_bytes)
|
|
340
|
+
log_debug("[Renamed] Upload: #{filename} (#{format_size(size_bytes)})")
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def log_job_status(job_id, status, progress = nil)
|
|
344
|
+
message = "[Renamed] Job #{job_id}: #{status}"
|
|
345
|
+
message += " (#{progress}%)" if progress
|
|
346
|
+
log_debug(message)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def format_size(bytes)
|
|
350
|
+
if bytes >= 1_000_000
|
|
351
|
+
format("%.1f MB", bytes / 1_000_000.0)
|
|
352
|
+
elsif bytes >= 1_000
|
|
353
|
+
format("%.1f KB", bytes / 1_000.0)
|
|
354
|
+
else
|
|
355
|
+
"#{bytes} B"
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def mask_api_key(key)
|
|
360
|
+
return "***" if key.nil? || key.length < 7
|
|
361
|
+
|
|
362
|
+
"#{key[0, 3]}...#{key[-4, 4]}"
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def monotonic_time
|
|
366
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
367
|
+
end
|
|
289
368
|
end
|
|
290
369
|
end
|
data/lib/renamed/version.rb
CHANGED
data/lib/renamed.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: renamed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.0.beta.
|
|
4
|
+
version: 0.1.0.beta.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- renamed.to
|
|
@@ -143,14 +143,14 @@ files:
|
|
|
143
143
|
- lib/renamed/errors.rb
|
|
144
144
|
- lib/renamed/models.rb
|
|
145
145
|
- lib/renamed/version.rb
|
|
146
|
-
homepage: https://renamed.to
|
|
146
|
+
homepage: https://www.renamed.to
|
|
147
147
|
licenses:
|
|
148
148
|
- MIT
|
|
149
149
|
metadata:
|
|
150
|
-
homepage_uri: https://renamed.to
|
|
150
|
+
homepage_uri: https://www.renamed.to
|
|
151
151
|
source_code_uri: https://github.com/renamed-to/renamed-sdk
|
|
152
152
|
changelog_uri: https://github.com/renamed-to/renamed-sdk/blob/main/sdks/ruby/CHANGELOG.md
|
|
153
|
-
documentation_uri: https://renamed.to/docs
|
|
153
|
+
documentation_uri: https://www.renamed.to/docs
|
|
154
154
|
rubygems_mfa_required: 'true'
|
|
155
155
|
post_install_message:
|
|
156
156
|
rdoc_options: []
|