treezor_connect 0.23.0 → 0.24.1

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: 9853144e2f1a2e86103752fae6340f674ecd3f4c25e38f32cad3f326a0021c63
4
- data.tar.gz: 932fd89d512e1eeb940ef10870a5938843e3c9129c9b6f2c0bfa0387dbbe20f6
3
+ metadata.gz: 7af15421900de0aee06206b3a3f1a600afe157a066a4674dc7a2ca40ea232e71
4
+ data.tar.gz: 6d625b75bff522f4a26df41556fb1948ed0fc2dfc0d289a1065bd9cf7778fb47
5
5
  SHA512:
6
- metadata.gz: 208436fb13bdd61369741a1ce577a6dc798c47ab48467676b2cdb9e80c04bf9e859054e00fbd3f0436a9ed8b88b2c2ccdc8a488bc9baf30f7f04a88749f3f2de
7
- data.tar.gz: d630695ec6682459dacaf7bdb67c13699f1ba039248d173433a3908637984356c246e5db0c74db6c848a1cc5d6908df4e0dbed0e6dc6e0b0cf8193f8892a726e
6
+ metadata.gz: 90a9a1b12c56e47162b90a1c5e645ddbea8363dfbf85b52355930d5aa25cbdcfe70200c63d7dd35f2a3a0ed77fbd09c1266006fa3c9a24e63138ec72cd363aea
7
+ data.tar.gz: c3ab3bab897518daa8329d3f78c6f45dd8e44aeaaf80f5e3351e1120cbba65b56d80749b8f92f4e3879111c08b5c9097db9f71b0e520a5cc60f99ea8527acfe3
@@ -16,7 +16,11 @@ module TreezorConnect
16
16
  client = TreezorConnect::Client.new(access_token)
17
17
  responses = client.execute_parallel_requests(method, url, headers:, params_list:)
18
18
  responses.map do |response|
19
- response.is_a?(ApiError) ? response : TreezorResponse.from_http_response(response)
19
+ if response.is_a?(ApiError)
20
+ response
21
+ else
22
+ TreezorResponse.from_http_response(response, record_headers: TreezorConnect.bulk_record_headers)
23
+ end
20
24
  end
21
25
  end
22
26
 
@@ -8,11 +8,9 @@ module TreezorConnect
8
8
  @access_token = access_token || default_access_token
9
9
  @conn = Faraday.new(
10
10
  url: TreezorConnect.api_base_url,
11
- headers: { 'Authorization' => "Bearer #{@access_token}" },
12
- parallel_manager:
11
+ headers: { 'Authorization' => "Bearer #{@access_token}" }
13
12
  ) do |faraday|
14
13
  faraday.response :logger, Logger.new($stdout) if ENV['ENABLE_HTTP_LOGGING']
15
- faraday.adapter :typhoeus
16
14
  end
17
15
  end
18
16
 
@@ -26,21 +24,33 @@ module TreezorConnect
26
24
  end
27
25
 
28
26
  def execute_parallel_requests(method, path, headers: {}, params_list: [])
29
- responses = []
30
- conn.in_parallel do
31
- params_list.each do |params|
32
- responses << conn.public_send(method, path) do |req|
33
- req.headers.merge!(headers)
34
- configure_request(req, params)
35
- end
36
- end
27
+ # For now this is only needed for BulkVoP that uses json, if needed for other uses we might need to refactor a bit
28
+ unless params_list.flat_map(&:keys).uniq == [:body]
29
+ raise NotImplementedError, 'For now parallel requests only work on JSON POST'
30
+ end
31
+
32
+ # Shared frozen headers — built once, never duped : this is to avoid huge memory costs
33
+ shared_headers = { **conn.headers, 'Content-Type' => 'application/json', **headers }.freeze
34
+
35
+ requests = params_list.map do |params|
36
+ Typhoeus::Request.new(
37
+ conn.url_prefix + path, method:, headers: shared_headers, body: params.fetch(:body).to_json
38
+ ).tap { |req| parallel_manager.queue(req) }
37
39
  end
38
40
 
