rerout 0.5.0 → 0.6.0

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: 4d7253a49e955b1812e46e3d0c435999fda4c7276d5f19bad47586ac56d06247
4
- data.tar.gz: aeb26215de9a5c1e3f5de9637d348342f7cac7461179a8db7b005a438d1260ef
3
+ metadata.gz: 016c1f73ad3a38b6256f068ecf5d2ca3ab7d5f40e342c52f4e434835e337241f
4
+ data.tar.gz: 8ef0ff707b6f64bb9feb72f0c59df1f9a95b8a757898dba201d8ae90081d9f80
5
5
  SHA512:
6
- metadata.gz: 1a4435295c93cc7e74812509c38d5cd7c829e004a37ec71796b3cb08b3707d7959ea4ba8d28aef0925d58bb48b00b39f8df807f4503af1fd33d880de3c4ffc04
7
- data.tar.gz: ae6b3a652f246e38ca8537d4eda5699733de2fd3dcc1ed2e102eaca3e6e61041c1d8344082da8c764cdc35aeaa7c202c2818d6f0ed223bc10df376fdd5f658e6
6
+ metadata.gz: 83f97655cb2138c867d4937715bf4ec4e3c2f8cfcc56513e1062f6c87979454588bae276b90880d02e7573cecb1f4fae3f31a9c89be5d6918f8367143fd255af
7
+ data.tar.gz: a0be08c8c9fb89ea350c26bf1312bc93989e860b4eceb1b63a630d0cf4f0c7c80f6cf307aaf926e2271123b98c3ba6697d92b0ce25352f2df488033458cc5012
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to the `rerout` gem are documented in this file. The
4
4
  format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.6.0] - 2026-07-13
8
+
9
+ ### Added
10
+
11
+ - Explicit isolated sandbox selection, automatic routing to
12
+ \`https://sandbox-api.rerout.co\`, and fail-closed validation that prevents
13
+ genuine \`rrk_test_\` credentials from being mixed with live keys.
14
+
7
15
  ## [0.5.0] - 2026-06-20
8
16
 
9
17
  ### Added
data/lib/rerout/client.rb CHANGED
@@ -24,6 +24,7 @@ require_relative 'tags_resource'
24
24
  module Rerout
25
25
  # Default production API base URL.
26
26
  DEFAULT_BASE_URL = 'https://api.rerout.co'
27
+ SANDBOX_BASE_URL = 'https://sandbox-api.rerout.co'
27
28
 
28
29
  # Main entry point — construct one of these per project API key and re-use
29
30
  # it across requests. Thread-safe so long as the injected Faraday connection
@@ -52,21 +53,19 @@ module Rerout
52
53
 
53
54
  # @param api_key [String] project API key (`rrk_…`). Required.
54
55
  # @param base_url [String, nil] override base URL. Defaults to `https://api.rerout.co`.
56
+ # @param environment [Symbol] production or sandbox data plane.
57
+ # @param sandbox [Boolean] convenience alias for the sandbox environment.
55
58
  # @param connection [Faraday::Connection, nil] inject a Faraday connection
56
59
  # (useful for the test adapter or for sharing connection pools).
57
60
  # @param timeout [Integer] per-request timeout in seconds. Default 30.
58
61
  # @param user_agent [String, nil] override the default `User-Agent` header.
59
- def initialize(api_key:, base_url: nil, connection: nil, timeout: 30, user_agent: nil)
60
- if api_key.nil? || !api_key.is_a?(String) || api_key.strip.empty?
61
- raise Error.new(
62
- code: 'missing_api_key',
63
- message: 'A project API key is required to construct Rerout::Client.',
64
- status: 0
65
- )
66
- end
62
+ def initialize(api_key:, base_url: nil, environment: :production, sandbox: false,
63
+ connection: nil, timeout: 30, user_agent: nil)
64
+ validate_api_key!(api_key)
65
+ is_sandbox = resolve_sandbox!(api_key, environment, sandbox)
67
66
 
68
67
  @api_key = api_key
69
- @base_url = (base_url || DEFAULT_BASE_URL).to_s.sub(%r{/+\z}, '')
68
+ @base_url = (base_url || (is_sandbox ? SANDBOX_BASE_URL : DEFAULT_BASE_URL)).to_s.sub(%r{/+\z}, '')
70
69
  @timeout = timeout
71
70
  @user_agent = user_agent || "rerout-ruby/#{Rerout::VERSION}"
72
71
  @connection = connection || default_connection
@@ -105,6 +104,37 @@ module Rerout
105
104
 
106
105
  private
107
106
 
107
+ def validate_api_key!(api_key)
108
+ return if api_key.is_a?(String) && !api_key.strip.empty?
109
+
110
+ raise Error.new(
111
+ code: 'missing_api_key',
112
+ message: 'A project API key is required to construct Rerout::Client.',
113
+ status: 0
114
+ )
115
+ end
116
+
117
+ def resolve_sandbox!(api_key, environment, sandbox)
118
+ resolved_environment = sandbox ? :sandbox : environment.to_sym
119
+ unless %i[production sandbox].include?(resolved_environment)
120
+ raise Error.new(
121
+ code: 'invalid_environment',
122
+ message: 'environment must be production or sandbox.',
123
+ status: 0
124
+ )
125
+ end
126
+
127
+ is_sandbox = resolved_environment == :sandbox
128
+ is_sandbox_key = api_key.match?(/\Arrk_test_[A-Za-z0-9]{32}\z/)
129
+ return is_sandbox if is_sandbox_key == is_sandbox
130
+
131
+ raise Error.new(
132
+ code: 'wrong_environment',
133
+ message: 'The API key does not match the selected Rerout environment.',
134
+ status: 0
135
+ )
136
+ end
137
+
108
138
  def perform_request(method:, path:, query:, headers:, payload:)
109
139
  full_url = "#{@base_url}#{path}"
110
140
  @connection.public_send(method) do |req|
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rerout
4
4
  # Library version. Follows semantic versioning.
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rerout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codecraft Solutions
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-07-13 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: faraday
@@ -135,6 +136,7 @@ metadata:
135
136
  bug_tracker_uri: https://github.com/ModestNerds-Co/rerout-sdks/issues
136
137
  documentation_uri: https://rerout.co/docs
137
138
  rubygems_mfa_required: 'true'
139
+ post_install_message:
138
140
  rdoc_options: []
139
141
  require_paths:
140
142
  - lib
@@ -149,7 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  - !ruby/object:Gem::Version
150
152
  version: '0'
151
153
  requirements: []
152
- rubygems_version: 3.6.9
154
+ rubygems_version: 3.0.3.1
155
+ signing_key:
153
156
  specification_version: 4
154
157
  summary: Official Ruby SDK for the Rerout branded-link API.
155
158
  test_files: []