zuora_api_oauth_alpha 2 → 2.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23681ed767d2a4792cfbdc8dcd90e7d321a2da72fc1ed0a0b70afde2b9a28a0a
|
4
|
+
data.tar.gz: 67e56da78688019331fada20da226aa067a749282b849ef989d78c23cd298d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 051ad8ae8af0e74a761d1b5e20d57c913403d6826f23e1c52b3c9e5b161eb7ca9d71c111ee8ef6dc539adba56b6224f1311bb708be01aa853e13c8b342b42995
|
7
|
+
data.tar.gz: 02239767a1f473ea139a131efa932e102626597d74396725fec172f25d22c5cbf8b87431d404c6b0fe6c35c5e3d026a6122c9949beb5780ffe99de6cb951a2cf
|
@@ -6,8 +6,10 @@ module ZuoraAPI
|
|
6
6
|
attr_reader :code, :response
|
7
7
|
attr_writer :default_message
|
8
8
|
|
9
|
-
def initialize(message = nil)
|
9
|
+
def initialize(message = nil,response=nil, code =nil)
|
10
|
+
@code = code
|
10
11
|
@message = message
|
12
|
+
@response = response
|
11
13
|
@default_message = "Error with Zuora Session."
|
12
14
|
end
|
13
15
|
|
@@ -97,8 +97,11 @@ module ZuoraAPI
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def get_session(prefix = false, auth_type = :basic)
|
100
|
-
Rails.logger.debug("
|
101
|
-
|
100
|
+
Rails.logger.debug("Checking for a cached session")
|
101
|
+
if self.check_session(auth_type) || self.current_session.nil?
|
102
|
+
self.current_session = self.new_session(auth_type)
|
103
|
+
end
|
104
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new(self.current_error) if self.status == 'AuthenticationError'
|
102
105
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if self.status != 'Active'
|
103
106
|
return self.authentication_prefix(auth_type) + self.current_session.to_s if prefix
|
104
107
|
return self.current_session.to_s
|
@@ -180,74 +183,95 @@ module ZuoraAPI
|
|
180
183
|
error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
|
181
184
|
message = body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text
|
182
185
|
|
186
|
+
if error.blank? || message.blank?
|
187
|
+
error = body.xpath('//faultcode').text
|
188
|
+
message = body.xpath('//faultstring').text
|
189
|
+
end
|
190
|
+
|
183
191
|
if error.blank? || message.blank?
|
184
192
|
error = body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text
|
185
193
|
message = body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text
|
186
194
|
end
|
187
|
-
|
188
|
-
|
189
|
-
|
195
|
+
|
196
|
+
#Update/Create/Delete Calls with multiple requests and responses
|
197
|
+
if body.xpath('//ns1:result', 'ns1' =>'http://api.zuora.com/').size > 0 && body.xpath('//ns1:Errors', 'ns1' =>'http://api.zuora.com/').size > 0
|
198
|
+
error = []
|
199
|
+
success = []
|
200
|
+
body.xpath('//ns1:result', 'ns1' =>'http://api.zuora.com/').each_with_index do |call, object_index|
|
201
|
+
|
202
|
+
if call.xpath('./ns1:Success', 'ns1' =>'http://api.zuora.com/').text == 'false'
|
203
|
+
message = "#{call.xpath('./*/ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{call.xpath('./*/ns1:Message', 'ns1' =>'http://api.zuora.com/').text}"
|
204
|
+
error.push(message)
|
205
|
+
else
|
206
|
+
success.push(call.xpath('./ns1:Id', 'ns1' =>'http://api.zuora.com/').text)
|
207
|
+
end
|
208
|
+
end
|
190
209
|
end
|
191
210
|
|
211
|
+
#By default response if not passed in for SOAP as all SOAP is 200
|
192
212
|
if error.present?
|
193
|
-
if error ==
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
213
|
+
if error.class == String
|
214
|
+
if error == "INVALID_SESSION"
|
215
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{error}::#{message}", body, response.present? ? response.code : nil )
|
216
|
+
end
|
217
|
+
if error == "REQUEST_EXCEEDED_LIMIT"
|
218
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{error}::#{message}", body, response.present? ? response.code : nil)
|
219
|
+
end
|
220
|
+
if error == "LOCK_COMPETITION"
|
221
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{error}::#{message}", body, response.present? ? response.code : nil)
|
222
|
+
end
|
223
|
+
if error.present?
|
224
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{error}::#{message}", body, response.present? ? response.code : nil)
|
225
|
+
end
|
226
|
+
elsif error.class == Array
|
227
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(error.group_by {|v| v}.map {|k,v| "(#{v.size}x) - #{k}"}.join(', '), body, response.present? ? response.code : nil, error, success)
|
204
228
|
end
|
205
229
|
end
|
206
|
-
|
207
|
-
when :JSON
|
230
|
+
|
231
|
+
when :JSON
|
208
232
|
if body.class == Hash && (!body["success"] || !body["Success"] || response.code != 200)
|
209
233
|
messages_array = (body["reasons"] || []).map {|error| error['message']}.compact
|
210
234
|
codes_array = (body["reasons"] || []).map {|error| error['code']}.compact
|
211
235
|
|
212
236
|
#Authentication failed
|
213
237
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(11) || response.code == 401
|
214
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{messages_array.join(', ')}")
|
238
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{messages_array.join(', ')}", body, response.code)
|
215
239
|
end
|
216
240
|
|
217
241
|
#Zuora REST Create Amendment error #Authentication failed
|
218
242
|
if body["faultcode"].present? && body["faultcode"] == "fns:INVALID_SESSION"
|
219
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body['faultstring']}")
|
243
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body['faultstring']}", body, response.code)
|
220
244
|
end
|
221
245
|
|
222
246
|
#Request exceeded limit
|
223
247
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
|
224
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}")
|
248
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", body, response.code)
|
225
249
|
end
|
226
250
|
|
227
251
|
#Locking contention
|
228
252
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
|
229
|
-
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}")
|
253
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", body, response.code)
|
230
254
|
end
|
231
255
|
|
232
256
|
#All Errors catch
|
233
|
-
if codes_array.size > 0
|
234
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{messages_array.join(', ')}")
|
257
|
+
if codes_array.size > 0
|
258
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{messages_array.join(', ')}", body, response.code)
|
235
259
|
end
|
236
260
|
|
237
261
|
#Zuora REST Query Errors
|
238
262
|
if body["faultcode"].present?
|
239
263
|
case body["faultcode"]
|
240
264
|
when "fns:MALFORMED_QUERY"
|
241
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}")
|
265
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
242
266
|
when "fns:REQUEST_EXCEEDED_LIMIT"
|
243
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body["faultcode"]}::#{body["faultstring"]}")
|
267
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
244
268
|
when "fns:LOCK_COMPETITION"
|
245
|
-
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body["faultcode"]}::#{body["faultstring"]}")
|
269
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
246
270
|
when "INVALID_SESSION"
|
247
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body["faultcode"]}::#{body["faultstring"]}")
|
271
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
248
272
|
else
|
249
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}")
|
250
|
-
end
|
273
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
274
|
+
end
|
251
275
|
end
|
252
276
|
|
253
277
|
if body["Errors"].present? || body["errors"].present?
|
@@ -255,24 +279,24 @@ module ZuoraAPI
|
|
255
279
|
(body["Errors"] || []).select { |obj| errors.push(obj["Message"]) }.compact
|
256
280
|
(body["errors"] || []).select { |obj| errors.push(obj["Message"]) }.compact
|
257
281
|
if errors.size > 0
|
258
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{errors.join(", ")}",
|
282
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{errors.join(", ")}", body, response.code, errors)
|
259
283
|
end
|
260
284
|
end
|
261
285
|
end
|
262
|
-
|
286
|
+
|
263
287
|
#Zuora REST Actions error (Create, Update, Delete)
|
264
288
|
if body.class == Array
|
265
289
|
all_errors = body.select {|obj| !obj['Success'] || !obj['success'] }.map {|obj| obj['Errors'] || obj['errors'] }.compact
|
266
290
|
all_success = body.select {|obj| obj['Success'] || obj['success']}.compact
|
267
291
|
|
268
|
-
if all_errors.size > 0
|
269
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{all_errors.flatten.group_by {|error| error['Message']}.keys.uniq.join(' ')}",
|
292
|
+
if all_errors.size > 0
|
293
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{all_errors.flatten.group_by {|error| error['Message']}.keys.uniq.join(' ')}", body, response.code, all_errors, all_success )
|
270
294
|
end
|
271
295
|
end
|
272
296
|
|
273
297
|
#All other errors
|
274
298
|
if response.code != 200
|
275
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}")
|
299
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}", body, response.code)
|
276
300
|
end
|
277
301
|
end
|
278
302
|
end
|
@@ -381,10 +405,13 @@ module ZuoraAPI
|
|
381
405
|
Rails.logger.debug('Connect') {"Response JSON: #{output_json}"} if debug && output_json.present?
|
382
406
|
|
383
407
|
raise_errors(type: :JSON, body: output_json, response: response)
|
408
|
+
rescue ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError => ex
|
409
|
+
Rails.logger.debug {"Session Bad Auth type"}
|
410
|
+
raise ex
|
384
411
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
385
412
|
if !(tries -= 1).zero? && z_session
|
386
413
|
Rails.logger.debug {"Session Invalid"}
|
387
|
-
self.new_session
|
414
|
+
self.new_session(oauth_only ? :bearer : nil)
|
388
415
|
retry
|
389
416
|
else
|
390
417
|
if errors.include?(ex.class)
|
@@ -567,7 +594,7 @@ module ZuoraAPI
|
|
567
594
|
end
|
568
595
|
end
|
569
596
|
rescue Exception => e
|
570
|
-
Rails.logger.fatal('GetFile') {"Download Failed: #{response_save} - #{e.message}"}
|
597
|
+
Rails.logger.fatal('GetFile') {"Download Failed: #{response_save} - #{e.class} : #{e.message}"}
|
571
598
|
Rails.logger.fatal('GetFile') {"Download Failed: #{e.backtrace.join("\n")}"}
|
572
599
|
raise
|
573
600
|
end
|
@@ -596,9 +623,10 @@ module ZuoraAPI
|
|
596
623
|
end
|
597
624
|
end
|
598
625
|
end
|
626
|
+
|
627
|
+
|
599
628
|
response_query = HTTParty.post(self.url, body: request.to_xml, headers: {'Content-Type' => "application/json; charset=utf-8"}, :timeout => 120)
|
600
629
|
output_xml = Nokogiri::XML(response_query.body)
|
601
|
-
|
602
630
|
raise 'Export Creation Unsuccessful : ' + output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
603
631
|
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
604
632
|
|
@@ -15,15 +15,21 @@ module ZuoraAPI
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def authentication_prefix(auth_type = :basic)
|
18
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic
|
18
19
|
return "ZSession "
|
19
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}")
|
20
20
|
end
|
21
21
|
|
22
22
|
def check_session(auth_type = :basic)
|
23
|
+
if auth_type != :basic
|
24
|
+
self.current_error = "Basic Login, does not support Authentication of Type: #{auth_type}"
|
25
|
+
self.status = 'AuthenticationError'
|
26
|
+
return false
|
27
|
+
end
|
23
28
|
return @z_session_token.blank?
|
24
29
|
end
|
25
30
|
|
26
31
|
def new_session(auth_type = :basic)
|
32
|
+
Rails.logger.debug("Create new session")
|
27
33
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic
|
28
34
|
begin
|
29
35
|
tries ||= 2
|
@@ -44,7 +44,11 @@ module ZuoraAPI
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def check_session(auth_type = :basic)
|
47
|
-
|
47
|
+
if !@supported_authentication_types.include?(auth_type)
|
48
|
+
self.current_error = "Oauth Login, does not support Authentication of Type: #{auth_type}"
|
49
|
+
self.status = 'AuthenticationError'
|
50
|
+
return false
|
51
|
+
end
|
48
52
|
return true if (auth_type != @stored_session_type || @stored_session_type.nil?)
|
49
53
|
return false
|
50
54
|
end
|
@@ -69,7 +73,7 @@ module ZuoraAPI
|
|
69
73
|
response = HTTParty.get(self.rest_endpoint("connections"), headers: {:Authorization => "Bearer " + @bearer_token})
|
70
74
|
end
|
71
75
|
if JSON.parse(response.body)["success"] ##.to_bool
|
72
|
-
|
76
|
+
self.z_session_token = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1]
|
73
77
|
@stored_session_type = :basic
|
74
78
|
self.current_error = nil
|
75
79
|
self.status = 'Active'
|
@@ -77,7 +81,6 @@ module ZuoraAPI
|
|
77
81
|
self.current_error = JSON.parse(response.body)["reasons"][0]["message"]
|
78
82
|
self.status = "Invalid"
|
79
83
|
end
|
80
|
-
|
81
84
|
return @z_session_token
|
82
85
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
83
86
|
if !(tries -= 1).zero? && z_session
|
@@ -121,7 +124,7 @@ module ZuoraAPI
|
|
121
124
|
url = URI.parse(encoded_url)
|
122
125
|
response = HTTParty.post(url,:headers => {:content_type => "application/x-www-form-urlencoded"}, :body => {:client_id=>@oauth_client_id, :client_secret=>@oauth_secret, :grant_type=>"client_credentials"})
|
123
126
|
if JSON.parse(response.body)["error"].nil?
|
124
|
-
|
127
|
+
self.bearer_token = JSON.parse(response.body)["access_token"]
|
125
128
|
@oauth_session_expires_at = Time.now.to_i + JSON.parse(response.body)["expires_in"].to_i
|
126
129
|
@stored_session_type = :bearer
|
127
130
|
self.current_error = nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_api_oauth_alpha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2'
|
4
|
+
version: '2.1'
|
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: 2018-04-
|
11
|
+
date: 2018-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: nokogiri
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: httparty
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|