nzbn-ruby 0.1.3 → 0.1.5
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 +17 -0
- data/README.md +34 -2
- data/lib/nzbn/client.rb +19 -4
- data/lib/nzbn/configuration.rb +45 -5
- data/lib/nzbn/version.rb +1 -1
- data/lib/nzbn.rb +3 -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: e7b5ed421a242eb20a20ab1915ca8b494e841dab14d1a570ba0b2091c96041b5
|
|
4
|
+
data.tar.gz: 02f681798322954cfe3f1d83f2e78dc745af871b7ec4c00aaa25fa97b12ef5ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b55a33c0e887d0c5a70162ebb32c9ed18f530f9c144c32a03217fb297d97c3c260b0040d701811129bd84c2490f3c6875f16757347cc4795aa459ad8f600be1e
|
|
7
|
+
data.tar.gz: 89d7aad88299b453d38873e25dacf66bcdd6bac8d1e55a40ae2e7455e29edc50ce1d8246bee8d28190a1ff2a49b29d62f7375ea4ff544f551a09a2ff7165571b
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ 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.5] - 2026-03-13
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Support for production and sandbox modes via `config.mode = :production` or `config.mode = :sandbox`
|
|
12
|
+
- Default production URL: `https://api.business.govt.nz/gateway/nzbn/v5`
|
|
13
|
+
- Default sandbox URL: `https://api.business.govt.nz/sandbox/nzbn/v5`
|
|
14
|
+
- `PRODUCTION_BASE_URL` and `SANDBOX_BASE_URL` constants
|
|
15
|
+
- `sandbox?` and `production?` convenience methods on Configuration
|
|
16
|
+
- Validation for invalid mode values with `ArgumentError`
|
|
17
|
+
|
|
18
|
+
## [0.1.4] - 2026-02-09
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- Added request/response logging with configurable logger
|
|
22
|
+
- Logs request ID, HTTP method, URL before each API call
|
|
23
|
+
- Logs response status after each API call
|
|
24
|
+
|
|
8
25
|
## [0.1.3] - 2026-02-09
|
|
9
26
|
|
|
10
27
|
### Fixed
|
data/README.md
CHANGED
|
@@ -33,10 +33,42 @@ 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
|
+
# Production mode (default)
|
|
36
37
|
Nzbn.configure do |config|
|
|
37
38
|
config.api_key = 'your-api-key'
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Sandbox mode
|
|
42
|
+
Nzbn.configure do |config|
|
|
43
|
+
config.api_key = 'your-api-key'
|
|
44
|
+
config.mode = :sandbox
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Configuration Options
|
|
49
|
+
|
|
50
|
+
| Option | Default | Description |
|
|
51
|
+
|--------|---------|-------------|
|
|
52
|
+
| `api_key` | `nil` | **(Required)** Your NZBN API subscription key |
|
|
53
|
+
| `mode` | `:production` | API mode — `:production` or `:sandbox` |
|
|
54
|
+
| `base_url` | Production URL | Auto-set by mode; can be overridden manually |
|
|
55
|
+
| `timeout` | `30` | Request timeout in seconds |
|
|
56
|
+
| `open_timeout` | `10` | Connection open timeout in seconds |
|
|
57
|
+
| `logger` | `nil` | Logger instance for request/response logging |
|
|
58
|
+
|
|
59
|
+
### Default URLs
|
|
60
|
+
|
|
61
|
+
| Mode | URL |
|
|
62
|
+
|------|-----|
|
|
63
|
+
| `:production` | `https://api.business.govt.nz/gateway/nzbn/v5` |
|
|
64
|
+
| `:sandbox` | `https://api.business.govt.nz/sandbox/nzbn/v5` |
|
|
65
|
+
|
|
66
|
+
You can also set a custom `base_url` directly, which overrides the mode:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
Nzbn.configure do |config|
|
|
70
|
+
config.api_key = 'your-api-key'
|
|
71
|
+
config.base_url = 'https://custom-url.example.com/nzbn/v5'
|
|
40
72
|
end
|
|
41
73
|
```
|
|
42
74
|
|
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/configuration.rb
CHANGED
|
@@ -3,24 +3,64 @@
|
|
|
3
3
|
module Nzbn
|
|
4
4
|
# Configuration class for NZBN client settings
|
|
5
5
|
#
|
|
6
|
-
# @example
|
|
6
|
+
# @example Production mode (default)
|
|
7
7
|
# Nzbn.configure do |config|
|
|
8
8
|
# config.api_key = 'your-api-key'
|
|
9
|
-
#
|
|
10
|
-
#
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# @example Sandbox mode
|
|
12
|
+
# Nzbn.configure do |config|
|
|
13
|
+
# config.api_key = 'your-api-key'
|
|
14
|
+
# config.mode = :sandbox
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# @example Custom base URL (overrides mode)
|
|
18
|
+
# Nzbn.configure do |config|
|
|
19
|
+
# config.api_key = 'your-api-key'
|
|
20
|
+
# config.base_url = 'https://custom-url.example.com/nzbn/v5'
|
|
11
21
|
# end
|
|
12
22
|
#
|
|
13
23
|
class Configuration
|
|
14
|
-
|
|
24
|
+
MODES = %i[production sandbox].freeze
|
|
25
|
+
|
|
26
|
+
attr_accessor :api_key, :timeout, :open_timeout, :logger
|
|
27
|
+
attr_reader :mode, :base_url
|
|
15
28
|
|
|
16
29
|
def initialize
|
|
17
30
|
@api_key = nil
|
|
18
|
-
@
|
|
31
|
+
@mode = :production
|
|
32
|
+
@base_url = Nzbn::PRODUCTION_BASE_URL
|
|
19
33
|
@timeout = 30
|
|
20
34
|
@open_timeout = 10
|
|
21
35
|
@logger = nil
|
|
22
36
|
end
|
|
23
37
|
|
|
38
|
+
# Set the mode (:production or :sandbox).
|
|
39
|
+
# This automatically updates base_url to the corresponding default URL.
|
|
40
|
+
def mode=(value)
|
|
41
|
+
value = value.to_sym
|
|
42
|
+
|
|
43
|
+
unless MODES.include?(value)
|
|
44
|
+
raise ArgumentError, "Invalid mode: #{value}. Must be one of: #{MODES.join(', ')}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@mode = value
|
|
48
|
+
@base_url = value == :sandbox ? Nzbn::SANDBOX_BASE_URL : Nzbn::PRODUCTION_BASE_URL
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Set a custom base URL. This overrides the mode-derived URL.
|
|
52
|
+
def base_url=(value)
|
|
53
|
+
@base_url = value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def sandbox?
|
|
57
|
+
@mode == :sandbox
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def production?
|
|
61
|
+
@mode == :production
|
|
62
|
+
end
|
|
63
|
+
|
|
24
64
|
def valid?
|
|
25
65
|
!api_key.nil? && !api_key.empty?
|
|
26
66
|
end
|
data/lib/nzbn/version.rb
CHANGED
data/lib/nzbn.rb
CHANGED
|
@@ -50,7 +50,9 @@ require_relative 'nzbn/api/history'
|
|
|
50
50
|
# entities = client.entities.search(search_term: 'Company Name')
|
|
51
51
|
#
|
|
52
52
|
module Nzbn
|
|
53
|
-
|
|
53
|
+
PRODUCTION_BASE_URL = 'https://api.business.govt.nz/gateway/nzbn/v5'
|
|
54
|
+
SANDBOX_BASE_URL = 'https://api.business.govt.nz/sandbox/nzbn/v5'
|
|
55
|
+
DEFAULT_BASE_URL = PRODUCTION_BASE_URL # backward compatibility
|
|
54
56
|
|
|
55
57
|
class << self
|
|
56
58
|
attr_accessor :configuration
|