nzbn-ruby 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bc9736578fcb4a9663e87a28d910e91dbfdc9acf724f30c09bfc03fb47b5e3f
4
- data.tar.gz: 1fffb71fac5bf19a6192220b89674212066f2be603fd37c2a6d8d4f7f8f6cf3f
3
+ metadata.gz: 6d534a41f82db0a2b137a0cd850749fdfc1c85ecc090cd226d2268997ec75a8d
4
+ data.tar.gz: a290d6cd3347116b5b4d20180ff16834dbe250b0a48ee8058b3261be1fa6cc32
5
5
  SHA512:
6
- metadata.gz: c5de87bf46f1d4bb736a5bb42815e25524c359e7c3e98b9f5b83fdf854862a4de960c80a1a43a25c18214e485660820cbbcd30003b40ba9cee7a5e7b52ff0403
7
- data.tar.gz: 7efe36fe483fe7a4ca917b313e65466aabef6539b8e8dc1ec83666df6ca0c64c96923d53f54782e5e69656fedf697ad74a5d63e80365be2268547aafde5d9f28
6
+ metadata.gz: 9b28cc5915381c31ce1cdf5fecee02212f3d0a8d923d58fe42c28d9eeb371c31b113dbb632cc20a0bf8b566a9cbc7ec6e72249051b5b69bc449e1e7f67817e36
7
+ data.tar.gz: 3b8b72ef58086b594c65a90faecd474e1ba872be9592d1ca975ef6fa213e1d639ee7a5d3f43c7a4f17566aef306cf3323d1134d47b0dd113611d653da544ae2e
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ 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.6] - 2026-03-13
9
+
10
+ ### Fixed
11
+ - Fixed URL path construction in `Client#request` to correctly parse base path from `base_url` and prepend it to request paths, preventing duplicate or missing path segments with Faraday
12
+
13
+ ## [0.1.5] - 2026-03-13
14
+
15
+ ### Added
16
+ - Support for production and sandbox modes via `config.mode = :production` or `config.mode = :sandbox`
17
+ - Default production URL: `https://api.business.govt.nz/gateway/nzbn/v5`
18
+ - Default sandbox URL: `https://api.business.govt.nz/sandbox/nzbn/v5`
19
+ - `PRODUCTION_BASE_URL` and `SANDBOX_BASE_URL` constants
20
+ - `sandbox?` and `production?` convenience methods on Configuration
21
+ - Validation for invalid mode values with `ArgumentError`
22
+
8
23
  ## [0.1.4] - 2026-02-09
9
24
 
10
25
  ### Added
data/README.md CHANGED
@@ -33,13 +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
- require 'logger'
36
+ # Production mode (default)
37
+ Nzbn.configure do |config|
38
+ config.api_key = 'your-api-key'
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
37
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
38
69
  Nzbn.configure do |config|
39
70
  config.api_key = 'your-api-key'
40
- config.base_url = 'https://api.business.govt.nz/gateway/nzbn/v5' # default
41
- config.timeout = 30 # optional, default 30 seconds
42
- config.logger = Logger.new(STDOUT) # optional, enables request/response logging
71
+ config.base_url = 'https://custom-url.example.com/nzbn/v5'
43
72
  end
44
73
  ```
45
74
 
data/lib/nzbn/client.rb CHANGED
@@ -119,13 +119,12 @@ module Nzbn
119
119
  def request(method, path, data, headers)
120
120
  request_id = SecureRandom.uuid
121
121
  full_url = "#{configuration.base_url}#{path}"
122
-
123
122
  log_request(method, full_url, request_id, data)
124
-
125
123
  merged_headers = default_headers(request_id).merge(headers)
124
+ base_path = URI.parse(configuration.base_url).path
126
125
 
127
126
  response = connection.public_send(method) do |req|
128
- req.url path
127
+ req.url "#{base_path}#{path}"
129
128
  req.headers = merged_headers
130
129
 
131
130
  case method
@@ -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
- # config.base_url = 'https://api.business.govt.nz/gateway/nzbn/v5'
10
- # config.timeout = 30
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
- attr_accessor :api_key, :base_url, :timeout, :open_timeout, :logger
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
- @base_url = Nzbn::DEFAULT_BASE_URL
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nzbn
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.6'
5
5
  end
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
- DEFAULT_BASE_URL = 'https://api.business.govt.nz/gateway/nzbn/v5'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nzbn-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhan Nguyen
@@ -141,7 +141,6 @@ files:
141
141
  - lib/nzbn/models/watchlist.rb
142
142
  - lib/nzbn/models/website.rb
143
143
  - lib/nzbn/version.rb
144
- - nzbn-ruby.gemspec
145
144
  homepage: https://github.com/nnhansg/nzbn-ruby
146
145
  licenses:
147
146
  - MIT
data/nzbn-ruby.gemspec DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/nzbn/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'nzbn-ruby'
7
- spec.version = Nzbn::VERSION
8
- spec.authors = ['Nhan Nguyen']
9
- spec.email = ['nnhansg@gmail.com']
10
-
11
- spec.summary = 'Ruby client for the New Zealand Business Number (NZBN) API'
12
- spec.description = 'A Ruby gem for interacting with the NZBN API v5. Search entities, manage watchlists, and access NZ business data.'
13
- spec.homepage = 'https://github.com/nnhansg/nzbn-ruby'
14
- spec.license = 'MIT'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = spec.homepage
18
- spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
-
20
- spec.files = Dir.chdir(__dir__) do
21
- `git ls-files -z`.split("\x0").reject do |f|
22
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
- end
24
- end
25
-
26
- spec.files += Dir['lib/**/*.rb']
27
- spec.require_paths = ['lib']
28
-
29
- spec.add_dependency 'faraday', '~> 1.0'
30
- spec.add_dependency 'json', '~> 2.1'
31
-
32
- spec.add_development_dependency 'bundler', '>= 1.0'
33
- spec.add_development_dependency 'rake', '~> 13.0'
34
- spec.add_development_dependency 'rspec', '~> 3.0'
35
- spec.add_development_dependency 'webmock', '~> 3.0'
36
- end