xero-ruby 2.9.0 → 2.9.1

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: c675f5570117bebac6707f82b0c2e45f96fd534ba4dbb8a2d2babc8adbdf1661
4
- data.tar.gz: 810b2d8317158471ab824cb1a8cba37cd19f3f36a48096012953c2142c26452d
3
+ metadata.gz: fb43e668c4cbd29f1190365df174d64a56385710319bdf3061ebe048b6dddcee
4
+ data.tar.gz: 0c4bacf725b0130b1675bc300bff98840fe537958fb8eef4627c709afd69ee5c
5
5
  SHA512:
6
- metadata.gz: eff76c0592c7bcdfb8f60b8b97407bb523d21b6ca3f9ad5e6c8c858bee3415c630a7ede34f50c2ed7d1b1717d349165cb751b4a56f6562c666d44f698a951f70
7
- data.tar.gz: f46138e8871e805d640a456089c901b597656aee376c13099c5dc8bc28e610250c811742f6978fe56d4835e405f9bee66510276e8ed94e63074fd18e9d5557f1
6
+ metadata.gz: 0eb80a0480dbf63d28ff6295f43e5288e90c0299616bfd48a60401b8f214424baff1d990e6964bafbb76b0d569dd172ccbb151dc9c9c96a7c3697e10f4361897
7
+ data.tar.gz: 780bd04d6cde627f8c6b4ac56a69c018ac9e5fef49169ccdf6a89201b6e826b253a1942e5459429256c351a459e3c0a45f105f99554aec32dadfa9b36e7fa63a
@@ -38,7 +38,8 @@ module XeroRuby
38
38
  @redirect_uri = credentials[:redirect_uri]
39
39
  @scopes = credentials[:scopes]
40
40
  @state = credentials[:state]
41
- @config = append_to_default_config(config)
41
+ default_config = Configuration.default.clone
42
+ @config = append_to_default_config(default_config, config)
42
43
 
43
44
  @user_agent = "xero-ruby-#{VERSION}"
44
45
  @default_headers = {
@@ -47,9 +48,9 @@ module XeroRuby
47
48
  }
48
49
  end
49
50
 
50
- def append_to_default_config(user_config)
51
- config = Configuration.default
52
- user_config.each{|k,v| config.send("#{k}=", v) } if user_config
51
+ def append_to_default_config(default_config, user_config)
52
+ config = default_config
53
+ user_config.each{|k,v| config.send("#{k}=", v)}
53
54
  config
54
55
  end
55
56
 
@@ -96,22 +97,32 @@ module XeroRuby
96
97
 
97
98
  # Token Helpers
98
99
  def token_set
99
- XeroRuby.configure.token_set
100
+ @config.token_set
100
101
  end
101
102
 
102
103
  def access_token
103
- XeroRuby.configure.access_token
104
+ @config.access_token
105
+ end
106
+
107
+ def id_token
108
+ @config.id_token
104
109
  end
105
110
 
106
111
  def set_token_set(token_set)
107
112
  # helper to set the token_set on a client once the user
108
113
  # has a valid token set ( access_token & refresh_token )
109
- XeroRuby.configure.token_set = token_set
114
+ @config.token_set = token_set
110
115
  set_access_token(token_set['access_token'])
111
116
  end
112
117
 
113
118
  def set_access_token(access_token)
114
- XeroRuby.configure.access_token = access_token
119
+ # puts "access_token -> #{access_token}"
120
+ @config.access_token = access_token
121
+ # puts "@config.access_token -> #{@config.access_token}"
122
+ end
123
+
124
+ def set_id_token(id_token)
125
+ @config.id_token = id_token
115
126
  end
116
127
 
117
128
  def get_token_set_from_callback(params)
@@ -182,7 +193,26 @@ module XeroRuby
182
193
  :client_key => @config.ssl_client_key
183
194
  }
184
195
 
