nzbn-ruby 0.1.3 → 0.1.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/CHANGELOG.md +7 -0
- data/README.md +3 -0
- data/lib/nzbn/client.rb +19 -4
- data/lib/nzbn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bc9736578fcb4a9663e87a28d910e91dbfdc9acf724f30c09bfc03fb47b5e3f
|
|
4
|
+
data.tar.gz: 1fffb71fac5bf19a6192220b89674212066f2be603fd37c2a6d8d4f7f8f6cf3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5de87bf46f1d4bb736a5bb42815e25524c359e7c3e98b9f5b83fdf854862a4de960c80a1a43a25c18214e485660820cbbcd30003b40ba9cee7a5e7b52ff0403
|
|
7
|
+
data.tar.gz: 7efe36fe483fe7a4ca917b313e65466aabef6539b8e8dc1ec83666df6ca0c64c96923d53f54782e5e69656fedf697ad74a5d63e80365be2268547aafde5d9f28
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.4] - 2026-02-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Added request/response logging with configurable logger
|
|
12
|
+
- Logs request ID, HTTP method, URL before each API call
|
|
13
|
+
- Logs response status after each API call
|
|
14
|
+
|
|
8
15
|
## [0.1.3] - 2026-02-09
|
|
9
16
|
|
|
10
17
|
### Fixed
|
data/README.md
CHANGED
|
@@ -33,10 +33,13 @@ gem install nzbn-ruby
|
|
|
33
33
|
Configure the gem with your NZBN API key (obtain from [api.business.govt.nz](https://api.business.govt.nz)):
|
|
34
34
|
|
|
35
35
|
```ruby
|
|
36
|
+
require 'logger'
|
|
37
|
+
|
|
36
38
|
Nzbn.configure do |config|
|
|
37
39
|
config.api_key = 'your-api-key'
|
|
38
40
|
config.base_url = 'https://api.business.govt.nz/gateway/nzbn/v5' # default
|
|
39
41
|
config.timeout = 30 # optional, default 30 seconds
|
|
42
|
+
config.logger = Logger.new(STDOUT) # optional, enables request/response logging
|
|
40
43
|
end
|
|
41
44
|
```
|
|
42
45
|
|
data/lib/nzbn/client.rb
CHANGED
|
@@ -113,15 +113,14 @@ module Nzbn
|
|
|
113
113
|
|
|
114
114
|
conn.options.timeout = configuration.timeout
|
|
115
115
|
conn.options.open_timeout = configuration.open_timeout
|
|
116
|
-
|
|
117
|
-
if configuration.logger
|
|
118
|
-
conn.response :logger, configuration.logger
|
|
119
|
-
end
|
|
120
116
|
end
|
|
121
117
|
end
|
|
122
118
|
|
|
123
119
|
def request(method, path, data, headers)
|
|
124
120
|
request_id = SecureRandom.uuid
|
|
121
|
+
full_url = "#{configuration.base_url}#{path}"
|
|
122
|
+
|
|
123
|
+
log_request(method, full_url, request_id, data)
|
|
125
124
|
|
|
126
125
|
merged_headers = default_headers(request_id).merge(headers)
|
|
127
126
|
|
|
@@ -137,6 +136,7 @@ module Nzbn
|
|
|
137
136
|
end
|
|
138
137
|
end
|
|
139
138
|
|
|
139
|
+
log_response(response, request_id)
|
|
140
140
|
handle_response(response)
|
|
141
141
|
rescue Faraday::TimeoutError => e
|
|
142
142
|
raise TimeoutError, "Request timed out: #{e.message}"
|
|
@@ -144,6 +144,21 @@ module Nzbn
|
|
|
144
144
|
raise ConnectionError, "Connection failed: #{e.message}"
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
+
def log_request(method, url, request_id, data)
|
|
148
|
+
return unless configuration.logger
|
|
149
|
+
|
|
150
|
+
configuration.logger.info("[NZBN] Request ID: #{request_id}")
|
|
151
|
+
configuration.logger.info("[NZBN] #{method.to_s.upcase} #{url}")
|
|
152
|
+
configuration.logger.debug("[NZBN] Request data: #{data.inspect}") unless data.empty?
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def log_response(response, request_id)
|
|
156
|
+
return unless configuration.logger
|
|
157
|
+
|
|
158
|
+
configuration.logger.info("[NZBN] Response ID: #{request_id} - Status: #{response.status}")
|
|
159
|
+
configuration.logger.debug("[NZBN] Response body: #{response.body[0..500]}...")
|
|
160
|
+
end
|
|
161
|
+
|
|
147
162
|
def default_headers(request_id)
|
|
148
163
|
{
|
|
149
164
|
'Ocp-Apim-Subscription-Key' => configuration.api_key,
|
data/lib/nzbn/version.rb
CHANGED