treezor_connect 0.24.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7af15421900de0aee06206b3a3f1a600afe157a066a4674dc7a2ca40ea232e71
|
|
4
|
+
data.tar.gz: 6d625b75bff522f4a26df41556fb1948ed0fc2dfc0d289a1065bd9cf7778fb47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
88
|
-
|
|
89
|
-
response
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
|
@@ -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
|
data/lib/treezor_connect.rb
CHANGED
|
@@ -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, :
|
|
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,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: treezor_connect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.24.
|
|
4
|
+
version: 0.24.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- stefakins
|
|
8
8
|
- jbauzone
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A gem for making HTTP calls to Treezor Connect.
|
|
14
14
|
email: stefan.atkinson69@gmail.com
|