pcp-server-ruby-sdk 1.3.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +105 -0
- data/example-app/example.rb +71 -0
- data/lib/PCP-server-Ruby-SDK/communicator_configuration.rb +6 -3
- data/lib/PCP-server-Ruby-SDK/endpoints/authentication_api_client.rb +4 -0
- data/lib/PCP-server-Ruby-SDK/endpoints/base_api_client.rb +59 -8
- data/lib/PCP-server-Ruby-SDK/endpoints/checkout_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/commerce_case_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/order_management_checkout_actions_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/version.rb +1 -1
- data/package-lock.json +179 -179
- data/package.json +1 -1
- data/spec/communicator_configuration_spec.rb +27 -0
- data/spec/endpoints/authentication_api_client_spec.rb +1 -1
- data/spec/endpoints/base_api_client_spec.rb +222 -0
- data/spec/endpoints/checkout_api_client_spec.rb +1 -1
- data/spec/endpoints/commerce_case_api_client_spec.rb +1 -1
- data/spec/endpoints/order_management_checkout_actions_api_client_spec.rb +1 -1
- data/spec/endpoints/payment_execution_api_client_spec.rb +1 -1
- data/spec/endpoints/payment_information_api_client_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- metadata +8 -6
data/package.json
CHANGED
@@ -19,5 +19,32 @@ RSpec.describe PCPServerSDK::CommunicatorConfiguration do
|
|
19
19
|
it 'sets host' do
|
20
20
|
expect(config.host).to eq(host)
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'sets http_client to nil by default' do
|
24
|
+
expect(config.http_client).to be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with custom http_client' do
|
28
|
+
let(:custom_http_client) { Net::HTTP.new('example.com', 80) }
|
29
|
+
let(:config_with_client) { PCPServerSDK::CommunicatorConfiguration.new(api_key, api_secret, host, custom_http_client) }
|
30
|
+
|
31
|
+
it 'sets the custom http_client' do
|
32
|
+
expect(config_with_client.http_client).to eq(custom_http_client)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#http_client=' do
|
38
|
+
it 'allows setting http_client after initialization' do
|
39
|
+
custom_client = Net::HTTP.new('example.com', 80)
|
40
|
+
config.http_client = custom_client
|
41
|
+
expect(config.http_client).to eq(custom_client)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows setting http_client to a proc' do
|
45
|
+
client_factory = proc { |uri| Net::HTTP.new(uri.host, uri.port) }
|
46
|
+
config.http_client = client_factory
|
47
|
+
expect(config.http_client).to eq(client_factory)
|
48
|
+
end
|
22
49
|
end
|
23
50
|
end
|
@@ -7,7 +7,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
7
7
|
|
8
8
|
|
9
9
|
RSpec.describe PCPServerSDK::Endpoints::AuthenticationApiClient do
|
10
|
-
let(:config) {
|
10
|
+
let(:config) { mock_communicator_config }
|
11
11
|
let(:client) { PCPServerSDK::Endpoints::AuthenticationApiClient.new(config) }
|
12
12
|
|
13
13
|
describe '#get_authentication_tokens' do
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
3
|
+
|
4
|
+
RSpec.describe PCPServerSDK::Endpoints::BaseApiClient do
|
5
|
+
let(:api_key) { 'test_api_key' }
|
6
|
+
let(:api_secret) { 'test_api_secret' }
|
7
|
+
let(:host) { 'https://api.example.com' }
|
8
|
+
let(:config) { PCPServerSDK::CommunicatorConfiguration.new(api_key, api_secret, host) }
|
9
|
+
let(:client) { PCPServerSDK::Endpoints::BaseApiClient.new(config) }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'sets the config' do
|
13
|
+
expect(client.send(:get_config)).to eq(config)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets http_client to nil by default' do
|
17
|
+
expect(client.http_client).to be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with custom http_client' do
|
21
|
+
let(:custom_http_client) { Net::HTTP.new('example.com', 80) }
|
22
|
+
let(:client_with_custom) { PCPServerSDK::Endpoints::BaseApiClient.new(config, custom_http_client) }
|
23
|
+
|
24
|
+
it 'sets the custom http_client' do
|
25
|
+
expect(client_with_custom.http_client).to eq(custom_http_client)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#http_client=' do
|
31
|
+
it 'allows setting http_client after initialization' do
|
32
|
+
custom_client = Net::HTTP.new('example.com', 80)
|
33
|
+
client.http_client = custom_client
|
34
|
+
expect(client.http_client).to eq(custom_client)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#get_http_client (private method)' do
|
39
|
+
let(:uri) { URI.parse('https://api.example.com/test') }
|
40
|
+
|
41
|
+
context 'with client-specific http_client' do
|
42
|
+
let(:client_specific_http) { Net::HTTP.new('client.example.com', 443) }
|
43
|
+
|
44
|
+
before do
|
45
|
+
client.http_client = client_specific_http
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns the client-specific http client' do
|
49
|
+
result = client.send(:get_http_client, uri)
|
50
|
+
expect(result).to eq(client_specific_http)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'prioritizes client-specific over global configuration' do
|
54
|
+
global_http = Net::HTTP.new('global.example.com', 443)
|
55
|
+
config.http_client = global_http
|
56
|
+
|
57
|
+
result = client.send(:get_http_client, uri)
|
58
|
+
expect(result).to eq(client_specific_http)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with global http_client in configuration' do
|
63
|
+
let(:global_http) { Net::HTTP.new('global.example.com', 443) }
|
64
|
+
|
65
|
+
before do
|
66
|
+
config.http_client = global_http
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the global http client when no client-specific client is set' do
|
70
|
+
result = client.send(:get_http_client, uri)
|
71
|
+
expect(result).to eq(global_http)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with proc-based http_client factory' do
|
76
|
+
let(:http_factory) do
|
77
|
+
proc do |uri|
|
78
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
79
|
+
http.use_ssl = uri.scheme == 'https'
|
80
|
+
http.read_timeout = 30
|
81
|
+
http
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
before do
|
86
|
+
client.http_client = http_factory
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'calls the proc with the URI and returns the result' do
|
90
|
+
result = client.send(:get_http_client, uri)
|
91
|
+
expect(result).to be_a(Net::HTTP)
|
92
|
+
expect(result.address).to eq('api.example.com')
|
93
|
+
expect(result.port).to eq(443)
|
94
|
+
expect(result.use_ssl?).to be true
|
95
|
+
expect(result.read_timeout).to eq(30)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with callable object as http_client factory' do
|
100
|
+
let(:http_factory) do
|
101
|
+
Class.new do
|
102
|
+
def call(uri)
|
103
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
104
|
+
http.use_ssl = uri.scheme == 'https'
|
105
|
+
http.open_timeout = 10
|
106
|
+
http
|
107
|
+
end
|
108
|
+
end.new
|
109
|
+
end
|
110
|
+
|
111
|
+
before do
|
112
|
+
config.http_client = http_factory
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'calls the callable object with the URI and returns the result' do
|
116
|
+
result = client.send(:get_http_client, uri)
|
117
|
+
expect(result).to be_a(Net::HTTP)
|
118
|
+
expect(result.address).to eq('api.example.com')
|
119
|
+
expect(result.port).to eq(443)
|
120
|
+
expect(result.use_ssl?).to be true
|
121
|
+
expect(result.open_timeout).to eq(10)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with default http_client (no customization)' do
|
126
|
+
it 'creates a default Net::HTTP client' do
|
127
|
+
result = client.send(:get_http_client, uri)
|
128
|
+
expect(result).to be_a(Net::HTTP)
|
129
|
+
expect(result.address).to eq('api.example.com')
|
130
|
+
expect(result.port).to eq(443)
|
131
|
+
expect(result.use_ssl?).to be true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'with invalid http_client' do
|
136
|
+
before do
|
137
|
+
client.http_client = "invalid_client"
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'raises an ArgumentError' do
|
141
|
+
expect {
|
142
|
+
client.send(:get_http_client, uri)
|
143
|
+
}.to raise_error(ArgumentError, /HTTP client must be a Net::HTTP instance, Proc, or respond to :call/)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#resolve_http_client (private method)' do
|
149
|
+
let(:uri) { URI.parse('https://api.example.com/test') }
|
150
|
+
|
151
|
+
context 'with Net::HTTP instance' do
|
152
|
+
let(:http_instance) { Net::HTTP.new('example.com', 80) }
|
153
|
+
|
154
|
+
it 'returns the instance directly' do
|
155
|
+
result = client.send(:resolve_http_client, http_instance, uri)
|
156
|
+
expect(result).to eq(http_instance)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with Proc' do
|
161
|
+
let(:http_proc) { proc { |uri| Net::HTTP.new(uri.host, uri.port) } }
|
162
|
+
|
163
|
+
it 'calls the proc with the URI' do
|
164
|
+
result = client.send(:resolve_http_client, http_proc, uri)
|
165
|
+
expect(result).to be_a(Net::HTTP)
|
166
|
+
expect(result.address).to eq('api.example.com')
|
167
|
+
expect(result.port).to eq(443)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'with callable object' do
|
172
|
+
let(:callable) do
|
173
|
+
Class.new do
|
174
|
+
def call(uri)
|
175
|
+
Net::HTTP.new(uri.host, uri.port)
|
176
|
+
end
|
177
|
+
end.new
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'calls the object with the URI' do
|
181
|
+
result = client.send(:resolve_http_client, callable, uri)
|
182
|
+
expect(result).to be_a(Net::HTTP)
|
183
|
+
expect(result.address).to eq('api.example.com')
|
184
|
+
expect(result.port).to eq(443)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'with invalid object' do
|
189
|
+
it 'raises an ArgumentError' do
|
190
|
+
expect {
|
191
|
+
client.send(:resolve_http_client, "invalid", uri)
|
192
|
+
}.to raise_error(ArgumentError, /HTTP client must be a Net::HTTP instance, Proc, or respond to :call/)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#create_default_http_client (private method)' do
|
198
|
+
context 'with HTTPS URI' do
|
199
|
+
let(:uri) { URI.parse('https://api.example.com/test') }
|
200
|
+
|
201
|
+
it 'creates an HTTPS-enabled client' do
|
202
|
+
result = client.send(:create_default_http_client, uri)
|
203
|
+
expect(result).to be_a(Net::HTTP)
|
204
|
+
expect(result.address).to eq('api.example.com')
|
205
|
+
expect(result.port).to eq(443)
|
206
|
+
expect(result.use_ssl?).to be true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'with HTTP URI' do
|
211
|
+
let(:uri) { URI.parse('http://api.example.com/test') }
|
212
|
+
|
213
|
+
it 'creates an HTTP client' do
|
214
|
+
result = client.send(:create_default_http_client, uri)
|
215
|
+
expect(result).to be_a(Net::HTTP)
|
216
|
+
expect(result.address).to eq('api.example.com')
|
217
|
+
expect(result.port).to eq(80)
|
218
|
+
expect(result.use_ssl?).to be false
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
5
5
|
|
6
6
|
|
7
7
|
RSpec.describe PCPServerSDK::Endpoints::CheckoutApiClient do
|
8
|
-
let(:config) {
|
8
|
+
let(:config) { mock_communicator_config }
|
9
9
|
let(:client) { described_class.new(config) }
|
10
10
|
let(:error_body) { PCPServerSDK::Models::ErrorResponse.new(
|
11
11
|
error_id: '1',
|
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
5
5
|
|
6
6
|
|
7
7
|
RSpec.describe PCPServerSDK::Endpoints::CommerceCaseApiClient do
|
8
|
-
let(:config) {
|
8
|
+
let(:config) { mock_communicator_config }
|
9
9
|
let(:client) { described_class.new(config) }
|
10
10
|
let(:error_body) {
|
11
11
|
PCPServerSDK::Models::ErrorResponse.new(
|
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
5
5
|
|
6
6
|
|
7
7
|
RSpec.describe PCPServerSDK::Endpoints::OrderManagementCheckoutActionsApiClient do
|
8
|
-
let(:config) {
|
8
|
+
let(:config) { mock_communicator_config }
|
9
9
|
let(:client) { described_class.new(config) }
|
10
10
|
let(:error_body) {
|
11
11
|
PCPServerSDK::Models::ErrorResponse.new(
|
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
5
5
|
|
6
6
|
|
7
7
|
RSpec.describe PCPServerSDK::Endpoints::PaymentExecutionApiClient do
|
8
|
-
let(:config) {
|
8
|
+
let(:config) { mock_communicator_config }
|
9
9
|
let(:client) { described_class.new(config) }
|
10
10
|
let(:error_body) {
|
11
11
|
PCPServerSDK::Models::ErrorResponse.new(
|
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
|
|
5
5
|
|
6
6
|
|
7
7
|
RSpec.describe PCPServerSDK::Endpoints::PaymentInformationApiClient do
|
8
|
-
let(:config) {
|
8
|
+
let(:config) { mock_communicator_config }
|
9
9
|
let(:client) { described_class.new(config) }
|
10
10
|
let(:error_body) {
|
11
11
|
PCPServerSDK::Models::ErrorResponse.new(
|
data/spec/spec_helper.rb
CHANGED
@@ -25,4 +25,13 @@ RSpec.configure do |config|
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
# Helper method to create properly mocked CommunicatorConfiguration
|
29
|
+
def mock_communicator_config(api_key: '', api_secret: '', host: 'https://api.example.com', http_client: nil)
|
30
|
+
double('PCPServerSDK::CommunicatorConfiguration',
|
31
|
+
api_key: api_key,
|
32
|
+
api_secret: api_secret,
|
33
|
+
host: host,
|
34
|
+
http_client: http_client)
|
35
|
+
end
|
36
|
+
|
28
37
|
require 'rspec'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcp-server-ruby-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PAYONE GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-http
|
@@ -281,6 +281,7 @@ files:
|
|
281
281
|
- sonar-project.properties
|
282
282
|
- spec/communicator_configuration_spec.rb
|
283
283
|
- spec/endpoints/authentication_api_client_spec.rb
|
284
|
+
- spec/endpoints/base_api_client_spec.rb
|
284
285
|
- spec/endpoints/checkout_api_client_spec.rb
|
285
286
|
- spec/endpoints/commerce_case_api_client_spec.rb
|
286
287
|
- spec/endpoints/order_management_checkout_actions_api_client_spec.rb
|
@@ -320,17 +321,18 @@ specification_version: 4
|
|
320
321
|
summary: Commerce Platform API Ruby Gem
|
321
322
|
test_files:
|
322
323
|
- spec/communicator_configuration_spec.rb
|
323
|
-
- spec/endpoints/checkout_api_client_spec.rb
|
324
324
|
- spec/endpoints/authentication_api_client_spec.rb
|
325
325
|
- spec/endpoints/commerce_case_api_client_spec.rb
|
326
|
-
- spec/endpoints/order_management_checkout_actions_api_client_spec.rb
|
327
326
|
- spec/endpoints/payment_execution_api_client_spec.rb
|
327
|
+
- spec/endpoints/checkout_api_client_spec.rb
|
328
328
|
- spec/endpoints/payment_information_api_client_spec.rb
|
329
|
-
- spec/
|
329
|
+
- spec/endpoints/base_api_client_spec.rb
|
330
|
+
- spec/endpoints/order_management_checkout_actions_api_client_spec.rb
|
330
331
|
- spec/errors/api_error_response_exception_spec.rb
|
331
332
|
- spec/errors/api_exception_spec.rb
|
332
|
-
- spec/
|
333
|
+
- spec/errors/api_response_retrieval_exception_spec.rb
|
333
334
|
- spec/queries/get_checkouts_query_spec.rb
|
335
|
+
- spec/queries/get_commerce_cases_query_spec.rb
|
334
336
|
- spec/request_header_generator_spec.rb
|
335
337
|
- spec/spec_helper.rb
|
336
338
|
- spec/transformer/apple_pay_transformer_spec.rb
|