zuora_api 1.7.7 → 1.7.08
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/.gitignore +0 -1
- data/.gitlab-ci.yml +2 -2
- data/Gemfile.lock +29 -29
- data/README.md +1 -1
- data/lib/insights_api/login.rb +6 -5
- data/lib/zuora_api/exceptions.rb +28 -103
- data/lib/zuora_api/login.rb +325 -595
- data/lib/zuora_api/logins/basic.rb +5 -14
- data/lib/zuora_api/logins/oauth.rb +32 -54
- data/lib/zuora_api/version.rb +1 -1
- metadata +2 -2
@@ -9,7 +9,7 @@ module ZuoraAPI
|
|
9
9
|
super
|
10
10
|
end
|
11
11
|
|
12
|
-
def new_session(auth_type: :basic, debug: false
|
12
|
+
def new_session(auth_type: :basic, debug: false)
|
13
13
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic
|
14
14
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Basic Login but either 'Username' or 'Password' were not passed.") if (self.password.blank? && self.username.blank?)
|
15
15
|
|
@@ -30,11 +30,8 @@ module ZuoraAPI
|
|
30
30
|
input_xml = Nokogiri::XML(request.to_xml(:save_with => XML_SAVE_OPTIONS).strip)
|
31
31
|
input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
|
32
32
|
Rails.logger.debug('Connect') {"SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
33
|
-
|
34
|
-
|
35
|
-
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
36
|
-
|
37
|
-
response_query = HTTParty.post(self.url,:body => request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => headers, :timeout => 10)
|
33
|
+
|
34
|
+
response_query = HTTParty.post(self.url,:body => request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => 10)
|
38
35
|
output_xml = Nokogiri::XML(response_query.body)
|
39
36
|
Rails.logger.debug('Connect') {"Response Code: #{response_query.code} SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
40
37
|
|
@@ -98,17 +95,11 @@ module ZuoraAPI
|
|
98
95
|
end
|
99
96
|
return self.status
|
100
97
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
101
|
-
if !tries.zero?
|
102
|
-
|
98
|
+
if !(tries -= 1).zero?
|
99
|
+
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
103
100
|
sleep(self.timeout_sleep)
|
104
101
|
retry
|
105
102
|
else
|
106
|
-
if Rails.logger.class.to_s == "Ougai::Logger"
|
107
|
-
Rails.logger.error("BasicLogin - Timed out", ex)
|
108
|
-
else
|
109
|
-
Rails.logger.error("BasicLogin - #{ex.class} Timed out")
|
110
|
-
end
|
111
|
-
|
112
103
|
self.current_error = "Request timed out. Try again"
|
113
104
|
self.status = 'Timeout'
|
114
105
|
return self.status
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ZuoraAPI
|
2
2
|
class Oauth < Login
|
3
|
-
attr_accessor :oauth_client_id, :oauth_secret, :bearer_token, :oauth_session_expires_at
|
3
|
+
attr_accessor :oauth_client_id, :oauth_secret, :bearer_token, :oauth_session_expires_at
|
4
4
|
|
5
5
|
def initialize(oauth_client_id: nil, oauth_secret: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
|
6
6
|
self.oauth_client_id = oauth_client_id
|
@@ -11,15 +11,15 @@ module ZuoraAPI
|
|
11
11
|
super
|
12
12
|
end
|
13
13
|
|
14
|
-
def new_session(
|
14
|
+
def new_session(raise_errors: false, auth_type: nil)
|
15
15
|
if auth_type == :bearer
|
16
|
-
get_bearer_token(
|
16
|
+
get_bearer_token()
|
17
17
|
elsif auth_type == :basic
|
18
|
-
get_bearer_token(
|
19
|
-
get_z_session(
|
18
|
+
get_bearer_token() if self.oauth_expired?
|
19
|
+
get_z_session() if self.status == 'Active'
|
20
20
|
else
|
21
|
-
get_bearer_token(
|
22
|
-
get_z_session(
|
21
|
+
get_bearer_token()
|
22
|
+
get_z_session() if self.status == 'Active'
|
23
23
|
end
|
24
24
|
return self.status
|
25
25
|
end
|
@@ -29,83 +29,66 @@ module ZuoraAPI
|
|
29
29
|
return self.bearer_token
|
30
30
|
end
|
31
31
|
|
32
|
-
def get_z_session(debug: false
|
32
|
+
def get_z_session(debug: false)
|
33
33
|
tries ||= 2
|
34
|
-
headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id } : {}
|
35
|
-
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
34
|
+
headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id } : {}
|
36
35
|
output_json, response = self.rest_call(:url => self.rest_endpoint("connections"), :session_type => :bearer, :headers => headers)
|
37
|
-
|
38
|
-
self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
|
39
|
-
rescue NoMethodError => ex
|
40
|
-
Rails.logger.fatal("Failure Parsing Cookie Headers", response.headers.to_s)
|
41
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Failure Parsing Cookie Headers")
|
42
|
-
end
|
36
|
+
self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
|
43
37
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
44
|
-
if !tries.zero?
|
45
|
-
tries -= 1
|
38
|
+
if !(tries -= 1).zero?
|
46
39
|
Rails.logger.debug {"Session Invalid"}
|
47
40
|
self.new_session(auth_type: :bearer)
|
48
41
|
retry
|
42
|
+
else
|
43
|
+
if errors.include?(ex.class)
|
44
|
+
raise ex
|
45
|
+
else
|
46
|
+
return [output_json, response]
|
47
|
+
end
|
49
48
|
end
|
50
|
-
raise ex if errors.include?(ex.class)
|
51
|
-
return [output_json, response]
|
52
|
-
|
53
49
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
if errors.include?(ex.class)
|
51
|
+
raise ex
|
52
|
+
else
|
53
|
+
return [output_json, response]
|
54
|
+
end
|
57
55
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
58
|
-
if !tries.zero?
|
59
|
-
|
56
|
+
if !(tries -= 1).zero?
|
57
|
+
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
60
58
|
sleep(self.timeout_sleep)
|
61
59
|
retry
|
62
|
-
end
|
63
|
-
if Rails.logger.class.to_s == "Ougai::Logger"
|
64
|
-
Rails.logger.error("OAuthLogin - Timed out", ex)
|
65
60
|
else
|
66
|
-
|
61
|
+
self.current_error = "Request timed out. Try again"
|
62
|
+
self.status = 'Timeout'
|
63
|
+
return self.status
|
67
64
|
end
|
68
|
-
self.current_error = "Request timed out. Try again"
|
69
|
-
self.status = 'Timeout'
|
70
|
-
return self.status
|
71
65
|
end
|
72
66
|
|
73
|
-
def get_bearer_token
|
67
|
+
def get_bearer_token
|
74
68
|
tries ||= 2
|
75
69
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Oauth Login but either 'Oauth Client Id' or 'Oauth Secret' were not passed") if self.oauth_client_id.blank? || self.oauth_secret.blank?
|
76
70
|
|
77
|
-
headers = { "content-type" => "application/x-www-form-urlencoded" }
|
78
|
-
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
79
|
-
|
80
71
|
output_json, response = self.rest_call(:method => :post,
|
81
72
|
:url => self.rest_endpoint.chomp('v1/').concat("oauth/token"),
|
82
73
|
:z_session => false,
|
83
74
|
:session_type => :bearer,
|
84
|
-
:headers =>
|
75
|
+
:headers => {"content-type" => "application/x-www-form-urlencoded"},
|
85
76
|
:body => {"client_id"=> self.oauth_client_id, "client_secret"=>self.oauth_secret, "grant_type" =>"client_credentials"}
|
86
77
|
)
|
87
78
|
|
88
79
|
self.bearer_token = output_json["access_token"]
|
89
|
-
self.scope_entities = output_json.fetch('scope', '').split(" ").map { |scope| scope.split('.').last.gsub('-', '') if scope.include?('entity.') }.compact.uniq
|
90
80
|
self.oauth_session_expires_at = Time.now.to_i + output_json["expires_in"].to_i
|
91
81
|
self.current_error = nil
|
92
82
|
self.status = 'Active'
|
93
83
|
|
94
84
|
return self.status
|
95
|
-
|
96
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPIInternalServerError => ex
|
97
|
-
raise ex if tries.zero?
|
98
|
-
|
99
|
-
tries -= 1
|
100
|
-
sleep(self.timeout_sleep)
|
101
|
-
retry
|
102
85
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
103
86
|
self.bearer_token = nil
|
104
87
|
self.oauth_session_expires_at = nil
|
105
88
|
self.current_error = ex.message
|
106
89
|
case ex.message
|
107
90
|
when "Forbidden"
|
108
|
-
self.current_error = "The user associated to OAuth credential set has been deactivated."
|
91
|
+
self.current_error = "The user associated to OAuth credential, '#{self.oauth_client_id}', set has been deactivated."
|
109
92
|
self.status = 'Deactivated'
|
110
93
|
else
|
111
94
|
self.current_error = "Invalid login, please check client ID and Client Secret or URL endpoint"
|
@@ -116,16 +99,11 @@ module ZuoraAPI
|
|
116
99
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
117
100
|
raise ex
|
118
101
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
119
|
-
if !tries.zero?
|
120
|
-
|
102
|
+
if !(tries -= 1).zero?
|
103
|
+
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
121
104
|
sleep(self.timeout_sleep)
|
122
105
|
retry
|
123
106
|
else
|
124
|
-
if Rails.logger.class.to_s == "Ougai::Logger"
|
125
|
-
Rails.logger.error("OAuthLogin - Timed out will retry after #{self.timeout_sleep} seconds", ex)
|
126
|
-
else
|
127
|
-
Rails.logger.error("OAuthLogin - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
|
128
|
-
end
|
129
107
|
self.current_error = "Invalid login, please check client ID and Client Secret or URL endpoint"
|
130
108
|
self.status = 'Timeout'
|
131
109
|
return self.status
|
data/lib/zuora_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.08
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zuora Strategic Solutions Group
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|