client-api-builder 0.6.0 → 0.6.1
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/.rubocop.yml +1 -1
- data/README.md +22 -0
- data/client-api-builder.gemspec +1 -1
- data/lib/client_api_builder/router.rb +29 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a417fa853b68dc6e9e96eff4cf99d6a0e026d459e38ae57cbec7341e4735e291
|
|
4
|
+
data.tar.gz: b2cb35125eb9cdea344051788aee903daea7762c1f0bbbfc13526e1a8815692b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7fbc5052d79571ea1b901067bbaa3feb9a5e0e3c29ccebe1279905b917c121ecda94284f583c52badc5f00ef2c8c55fcba062563e1e8446730ea496659ac5ba3
|
|
7
|
+
data.tar.gz: f2521e526d45195ff795ad3663c7f6bf8140bb8316a8c3b04f170fe215c0b185745536b152ea0879a896d60ea82cc33a7e7e2e0a9086892c1ee1c5c6a82125eb
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
|
@@ -433,6 +433,28 @@ subscriber = ClientApiBuilder::ActiveSupportLogSubscriber.new(Rails.logger)
|
|
|
433
433
|
subscriber.subscribe!
|
|
434
434
|
```
|
|
435
435
|
|
|
436
|
+
#### Production Logging
|
|
437
|
+
|
|
438
|
+
For production environments, it's important to log requests without exposing sensitive credentials that may be present in query parameters. The following example strips query parameters from logged URLs:
|
|
439
|
+
|
|
440
|
+
```ruby
|
|
441
|
+
ActiveSupport::Notifications.subscribe('client_api_builder.request') do |_, start_time, end_time, _, payload|
|
|
442
|
+
client = payload[:client]
|
|
443
|
+
method = client.request_options[:method].to_s.upcase
|
|
444
|
+
uri = client.request_options[:uri]
|
|
445
|
+
response_code = client.response ? client.response.code : 'UNKNOWN'
|
|
446
|
+
|
|
447
|
+
duration = ((end_time - start_time) * 1000).to_i
|
|
448
|
+
Rails.logger.info "#{method} #{uri.scheme}://#{uri.host}#{uri.path}[#{response_code}] took #{duration}ms"
|
|
449
|
+
end
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
This produces clean log entries like:
|
|
453
|
+
```
|
|
454
|
+
GET https://api.example.com/users/123[200] took 45ms
|
|
455
|
+
POST https://api.example.com/auth/token[201] took 120ms
|
|
456
|
+
```
|
|
457
|
+
|
|
436
458
|
## Security Features
|
|
437
459
|
|
|
438
460
|
Client API Builder includes several security features enabled by default:
|
data/client-api-builder.gemspec
CHANGED
|
@@ -282,10 +282,37 @@ module ClientApiBuilder
|
|
|
282
282
|
[path, path_arguments]
|
|
283
283
|
end
|
|
284
284
|
|
|
285
|
+
# Converts a value to Ruby code string with consistent hash syntax across Ruby versions.
|
|
286
|
+
# Uses modern {key: value} syntax for symbol keys.
|
|
287
|
+
def value_to_code(value)
|
|
288
|
+
case value
|
|
289
|
+
when Hash
|
|
290
|
+
return '{}' if value.empty?
|
|
291
|
+
|
|
292
|
+
pairs = value.map do |k, v|
|
|
293
|
+
key_code = case k
|
|
294
|
+
when Symbol then "#{k}: "
|
|
295
|
+
when String then "#{k.inspect} => "
|
|
296
|
+
else "#{value_to_code(k)} => "
|
|
297
|
+
end
|
|
298
|
+
"#{key_code}#{value_to_code(v)}"
|
|
299
|
+
end
|
|
300
|
+
"{#{pairs.join(', ')}}"
|
|
301
|
+
when Array
|
|
302
|
+
"[#{value.map { |v| value_to_code(v) }.join(', ')}]"
|
|
303
|
+
when NilClass
|
|
304
|
+
'nil'
|
|
305
|
+
when TrueClass, FalseClass
|
|
306
|
+
value.to_s
|
|
307
|
+
else
|
|
308
|
+
value.inspect
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
285
312
|
def build_query_code(options)
|
|
286
313
|
if options[:query]
|
|
287
314
|
query_arguments = get_arguments(options[:query])
|
|
288
|
-
str = options[:query]
|
|
315
|
+
str = value_to_code(options[:query])
|
|
289
316
|
str = str.gsub(/"__\|\|(.+?)\|\|__"/) { Regexp.last_match(1) }
|
|
290
317
|
[str, query_arguments.map(&:to_s)]
|
|
291
318
|
else
|
|
@@ -296,7 +323,7 @@ module ClientApiBuilder
|
|
|
296
323
|
def build_body_code(options, has_body_param)
|
|
297
324
|
if options[:body]
|
|
298
325
|
body_arguments = get_arguments(options[:body])
|
|
299
|
-
str = options[:body]
|
|
326
|
+
str = value_to_code(options[:body])
|
|
300
327
|
str = str.gsub(/"__\|\|(.+?)\|\|__"/) { Regexp.last_match(1) }
|
|
301
328
|
[str, body_arguments.map(&:to_s), false]
|
|
302
329
|
else
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: client-api-builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Doug Youch
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01
|
|
10
|
+
date: 2026-02-01 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: inheritance-helper
|