zuora_connect 1.5.13 → 1.5.14
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73f9738a5746908f0cbf6db3bd327b69980e0f6
|
4
|
+
data.tar.gz: 8abe423e467c692445c180a108def67225ebf21e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c491398a80320a9ed09625b0f0809642ed2c9898c24e8c890858103849cb6b131ba55e746e8f35bcdeba0c89c302cd531ae49348b7d784ac5ea30b2e24e22c9b
|
7
|
+
data.tar.gz: 1457f3288b2ebd62ab6675b211b89006a3e79cde2323da9fde9b1bc9cd5851a2ec3b90a1bbaef183c57189e46a14b8c5c11c966ca6e3f442fc9c2bc1a40224dc
|
@@ -8,6 +8,7 @@ module ZuoraConnect
|
|
8
8
|
def init
|
9
9
|
@options = Hash.new
|
10
10
|
@logins = Hash.new
|
11
|
+
@api_version = "v2"
|
11
12
|
self.attr_builder("timezone", ZuoraConnect.configuration.default_time_zone)
|
12
13
|
self.attr_builder("locale", ZuoraConnect.configuration.default_locale)
|
13
14
|
PaperTrail.whodunnit = "Backend" if defined?(PaperTrail)
|
@@ -396,6 +397,8 @@ module ZuoraConnect
|
|
396
397
|
|
397
398
|
def updateOption(optionId, value)
|
398
399
|
if self.access_token && self.refresh_token
|
400
|
+
#Refresh token if already expired
|
401
|
+
self.refresh_oauth if self.oauth_expired?
|
399
402
|
return HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/application_options/#{optionId}/edit?value=#{value}",:body => {:access_token => self.username})
|
400
403
|
else
|
401
404
|
return false
|
@@ -408,6 +411,9 @@ module ZuoraConnect
|
|
408
411
|
#This can add a new login
|
409
412
|
#This can change to another existing login
|
410
413
|
def update_logins(options)
|
414
|
+
#Refresh token if already expired
|
415
|
+
self.refresh_oauth if self.oauth_expired?
|
416
|
+
|
411
417
|
count ||= 0
|
412
418
|
response = HTTParty.post(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}/logins",:body => {:access_token => self.username}.merge(options))
|
413
419
|
if response.code == 200
|
@@ -416,15 +422,16 @@ module ZuoraConnect
|
|
416
422
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
417
423
|
end
|
418
424
|
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError
|
419
|
-
if (count += 1) <
|
425
|
+
if (count += 1) < 3
|
420
426
|
retry
|
421
427
|
else
|
422
428
|
raise
|
423
429
|
end
|
424
430
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
425
|
-
if count
|
426
|
-
|
427
|
-
|
431
|
+
if (count += 1) < 3
|
432
|
+
if ex.code == 401
|
433
|
+
self.refresh_oauth
|
434
|
+
end
|
428
435
|
retry
|
429
436
|
else
|
430
437
|
raise
|
@@ -432,8 +439,12 @@ module ZuoraConnect
|
|
432
439
|
end
|
433
440
|
|
434
441
|
def refresh(session = nil)
|
442
|
+
#Refresh token if already expired
|
443
|
+
self.refresh_oauth if self.oauth_expired?
|
444
|
+
|
435
445
|
count ||= 0
|
436
446
|
start = Time.now
|
447
|
+
Rails.logger.info("[#{self.id}] REFRESHING - Get Task Info")
|
437
448
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
438
449
|
response_time = Time.now - start
|
439
450
|
|
@@ -445,16 +456,16 @@ module ZuoraConnect
|
|
445
456
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
446
457
|
end
|
447
458
|
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError
|
448
|
-
if count <
|
449
|
-
count += 1
|
459
|
+
if (count += 1) < 3
|
450
460
|
retry
|
451
461
|
else
|
452
462
|
raise
|
453
463
|
end
|
454
464
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
455
|
-
if count
|
456
|
-
|
457
|
-
|
465
|
+
if (count += 1) < 3
|
466
|
+
if ex.code == 401
|
467
|
+
self.refresh_oauth
|
468
|
+
end
|
458
469
|
retry
|
459
470
|
else
|
460
471
|
raise
|
@@ -533,9 +544,9 @@ module ZuoraConnect
|
|
533
544
|
response_time = Time.now - start
|
534
545
|
Rails.logger.info("[#{self.id}] REFRESHING - OAuth in #{response_time.round(2).to_s}")
|
535
546
|
|
536
|
-
response_body = JSON.parse(response.body)
|
537
|
-
|
538
547
|
if response.code == 200
|
548
|
+
response_body = JSON.parse(response.body)
|
549
|
+
|
539
550
|
self.refresh_token = response_body["refresh_token"]
|
540
551
|
self.access_token = response_body["access_token"]
|
541
552
|
self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
|
@@ -546,18 +557,16 @@ module ZuoraConnect
|
|
546
557
|
end
|
547
558
|
|
548
559
|
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => ex
|
549
|
-
if count <
|
550
|
-
count += 1
|
560
|
+
if (count += 1) < 3
|
551
561
|
retry
|
552
562
|
else
|
553
563
|
raise
|
554
564
|
end
|
555
565
|
rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
|
556
|
-
if count < 3
|
566
|
+
if (count += 1) < 3
|
557
567
|
Rails.logger.info("REFRESHING - OAuth Failed - Retrying(#{count})")
|
558
568
|
self.reload
|
559
569
|
sleep(5)
|
560
|
-
count += 1
|
561
570
|
retry
|
562
571
|
else
|
563
572
|
Rails.logger.fatal("REFRESHING - OAuth Failed")
|
@@ -566,7 +575,7 @@ module ZuoraConnect
|
|
566
575
|
end
|
567
576
|
|
568
577
|
def oauth_expired?
|
569
|
-
(
|
578
|
+
(self.oauth_expires_at < Time.now)
|
570
579
|
end
|
571
580
|
|
572
581
|
def attr_builder(field,val)
|
@@ -5,16 +5,18 @@ module ZuoraConnect
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
def authenticate_app_api_request
|
8
|
+
#Skip session for api requests
|
9
|
+
request.session_options[:skip] = true
|
8
10
|
start_time = Time.now
|
9
11
|
if !request.headers["API-Token"].blank?
|
10
12
|
@appinstance = ZuoraConnect::AppInstance.where(:api_token => request.headers["API-Token"]).first
|
11
|
-
Rails.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if
|
13
|
+
Rails.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if @appinstance.present?
|
12
14
|
check_instance
|
13
15
|
else
|
14
16
|
authenticate_or_request_with_http_basic do |username, password|
|
15
17
|
@appinstance = ZuoraConnect::AppInstance.where(:token => password).first
|
16
18
|
@appinstance ||= ZuoraConnect::AppInstance.where(:api_token => password).first
|
17
|
-
Rails.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if
|
19
|
+
Rails.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if @appinstance.present?
|
18
20
|
check_instance
|
19
21
|
end
|
20
22
|
end
|
@@ -65,7 +67,7 @@ module ZuoraConnect
|
|
65
67
|
|
66
68
|
private
|
67
69
|
def setup_instance_via_data
|
68
|
-
|
70
|
+
session.clear
|
69
71
|
values = JSON.parse(ZuoraConnect::AppInstance.decrypt_response(Base64.urlsafe_decode64(request["data"])))
|
70
72
|
Rails.logger.debug("Data: #{values.to_json}")
|
71
73
|
if values["param_data"]
|
@@ -98,7 +100,7 @@ module ZuoraConnect
|
|
98
100
|
end
|
99
101
|
|
100
102
|
def setup_instance_via_session
|
101
|
-
if
|
103
|
+
if session["appInstance"].present?
|
102
104
|
@appinstance = ZuoraConnect::AppInstance.where(:id => session["appInstance"]).first
|
103
105
|
else
|
104
106
|
raise ZuoraConnect::Exceptions::SessionInvalid.new("Session Blank -- Relaunch Application")
|
@@ -125,7 +127,7 @@ module ZuoraConnect
|
|
125
127
|
|
126
128
|
#API ONLY
|
127
129
|
def check_instance
|
128
|
-
if
|
130
|
+
if @appinstance.present?
|
129
131
|
@appinstance.new_session(:session => @appinstance.data_lookup(:session => session))
|
130
132
|
Thread.current[:appinstance] = @appinstance
|
131
133
|
PaperTrail.whodunnit = "API User" if defined?(PaperTrail)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|