185
- connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
196
+ case api_client
197
+ when "AccountingApi"
198
+ method_base_url = @config.accounting_url
199
+ when "AssetApi"
200
+ method_base_url = @config.asset_url
201
+ when "FilesApi"
202
+ method_base_url = @config.files_url
203
+ when "PayrollAuApi"
204
+ method_base_url = @config.payroll_au_url
205
+ when "PayrollNzApi"
206
+ method_base_url = @config.payroll_nz_url
207
+ when "PayrollUkApi"
208
+ method_base_url = @config.payroll_uk_url
209
+ when "ProjectApi"
210
+ method_base_url = @config.project_url
211
+ else
212
+ method_base_url = @config.accounting_url
213
+ end
214
+
215
+ connection = Faraday.new(:url => method_base_url, :ssl => ssl_options) do |conn|
186
216
  conn.basic_auth(config.username, config.password)
187
217
  if opts[:header_params]["Content-Type"] == "multipart/form-data"
188
218
  conn.request :multipart
@@ -265,7 +295,8 @@ module XeroRuby
265
295
  end
266
296
  end
267
297
  request.headers = header_params
268
- request.options.timeout = @config.timeout
298
+ timeout = @config.timeout
299
+ request.options.timeout = timeout if timeout > 0
269
300
  request.body = req_body
270
301
  request.url url
271
302
  request.params = query_params
@@ -60,8 +60,11 @@ module XeroRuby
60
60
  # @return [String]
61
61
  attr_accessor :password
62
62
 
63
- # Defines the access token (Bearer) used with OAuth2.
63
+ # Defines the access token (Bearer) used with OAuth2 authorization
64
64
  attr_accessor :access_token
65
+
66
+ # Defines OpenID Connect id_token containing Xero user authentication detail
67
+ attr_accessor :id_token
65
68
 
66
69
  # Defines the token set used with OAuth2. May include id/access/refresh token & other meta info.
67
70
  attr_accessor :token_set
@@ -146,6 +149,8 @@ module XeroRuby
146
149
  @payroll_au_url = 'https://api.xero.com/payroll.xro/1.0/'
147
150
  @payroll_nz_url = 'https://api.xero.com/payroll.xro/2.0/'
148
151
  @payroll_uk_url = 'https://api.xero.com/payroll.xro/2.0/'
152
+ @access_token = nil
153
+ @id_token = nil
149
154
  @api_key = {}
150
155
  @api_key_prefix = {}
151
156
  @timeout = 0
@@ -191,6 +196,14 @@ module XeroRuby
191
196
  def base_url=(api_url)
192
197
  @base_url = api_url
193
198
  end
199
+
200
+ def access_token=(access_token)
201
+ @access_token = access_token
202
+ end
203
+
204
+ def id_token=(id_token)
205
+ @id_token = id_token
206
+ end
194
207
 
195
208
  # Gets API key (with prefix if set).
196
209
  # @param [String] param_name the parameter name of API key auth
@@ -97,10 +97,6 @@ module XeroRuby::PayrollAu
97
97
  invalid_properties.push('invalid value for "deduction_type_id", deduction_type_id cannot be nil.')
98
98
  end
99
99
 
100
- if @calculation_type.nil?
101
- invalid_properties.push('invalid value for "calculation_type", calculation_type cannot be nil.')
102
- end
103
-
104
100
  invalid_properties
105
101
  end
106
102
 
@@ -108,7 +104,6 @@ module XeroRuby::PayrollAu
108
104
  # @return true if the model is valid
109
105
  def valid?
110
106
  return false if @deduction_type_id.nil?
111
- return false if @calculation_type.nil?
112
107
  true
113
108
  end
114
109
 
@@ -7,9 +7,9 @@ Contact: api@xero.com
7
7
  Generated by: https://openapi-generator.tech
8
8
  OpenAPI Generator version: 4.3.1
9
9
 
10
- The version of the XeroOpenAPI document: 2.10.4
10
+ The version of the XeroOpenAPI document: 2.10.5
11
11
  =end
12
12
 
13
13
  module XeroRuby
14
- VERSION = '2.9.0'
14
+ VERSION = '2.9.1'
15
15
  end
@@ -371,4 +371,85 @@ describe XeroRuby::ApiClient do
371
371
  expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
372
372
  end
373
373
  end
