zuora_api 1.8.1 → 1.9.0

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.1"
2
+ VERSION = "1.9.0"
3
3
  end
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.1
4
+ version: 1.9.0
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-11-10 00:00:00.000000000 Z
11
+ date: 2021-04-06 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
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: webmock
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,34 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-cobertura
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ougai
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: nokogiri
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -131,7 +173,7 @@ dependencies:
131
173
  version: 4.1.0
132
174
  - - "<"
133
175
  - !ruby/object:Gem::Version
134
- version: '6'
176
+ version: '6.2'
135
177
  type: :runtime
136
178
  prerelease: false
137
179
  version_requirements: !ruby/object:Gem::Requirement
@@ -141,7 +183,7 @@ dependencies:
141
183
  version: 4.1.0
142
184
  - - "<"
143
185
  - !ruby/object:Gem::Version
144
- version: '6'
186
+ version: '6.2'
145
187
  description: Gem that provides easy integration to Zuora
146
188
  email:
147
189
  - connect@zuora.com
@@ -149,17 +191,9 @@ executables: []
149
191
  extensions: []
150
192
  extra_rdoc_files: []
151
193
  files:
152
- - ".gitignore"
153
- - ".gitlab-ci.yml"
154
- - ".rspec"
155
- - ".travis.yml"
156
- - CHANGELOG.md
157
- - Gemfile
158
- - Gemfile.lock
194
+ - MIT-LICENSE
159
195
  - README.md
160
196
  - Rakefile
161
- - bin/console
162
- - bin/setup
163
197
  - lib/insights_api/login.rb
164
198
  - lib/zuora_api.rb
165
199
  - lib/zuora_api/exceptions.rb
@@ -167,7 +201,6 @@ files:
167
201
  - lib/zuora_api/logins/basic.rb
168
202
  - lib/zuora_api/logins/oauth.rb
169
203
  - lib/zuora_api/version.rb
170
- - zuora_api.gemspec
171
204
  homepage: https://connect.zuora.com
172
205
  licenses: []
173
206
  metadata: {}
@@ -186,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
219
  - !ruby/object:Gem::Version
187
220
  version: '0'
188
221
  requirements: []
189
- rubygems_version: 3.0.3
222
+ rubygems_version: 3.2.15
190
223
  signing_key:
191
224
  specification_version: 4
192
225
  summary: Gem that provides easy integration to Zuora
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- .idea
data/.gitlab-ci.yml DELETED
@@ -1,63 +0,0 @@
1
- image: ruby:2.6
2
- stages:
3
- - setup
4
- - test
5
- - deploy
6
-
7
- setup:
8
- stage: setup
9
- allow_failure: true
10
- cache:
11
- key: gems
12
- paths:
13
- - vendor/bundle
14
- script:
15
- - apt-get update -qy
16
- - apt-get install -y nodejs
17
- - bundle install
18
-
19
- rubocop-testing:
20
- stage: test
21
- allow_failure: true
22
- script:
23
- - gem install rubocop
24
- - rubocop --lint
25
-
26
- security-testing:
27
- stage: test
28
- allow_failure: true
29
- script:
30
- - gem install brakeman
31
- - brakeman
32
-
33
- rspec-testing:
34
- stage: test
35
- script:
36
- - bundle install
37
- - rspec
38
-
39
- rubygems-deploy:
40
- stage: deploy
41
- allow_failure: false
42
- script:
43
- - echo "deb http://ftp.us.debian.org/debian testing main contrib non-free" >> /etc/apt/sources.list
44
- - apt-get update
45
- - apt-get install -y git
46
- - apt-get clean all
47
- - gem install dpl
48
- - if [[ "staging" == $CI_BUILD_REF_SLUG ]];then export VERSION=`git describe --match "[0-9]*\.[0-9]*\.[0-9]*[a-z]" --abbrev=0 --tags HEAD`; fi
49
- - if [[ "master" == $CI_BUILD_REF_SLUG ]];then export VERSION=`git describe --exclude "[0-9]*\.[0-9]*\.[0-9]*[a-z]" --abbrev=0 --tags HEAD`; fi
50
- - echo $VERSION
51
- - sed -i "s/0.0.1/$VERSION/" lib/zuora_api/version.rb
52
- - git add lib/zuora_api/version.rb
53
- - git config --global user.email "connect@zuora.com"
54
- - git config --global user.name "Connect Automation"
55
- - git commit -m "Automated Version Update $VERSION"
56
- - bundle install
57
- - gem install rake
58
- - version=$(rake install | grep -o 'pkg/zuora_api-.*gem')
59
- - curl -u $USERNAME:$PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
60
- - gem push $version
61
- only:
62
- - master
63
- - staging