39
- responses.map { |response| process_parallel_response(response) }
41
+ parallel_manager.run
42
+
43
+ process_parallel_requests(requests)
40
44
  end
41
45
 
42
46
  private
43
47
 
48
+ module FaradayResponseCompatibilyMethods
49
+ def status
50
+ code
51
+ end
52
+ end
53
+
44
54
  attr_reader :conn
45
55
 
46
56
  def configure_request(req, params)
@@ -65,7 +75,7 @@ module TreezorConnect
65
75
  def parallel_manager
66
76
  @parallel_manager ||= begin
67
77
  # Currently library default is 200 but this way we are future-proof
68
- max_concurrency = TreezorConnect.max_concurrency || Typhoeus::Hydra.new.max_concurrency
78
+ max_concurrency = TreezorConnect.bulk_max_concurrency || Typhoeus::Hydra.new.max_concurrency
69
79
  Typhoeus::Hydra.new(max_concurrency:)
70
80
  end
71
81
  end
@@ -84,13 +94,16 @@ module TreezorConnect
84
94
  end
85
95
  end
86
96
 
87
- def process_parallel_response(response)
88
- if response.success?
89
- response
90
- elsif response.status == 303
91
- AlreadyCreatedError.new(response)
92
- else
93
- build_api_error(http_status: response.status, http_body: JSON.parse(response.body))
97
+ def process_parallel_requests(requests)
98
+ requests.map do |request|
99
+ response = request.response
100
+ # For parallel calls we use Typhoeus requests, to play well with the rest of our code we mimic Faraday responses
101
+ response.extend(FaradayResponseCompatibilyMethods)
102
+ begin
103
+ process_response(response)
104
+ rescue AlreadyCreatedError, ApiError => e
105
+ e
106
+ end
94
107
  end
95
108
  end
96
109
 
@@ -11,5 +11,6 @@ module TreezorConnect
11
11
  end
12
12
 
13
13
  extend TreezorConnect::ApiOperations::Create
14
+ extend TreezorConnect::ApiOperations::Fetch
14
15
  end
15
16
  end
@@ -4,11 +4,11 @@ module TreezorConnect
4
4
  class TreezorResponse
5
5
  attr_accessor :data, :http_body, :http_headers, :http_status
6
6
 
7
- def self.from_http_response(http_resp)
7
+ def self.from_http_response(http_resp, record_headers: true)
8
8
  resp = TreezorResponse.new
9
9
  resp.data = JSON.parse(http_resp.body) if http_resp.body.to_s != ''
10
10
  resp.http_body = http_resp.body
11
- resp.http_headers = http_resp.headers
11
+ resp.http_headers = http_resp.headers if record_headers
12
12
  resp.http_status = http_resp.status
13
13
  resp
14
14
  end
@@ -34,7 +34,7 @@ require 'treezor_connect/resources'
34
34
 
35
35
  module TreezorConnect
36
36
  class << self
37
- attr_accessor :api_base_url, :client_id, :client_secret, :max_concurrency
37
+ attr_accessor :api_base_url, :client_id, :client_secret, :bulk_max_concurrency, :bulk_record_headers
38
38
  end
39
39
 
40
40
  def self.configure
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treezor_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - stefakins
8
8
  - jbauzone
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2026-06-16 00:00:00.000000000 Z
11
+ date: 2026-06-18 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A gem for making HTTP calls to Treezor Connect.
15
14
  email: stefan.atkinson69@gmail.com
@@ -57,7 +56,6 @@ licenses:
57
56
  - MIT
58
57
  metadata:
59
58
  rubygems_mfa_required: 'true'
60
- post_install_message:
61
59
  rdoc_options: []
62
60
  require_paths:
63
61
  - lib
@@ -72,8 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  - !ruby/object:Gem::Version
73
71
  version: '0'
74
72
  requirements: []
75
- rubygems_version: 3.4.19
76
- signing_key:
73
+ rubygems_version: 3.6.5
77
74
  specification_version: 4
78
75
  summary: A gem for making HTTP calls to Treezor Connect.
79
76
  test_files: []