zuora_api 1.8.2 → 1.8.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,113 +10,22 @@ module ZuoraAPI
10
10
  end
11
11
 
12
12
  def new_session(auth_type: :basic, debug: false, zuora_track_id: nil)
13
- raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic
14
- raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Basic Login but either 'Username' or 'Password' were not passed.") if (self.password.blank? && self.username.blank?)
13
+ super do
14
+ raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic
15
+ raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Basic Login but either 'Username' or 'Password' were not passed.") if (self.password.blank? && self.username.blank?)
15
16
 
16
- tries ||= 2
17
- request = Nokogiri::XML::Builder.new do |xml|
18
- xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' =>"http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:api' => "http://api.zuora.com/" ) do
19
- xml['SOAP-ENV'].Header
20
- xml['SOAP-ENV'].Body do
21
- xml['api'].login do
22
- xml['api'].username self.username
23
- xml['api'].password self.password
24
- xml['api'].entityId self.entity_id if !self.entity_id.blank?
25
- end
17
+ output_xml, input_xml, response = soap_call(timeout_retry: true, skip_session: true, zuora_track_id: zuora_track_id) do |xml|
18
+ xml['api'].login do
19
+ xml['api'].username self.username
20
+ xml['api'].password self.password
21
+ xml['api'].entityId self.entity_id if !self.entity_id.blank?
26
22
  end
27
23
  end
28
- end
29
-
30
- input_xml = Nokogiri::XML(request.to_xml(:save_with => XML_SAVE_OPTIONS).strip)
31
- input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
32
- Rails.logger.debug('Connect') {"SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
33
-
34
- headers = { 'Content-Type' => "text/xml; charset=utf-8" }
35
- headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
36
24
 
37
- response_query = HTTParty.post(self.url,:body => request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => headers, :timeout => 10)
38
- output_xml = Nokogiri::XML(response_query.body)
39
- Rails.logger.debug('Connect') {"Response Code: #{response_query.code} SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
40
-
41
- if !response_query.success?
42
- self.current_session = nil
43
- if output_xml.namespaces.size > 0 && output_xml.xpath('//soapenv:Fault').size > 0
44
- self.current_error = output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text
45
- if self.current_error.include?('deactivated')
46
- self.status = 'Deactivated'
47
- self.current_error = 'Deactivated user login, please check with Zuora tenant administrator'
48
- self.errors[:username] = self.current_error
49
- elsif self.current_error.include?('inactive')
50
- self.status = 'Inactive'
51
- self.current_error = 'Inactive user login, please check with Zuora tenant administrator'
52
- self.errors[:username] = self.current_error
53
- elsif self.current_error.include?("invalid username or password") || self.current_error.include?("Invalid login. User name and password do not match.")
54
- self.status = 'Invalid Login'
55
- self.current_error = 'Invalid login, please check username and password or URL endpoint'
56
- self.errors[:username] = self.current_error
57
- self.errors[:password] = self.current_error
58
- elsif self.current_error.include?('unsupported version')
59
- self.status = 'Unsupported API Version'
60
- self.current_error = 'Unsupported API version, please verify URL endpoint'
61
- self.errors[:url] = self.current_error
62
- elsif self.current_error.include?('invalid api version')
63
- self.status = 'Invalid API Version'
64
- self.current_error = 'Invalid API version, please verify URL endpoint'
65
- self.errors[:url] = self.current_error
66
- elsif self.current_error.include?('invalid session')
67
- self.status = 'Invalid Session'
68
- self.current_error = 'Session invalid, please update session and verify URL endpoint'
69
- self.errors[:session] = self.current_error
70
- elsif self.current_error.include?('Your IP address')
71
- self.status = 'Restricted IP'
72
- self.current_error = 'IP restricted, contact Zuora tenant administrator and remove IP restriction'
73
- self.errors[:base] = self.current_error
74
- elsif self.current_error.include?('This account has been locked')
75
- self.status = 'Locked'
76
- self.current_error = 'Locked user login, please wait or navigate to Zuora to unlock user'
77
- self.errors[:username] = self.current_error
78
- elsif self.current_error.include?('Entity not exist:')
79
- self.status = 'Entity Missing'
80
- self.errors[:base] = self.current_error
81
- else
82
- self.status = 'Unknown'
83
- self.current_error = output_xml.xpath('//faultstring').text if self.current_error.blank?
84
- self.errors[:base] = self.current_error
85
- end
86
-
87
- else
88
- self.status = 'Unknown'
89
- self.current_error = output_xml.xpath('//faultstring').text if self.current_error.blank?
90
- self.errors[:base] = self.current_error
91
- end
92
- else
93
- #Username & password combo
94
25
  retrieved_session = output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text
95
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("No session found for api call.", response_query) if retrieved_session.blank?
96
- self.status = 'Active'
26
+ raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("No session found for api call.", response) if retrieved_session.blank?
97
27
  self.current_session = retrieved_session
98
- end
99
- return self.status
100
- rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
101
- if !tries.zero?
102
- tries -= 1
103
- sleep(self.timeout_sleep)
104
- retry
105
- 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
- self.current_error = "Request timed out. Try again"
113
- self.status = 'Timeout'
114
- return self.status
115
- end
116
- rescue EOFError
117
- if self.url.match?(/.*services\d{1,}.zuora.com*/)
118
- self.current_error = "Services tenant '#{self.url.scan(/.*\/\/(services\d{1,}).zuora.com*/).last.first}' is no longer available."
119
- self.status = 'Not Available'
28
+ self.status = 'Active'
120
29
  return self.status
121
30
  end
122
31
  end
@@ -12,16 +12,18 @@ module ZuoraAPI
12
12
  end
13
13
 
14
14
  def new_session(auth_type: nil, zuora_track_id: nil)
15
- if auth_type == :bearer
16
- get_bearer_token(zuora_track_id: zuora_track_id)
17
- elsif auth_type == :basic
18
- get_bearer_token(zuora_track_id: zuora_track_id) if self.oauth_expired?
19
- get_z_session(zuora_track_id: zuora_track_id) if self.status == 'Active'
20
- else
21
- get_bearer_token(zuora_track_id: zuora_track_id)
22
- get_z_session(zuora_track_id: zuora_track_id) if self.status == 'Active'
15
+ super do
16
+ if auth_type == :bearer
17
+ get_bearer_token(zuora_track_id: zuora_track_id)
18
+ elsif auth_type == :basic
19
+ get_bearer_token(zuora_track_id: zuora_track_id) if self.oauth_expired?
20
+ get_z_session(zuora_track_id: zuora_track_id)
21
+ else
22
+ get_bearer_token(zuora_track_id: zuora_track_id) if self.oauth_expired?
23
+ get_z_session(zuora_track_id: zuora_track_id)
24
+ end
25
+ return self.status
23
26
  end
24
- return self.status
25
27
  end
26
28
 
27
29
  def get_active_bearer_token
@@ -30,59 +32,35 @@ module ZuoraAPI
30
32
  end
31
33
 
32
34
  def get_z_session(debug: false, zuora_track_id: nil)
33
- tries ||= 2
34
35
  headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id } : {}
35
36
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
36
37
  output_json, response = self.rest_call(:url => self.rest_endpoint("connections"), :session_type => :bearer, :headers => headers)
37
38
  begin
38
39
  self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
39
40
  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")
41
+ Rails.logger.fatal("Failure Parsing Cookie Headers", {
42
+ response: {
43
+ status: response.code,
44
+ params: response.body.to_s,
45
+ headers: response.headers.to_s,
46
+ }
47
+ })
48
+ raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("Failure Parsing Cookie Headers", response)
42
49
  end
43
- rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
44
- if !tries.zero?
45
- tries -= 1
46
- Rails.logger.debug {"Session Invalid"}
47
- self.new_session(auth_type: :bearer)
48
- retry
49
- end
50
- raise ex if errors.include?(ex.class)
51
- return [output_json, response]
52
-
53
- rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
54
- raise ex if errors.include?(ex.class)
55
- return [output_json, response]
56
-
57
- rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
58
- if !tries.zero?
59
- tries -= 1
60
- sleep(self.timeout_sleep)
61
- retry
62
- end
63
- if Rails.logger.class.to_s == "Ougai::Logger"
64
- Rails.logger.error("OAuthLogin - Timed out", ex)
65
- else
66
- Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
67
- end
68
- self.current_error = "Request timed out. Try again"
69
- self.status = 'Timeout'
70
- return self.status
71
50
  end
72
51
 
73
52
  def get_bearer_token(zuora_track_id: nil)
74
- tries ||= 2
75
53
  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
54
 
77
55
  headers = { "content-type" => "application/x-www-form-urlencoded" }
78
56
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
79
57
 
80
58
  output_json, response = self.rest_call(:method => :post,
81
- :url => self.rest_endpoint.chomp('v1/').concat("oauth/token"),
82
- :z_session => false,
83
- :session_type => :bearer,
84
- :headers => headers,
85
- :body => {"client_id"=> self.oauth_client_id, "client_secret"=>self.oauth_secret, "grant_type" =>"client_credentials"}
59
+ url: self.rest_endpoint.chomp('v1/').concat("oauth/token"),
60
+ z_session: false,
61
+ timeout_retry: true,
62
+ headers: headers,
63
+ body: {"client_id"=> self.oauth_client_id, "client_secret"=>self.oauth_secret, "grant_type" =>"client_credentials"}
86
64
  )
87
65
 
88
66
  self.bearer_token = output_json["access_token"]
@@ -92,44 +70,6 @@ module ZuoraAPI
92
70
  self.status = 'Active'
93
71
 
94
72
  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
- rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
103
- self.bearer_token = nil
104
- self.oauth_session_expires_at = nil
105
- self.current_error = ex.message
106
- case ex.message
107
- when "Forbidden"
108
- self.current_error = "The user associated to OAuth credential set has been deactivated."
109
- self.status = 'Deactivated'
110
- else
111
- self.current_error = "Invalid login, please check client ID and Client Secret or URL endpoint"
112
- self.status = 'Invalid Login'
113
- end
114
-
115
- return self.status
116
- rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
117
- raise ex
118
- rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
119
- if !tries.zero?
120
- tries -= 1
121
- sleep(self.timeout_sleep)
122
- retry
123
- 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
- self.current_error = "Invalid login, please check client ID and Client Secret or URL endpoint"
130
- self.status = 'Timeout'
131
- return self.status
132
- end
133
73
  end
134
74
 
135
75
  def oauth_expired?
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.8.2"
2
+ VERSION = "1.8.21"
3
3
  end
@@ -18,11 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
  spec.add_development_dependency("webmock")
25
- spec.add_development_dependency("simplecov")
25
+ spec.add_development_dependency("simplecov", "~> 0.18.5")
26
+ spec.add_dependency("ougai")
26
27
  spec.add_dependency("nokogiri")
27
28
  spec.add_dependency("httparty")
28
29
  spec.add_dependency("rubyzip")
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.21
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: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,12 +68,26 @@ dependencies:
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.18.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: ougai
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
- type: :development
90
+ type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
@@ -160,6 +174,8 @@ files:
160
174
  - Rakefile
161
175
  - bin/console
162
176
  - bin/setup
177
+ - catalog-info.yaml
178
+ - docs/index.md
163
179
  - gemfiles/Gemfile-rails.5.0.x
164
180
  - gemfiles/Gemfile-rails.5.1.x
165
181
  - gemfiles/Gemfile-rails.5.2.x
@@ -190,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
206
  - !ruby/object:Gem::Version
191
207
  version: '0'
192
208
  requirements: []
193
- rubygems_version: 3.0.3
209
+ rubygems_version: 3.1.4
194
210
  signing_key:
195
211
  specification_version: 4
196
212
  summary: Gem that provides easy integration to Zuora