374
+
375
+ describe 'thread safety in the XeroClient' do
376
+ let(:creds) {{
377
+ client_id: 'abc',
378
+ client_secret: '123',
379
+ redirect_uri: 'https://mydomain.com/callback',
380
+ scopes: 'openid profile email accounting.transactions'
381
+ }}
382
+ let(:api_client_1) {XeroRuby::ApiClient.new(credentials: creds)}
383
+ let(:api_client_2) {XeroRuby::ApiClient.new(credentials: creds)}
384
+ let(:api_client_3) {XeroRuby::ApiClient.new(credentials: creds)}
385
+
386
+ let(:tkn_set_1){{id_token: "abc.123.1", access_token: "xxx.yyy.zzz.111"}}
387
+ let(:tkn_set_2){{id_token: "efg.456.2", access_token: "xxx.yyy.zzz.222"}}
388
+
389
+ describe 'when configuration is changed, other instantiations of the client are not affected' do
390
+ it 'applies to #set_access_token' do
391
+ expect(api_client_1.access_token).to eq(nil)
392
+ expect(api_client_2.access_token).to eq(nil)
393
+ expect(api_client_3.access_token).to eq(nil)
394
+
395
+ api_client_1.set_access_token("ACCESS_TOKEN_1")
396
+ expect(api_client_1.access_token).to eq("ACCESS_TOKEN_1")
397
+ expect(api_client_2.access_token).to eq(nil)
398
+ expect(api_client_3.access_token).to eq(nil)
399
+
400
+ api_client_2.set_access_token("ACCESS_TOKEN_2")
401
+ expect(api_client_1.access_token).to eq("ACCESS_TOKEN_1")
402
+ expect(api_client_2.access_token).to eq("ACCESS_TOKEN_2")
403
+ expect(api_client_3.access_token).to eq(nil)
404
+
405
+ api_client_3.set_access_token("ACCESS_TOKEN_3")
406
+ expect(api_client_1.access_token).to eq("ACCESS_TOKEN_1")
407
+ expect(api_client_2.access_token).to eq("ACCESS_TOKEN_2")
408
+ expect(api_client_3.access_token).to eq("ACCESS_TOKEN_3")
409
+ end
410
+
411
+ it 'applies to #set_id_token' do
412
+ expect(api_client_1.id_token).to eq(nil)
413
+ expect(api_client_2.id_token).to eq(nil)
414
+
415
+ api_client_1.set_id_token("id_token_1")
416
+ expect(api_client_1.id_token).to eq("id_token_1")
417
+ expect(api_client_2.id_token).to eq(nil)
418
+
419
+ api_client_2.set_id_token("id_token_2")
420
+ expect(api_client_1.id_token).to eq("id_token_1")
421
+ expect(api_client_2.id_token).to eq("id_token_2")
422
+ end
423
+
424
+ it 'applies to #set_token_set' do
425
+ expect(api_client_1.token_set).to eq(nil)
426
+ expect(api_client_2.token_set).to eq(nil)
427
+
428
+ api_client_1.set_token_set(tkn_set_1)
429
+ expect(api_client_1.token_set).to eq(tkn_set_1)
430
+ expect(api_client_2.token_set).to eq(nil)
431
+
432
+ api_client_2.set_token_set(tkn_set_2)
433
+ expect(api_client_1.token_set).to eq(tkn_set_1)
434
+ expect(api_client_2.token_set).to eq(tkn_set_2)
435
+ end
436
+
437
+ it 'applies to #base_url' do
438
+ expect(api_client_1.config.base_url).to eq(nil)
439
+ expect(api_client_2.config.base_url).to eq(nil)
440
+
441
+ api_client_1.accounting_api
442
+ expect(api_client_1.config.base_url).to eq(api_client_1.config.accounting_url)
443
+ expect(api_client_2.config.base_url).to eq(nil)
444
+
445
+ api_client_2.files_api
446
+ expect(api_client_1.config.base_url).to eq(api_client_1.config.accounting_url)
447
+ expect(api_client_2.config.base_url).to eq(api_client_1.config.files_url)
448
+
449
+ api_client_2.project_api
450
+ expect(api_client_1.config.base_url).to eq(api_client_1.config.accounting_url)
451
+ expect(api_client_2.config.base_url).to eq(api_client_1.config.project_url)
452
+ end
453
+ end
454
+ end
374
455
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xero-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xero API Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday