mangopay 3.19.0 → 3.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2459553bb0f22fb9230f0b13fa8068e6dccb7996c3436a669bea65e05af3e575
4
- data.tar.gz: 1242453e9fd1f2d9fb943c737c0eef69e1caf26aed2aaae24ee2012803816ddc
3
+ metadata.gz: c22a75f6a785d55c368cc565e3d9b2dc399c5b08cb8b4b8ed27f24762ee9b6a2
4
+ data.tar.gz: 7b1b066c802f7716aa500267349928ed05d7df7ac9be74e63855376c284e2c03
5
5
  SHA512:
6
- metadata.gz: f3478fdff62b888c86e3e38d1079cd467eb0e7860e16fc9977d9e6be49bec4c645e5a63b0a954c2f416577788abd125759d6b079e191b55a846af524044598e9
7
- data.tar.gz: 11634f163a8d798787a4a1a200592b2387caf05df99df24a4089add703d6128f648aaa8c884c590bbaba2e53ab85ca45100e52fbb3ff89e218a6e0c9d7ddfedb
6
+ metadata.gz: 51efb4cb9942a749604b7f44e0fb79958b862ab03a0aa742c70af9bc650001aff7b339d43e56011392556e2e38572343c19a243e5218e09b24d4960346d3c10c
7
+ data.tar.gz: 1b8d01d73103c23d7e999e6c4e49ae2d57f5161ecb20626be0465d581de3e4c606b38549c4bde0fc4e4b2d27d4a7684c6cd1566b949f32463bf52ace34b309cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## [3.20.0] - 2023-11-15
2
+ ### Added
3
+
4
+ Now, our SDK enables seamless integration with multiple clientIDs, offering enhanced flexibility and customization.
5
+
6
+ You can effortlessly create multiple configuration objects tailored to your specific needs:
7
+
8
+ ```
9
+ config = MangoPay::Configuration.new
10
+ config.client_id = 'your-client-id'
11
+ config.client_apiKey = 'your-api-key'
12
+ config.preproduction = true
13
+ ```
14
+ add them using :
15
+
16
+ `MangoPay.add_config('config1', config)`
17
+
18
+ and perform a call with them using :
19
+
20
+ `MangoPay.get_config('config1').apply_configuration`
21
+
22
+ The previous method configure() is still working.
23
+
1
24
  ## [3.19.0] - 2023-11-02
2
25
  ### Updated
3
26
 
data/README.md CHANGED
@@ -85,6 +85,25 @@ rescue MangoPay::ResponseError => ex
85
85
  end
