castle-rb 9.1.0 → 9.3.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: c138f51f6546b1a01b53f8542506e6e8566928d4b0907992d33dcb648788c9ee
4
- data.tar.gz: d8f282e27ad75bad8e0d137b21ca15158ac3b6c3603f89098a3d77487cfa3658
3
+ metadata.gz: 45354835d85251395bc9830ccdcccbe04db16d6e19134babbd36ff110e587758
4
+ data.tar.gz: 9560b565f2042f57f6a5cb85e54860b2ef5f950c9b1d63c4371420d41dc7ff7a
5
5
  SHA512:
6
- metadata.gz: 9b5c96cf024088766cd6cf1dad0b6c371dcfee03241ec695fc148c08d5bafd5658b4731514db4e8cf88ad430607cf26650077ce0db2ee9b95d56d62459b6a987
7
- data.tar.gz: 054deed51da4427e2c715b2e5f63a646d8acc73125e64d30b5d3fa2fadbd42119baf536d2b83e31b158fb5423f0b18b7d0bda67613d0f1fbb360c59c8f4959e3
6
+ metadata.gz: 4471bf9db7d73a0434db57dc27a0f5d265f5d9ff62f0046bf9755636bd57b6ab0676169c579cd67bb5ba29a8719a9ddc93ccd0169ffdaa5e65e44a3dfb6083d3
7
+ data.tar.gz: 7725515e779e546a4ce763aad5a4bd8001aa0cf755a07963bb44643726c115d271a1210529d48d90f5feef50a6f63b8194f9bf6349e5338dccc11a93693fddc3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.3.0
4
+
5
+ - Add `Castle::PaymentRequiredError` for HTTP 402 responses.
6
+
7
+ ## 9.2.0
8
+
9
+ **Changes:**
10
+
11
+ - Slim down the default request context to `headers`, `ip` and `library`; the remaining data is already available via `headers`.
12
+ - Remove the internal `Castle::ClientId::Extract` service and the now-unused `cookies` plumbing in `Castle::Context::GetDefault`.
13
+ - No longer read the API secret from the `CASTLE_API_SECRET` environment variable automatically; set `Castle.api_secret` explicitly (for example `Castle.api_secret = ENV.fetch('CASTLE_API_SECRET')`).
14
+
3
15
  ## 9.1.0
4
16
 
5
17
  **Enhancements:**
@@ -17,7 +29,7 @@
17
29
  - Bump Bundler 2.6.9 → 2.7.2
18
30
  - Bump json 2.19.5 → 2.19.7
19
31
 
20
- ## master
32
+ ## Unreleased
21
33
 
22
34
  - Bump dependencies (rack 3.1.19 → 3.2.6, rake, rspec-\*, timecop, simplecov-html, diff-lcs)
23
35
  - Bump Ruby to 3.4.9 (zlib CVE-2026-27820)
data/README.md CHANGED
@@ -293,6 +293,7 @@ All exceptions inherit from `Castle::Error`. The most useful ones:
293
293
  | `Castle::InvalidRequestTokenError` | The `request_token` is missing or invalid. |
294
294
  | `Castle::InvalidParametersError` | 422 response with validation details. |
295
295
  | `Castle::RateLimitError` | 429 response — back off and retry. |
296
+ | `Castle::PaymentRequiredError` | 402 response. |
296
297
  | `Castle::UnauthorizedError` | 401 — bad API secret. |
297
298
  | `Castle::InternalServerError` | 5xx response from Castle. |
298
299
  | `Castle::WebhookVerificationError` | Webhook signature did not match. |
data/lib/castle/api.rb CHANGED
@@ -43,9 +43,8 @@ module Castle
43
43
  # @note We need to initialize the error, as the original error is a cause for this
44
44
  # custom exception. If we would do it the default Ruby way, the original error
45
45
  # would get converted into a string
46
- # rubocop:disable Style/RaiseArgs
46
+ # rubocop:disable-next Style/RaiseArgs
47
47
  raise Castle::RequestError.new(e)
48
- # rubocop:enable Style/RaiseArgs
49
48
  end
50
49
  end
51
50
  end
@@ -69,7 +69,7 @@ module Castle
69
69
  self.base_url = BASE_URL
70
70
  self.allowlisted = [].freeze
71
71
  self.denylisted = [].freeze
72
- self.api_secret = ENV.fetch('CASTLE_API_SECRET', '')
72
+ self.api_secret = ''
73
73
  self.ip_headers = [].freeze
74
74
  self.trusted_proxies = [].freeze
75
75
  self.trust_proxy_chain = false
@@ -3,50 +3,21 @@
3
3
  module Castle
4
4
  module Context
5
5
  class GetDefault
6
- def initialize(request, cookies = nil)
6
+ def initialize(request)
7
7
  @pre_headers = Castle::Headers::Filter.new(request).call
8
- @cookies = cookies || request.cookies
9
- @request = request
10
8
  end
11
9
 
12
10
  def call
13
- {
14
- client_id: client_id,
15
- active: true,
16
- headers: headers,
17
- ip: ip,
18
- library: {
19
- name: 'castle-rb',
20
- version: Castle::VERSION
21
- }
22
- }.tap do |result|
23
- result[:locale] = locale if locale
24
- result[:user_agent] = user_agent if user_agent
25
- end
11
+ { headers: headers, ip: ip, library: { name: 'castle-rb', version: Castle::VERSION } }
26
12
  end
27
13
 
28
14
  private
29
15
 
30
- # @return [String]
31
- def locale
32
- @pre_headers['Accept-Language']
33
- end
34
-
35
- # @return [String]
36
- def user_agent
37
- @pre_headers['User-Agent']
38
- end
39
-
40
16
  # @return [String]
41
17
  def ip
42
18
  Castle::IPs::Extract.new(@pre_headers).call
43
19
  end
44
20
 
45
- # @return [String]
46
- def client_id
47
- Castle::ClientId::Extract.new(@pre_headers, @cookies).call
48
- end
49
-
50
21
  # formatted and filtered headers
51
22
  # @return [Hash]
52
23
  def headers
@@ -9,7 +9,7 @@ module Castle
9
9
  # @param options [Hash]
10
10
  # @return [Hash]
11
11
  def call(request, options = {})
12
- default_context = Castle::Context::GetDefault.new(request, options[:cookies]).call
12
+ default_context = Castle::Context::GetDefault.new(request).call
13
13
  Castle::Context::Merge.call(default_context, options[:context])
14
14
  end
15
15
  end
@@ -7,6 +7,7 @@ module Castle
7
7
  RESPONSE_ERRORS = {
8
8
  400 => Castle::BadRequestError,
9
9
  401 => Castle::UnauthorizedError,
10
+ 402 => Castle::PaymentRequiredError,
10
11
  403 => Castle::ForbiddenError,
11
12
  404 => Castle::NotFoundError,
12
13
  419 => Castle::UserUnauthorizedError,
data/lib/castle/errors.rb CHANGED
@@ -65,6 +65,9 @@ module Castle
65
65
  class RateLimitError < Castle::ApiError
66
66
  end
67
67
 
68
+ class PaymentRequiredError < Castle::ApiError
69
+ end
70
+
68
71
  # all internal server errors
69
72
  class InternalServerError < Castle::ApiError
70
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Castle
4
- VERSION = '9.1.0'
4
+ VERSION = '9.3.0'
5
5
  end
data/lib/castle.rb CHANGED
@@ -78,7 +78,6 @@
78
78
  castle/headers/format
79
79
  castle/headers/extract
80
80
  castle/secure_mode
81
- castle/client_id/extract
82
81
  castle/ips/extract
83
82
  castle/core/get_connection
84
83
  castle/core/process_response
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: castle-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Brissmyr
@@ -67,7 +67,6 @@ files:
67
67
  - lib/castle/client_actions/list_items.rb
68
68
  - lib/castle/client_actions/lists.rb
69
69
  - lib/castle/client_actions/privacy.rb
70
- - lib/castle/client_id/extract.rb
71
70
  - lib/castle/command.rb
72
71
  - lib/castle/commands/events/group.rb
73
72
  - lib/castle/commands/events/query.rb
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
146
  - !ruby/object:Gem::Version
148
147
  version: '0'
149
148
  requirements: []
150
- rubygems_version: 4.0.8
149
+ rubygems_version: 3.6.9
151
150
  specification_version: 4
152
151
  summary: Official Ruby SDK for the Castle fraud and account-abuse prevention platform
153
152
  test_files: []
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Castle
4
- module ClientId
5
- # used for extraction of cookies and headers from the request
6
- class Extract
7
- # @param headers [Hash]
8
- # @param cookies [NilClass|Hash]
9
- def initialize(headers, cookies)
10
- @headers = headers
11
- @cookies = cookies || {}
12
- end
13
-
14
- # extracts client id
15
- # @return [String]
16
- def call
17
- @headers['X-Castle-Client-Id'] || @cookies['__cid'] || ''
18
- end
19
- end
20
- end
21
- end