86
86
  ```
87
87
 
88
+ ### Using multiple clientIDs
89
+ You can effortlessly create multiple configuration objects tailored to your specific needs:
90
+
91
+ ```
92
+ config = MangoPay::Configuration.new
93
+ config.client_id = 'your-client-id'
94
+ config.client_apiKey = 'your-api-key'
95
+ config.preproduction = true
96
+ ```
97
+ add them using :
98
+
99
+ `MangoPay.add_config('config1', config)`
100
+
101
+ and perform a call with them using :
102
+
103
+ `MangoPay.get_config('config1').apply_configuration`
104
+
105
+ The previous method configure() is still working.
106
+
88
107
  ### Accessing RateLimit Headers
89
108
  Along with each request, the rate limiting headers are automatically updated in MangoPay object:
90
109
 
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.19.0'
2
+ VERSION = '3.20.0'
3
3
  end
data/lib/mangopay.rb CHANGED
@@ -49,6 +49,8 @@ module MangoPay
49
49
  # temporary
50
50
  autoload :Temp, 'mangopay/temp'
51
51
 
52
+ @configurations = {}
53
+
52
54
  class Configuration
53
55
  attr_accessor :preproduction, :root_url,
54
56
  :client_id, :client_apiKey,
@@ -56,6 +58,20 @@ module MangoPay
56
58
  :http_max_retries, :http_open_timeout,
57
59
  :logger, :use_ssl
58
60
 
61
+ def apply_configuration
62
+ MangoPay.configure do |config|
63
+ config.preproduction = @preproduction
64
+ config.client_id = @client_id
65
+ config.client_apiKey = @client_apiKey
66
+ config.log_file = @log_file
67
+ config.http_timeout = @http_timeout
68
+ config.http_max_retries = @http_max_retries
69
+ config.http_open_timeout = @http_open_timeout
70
+ config.use_ssl = @use_ssl
71
+ config.logger = @logger
72
+ end
73
+ end
74
+
59
75
  def preproduction
60
76
  @preproduction || false
61
77
  end
@@ -138,6 +154,23 @@ module MangoPay
138
154
  @ratelimit = obj
139
155
  end
140
156
 
157
+ # Add MangoPay.Configuration to the list of configs
158
+ def add_config(name, config)
159
+ @configurations[name] = config
160
+ end
161
+
162
+ # Fetch a MangoPay configuration from the list of configs. Throw error if not found
163
+ def get_config(name)
164
+ config = @configurations[name]
165
+ raise "Could not find any configuration with name '#{name}'" unless config
166
+ config
167
+ end
168
+
169
+ def remove_config(name)
170
+ raise "Could not find any configuration with name '#{name}'" unless @configurations[name]
171
+ @configurations[name] = nil
172
+ end
173
+
141
174
  #
142
175
  # - +method+: HTTP method; lowercase symbol, e.g. :get, :post etc.
143
176
  # - +url+: the part after Configuration#root_url
@@ -13,6 +13,74 @@ describe MangoPay::Configuration do
13
13
  }
14
14
  end
15
15
 
16
+ it 'fails when calling with wrong client credentials, but succeeds after applying a new (correct) config' do
17
+ # create a wrong configuration
18
+ wrong_config = MangoPay::Configuration.new
19
+ wrong_config.client_id = 'placeholder'
20
+ wrong_config.client_apiKey = '0000'
21
+ wrong_config.preproduction = true
22
+
23
+ # create a valid configuration
24
+ valid_config = MangoPay::Configuration.new
25
+ valid_config.client_id = 'sdk-unit-tests'
26
+ valid_config.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
27
+ valid_config.preproduction = true
28
+
29
+ # add the 2 configs to the list of MangoPay configs
30
+ MangoPay.add_config('wrong', wrong_config)
31
+ MangoPay.add_config('valid', valid_config)
32
+
33
+ # apply wrong config
34
+ MangoPay.get_config('wrong').apply_configuration
35
+
36
+ expect {
37
+ MangoPay::User.fetch()
38
+ }.to raise_error { |err|
39
+ expect(err).to be_a MangoPay::ResponseError
40
+ expect(err.code).to eq '401'
41
+ expect(err.message).to eq 'invalid_client'
42
+ }
43
+
44
+ # apply valid configuration
45
+ MangoPay.get_config('valid').apply_configuration
46
+
47
+ # expect success
48
+ users = MangoPay::User.fetch()
49
+ expect(users).to be_kind_of(Array)
50
+ end
51
+
52
+ it 'fails when fetching a config that does not exist' do
53
+ expect {
54
+ MangoPay.get_config('placeholder')
55
+ }.to raise_error { |err|
56
+ expect(err).to be_a RuntimeError
57
+ expect(err.message).to eq "Could not find any configuration with name 'placeholder'"
58
+ }
59
+ end
60
+
61
+ it 'succeeds when removing config' do
62
+ wrong_config = MangoPay::Configuration.new
63
+ wrong_config.client_id = 'placeholder'
64
+ wrong_config.client_apiKey = '0000'
65
+ wrong_config.preproduction = true
66
+
67
+ MangoPay.add_config('wrong', wrong_config)
68
+
69
+ # pass when fetching config before removing it
70
+ MangoPay.get_config('wrong')
71
+
72
+ # remove config
73
+ MangoPay.remove_config('wrong')
74
+
75
+ # fail when trying to fetch after removal
76
+ expect {
77
+ MangoPay.get_config('wrong')
78
+ }.to raise_error { |err|
79
+ expect(err).to be_a RuntimeError
80
+ expect(err.message).to eq "Could not find any configuration with name 'wrong'"
81
+ }
82
+ end
83
+
16
84
  it 'goes ok when calling with correct client credentials' do
17
85
  reset_mangopay_configuration
18
86
  users = MangoPay::User.fetch()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangopay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.19.0
4
+ version: 3.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Lorieux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-11-02 00:00:00.000000000 Z
12
+ date: 2023-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json