zuora_api 1.3.9991 → 1.3.9992
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/lib/zuora_api/login.rb +48 -27
- data/lib/zuora_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1545862494cd38e964941c2afedc76412969c3c2
|
4
|
+
data.tar.gz: efacf4819c5b3a4ea3a30a44b46ad7c4a392987f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecf0ec7e8ea922b7ef92c07030729e0d93b82bb031f8cbc6caa6c11b226ce853d5217a54ef20aa5ac84c8433351959fd450b0d8003b30fb7c93f4b68d3412c49
|
7
|
+
data.tar.gz: 466c4df3142e028f2173de67094c1f3a5182228b7e65fa38605d4b0ac50ef918fb3a923695ae3b944d3ec81412a1bedfcdbd660b03916e76d0468b8582020748
|
data/lib/zuora_api/login.rb
CHANGED
@@ -187,7 +187,7 @@ module ZuoraAPI
|
|
187
187
|
return self.current_session
|
188
188
|
end
|
189
189
|
|
190
|
-
def soap_call(ns1: 'ns1', ns2: 'ns2', batch_size: nil, single_transaction: false,debug: true, z_session: true, **keyword_args)
|
190
|
+
def soap_call(ns1: 'ns1', ns2: 'ns2', batch_size: nil, single_transaction: false, debug: true, errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError, ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition], z_session: true, **keyword_args)
|
191
191
|
tries ||= 2
|
192
192
|
xml = Nokogiri::XML::Builder.new do |xml|
|
193
193
|
xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/",
|
@@ -223,26 +223,22 @@ module ZuoraAPI
|
|
223
223
|
output_xml = Nokogiri::XML(response.body)
|
224
224
|
Rails.logger.debug('Connect') {"Response SOAP XML: #{output_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip}"} if debug
|
225
225
|
|
226
|
-
|
227
|
-
|
228
|
-
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "LOCK_COMPETITION")
|
229
|
-
|
230
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if !output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank?
|
231
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{output_xml.xpath('//faultcode').text}::#{output_xml.xpath('//faultstring').text}") if !output_xml.xpath('//faultcode').text.blank?
|
226
|
+
raise_errors(type: :SOAP, body: output_xml, response: response)
|
227
|
+
|
232
228
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
233
229
|
if !(tries -= 1).zero? && z_session
|
234
230
|
Rails.logger.debug {"Session Invalid"}
|
235
231
|
self.new_session
|
236
232
|
retry
|
237
233
|
else
|
238
|
-
if
|
234
|
+
if errors.include?(ex.class)
|
239
235
|
raise ex
|
240
236
|
else
|
241
|
-
return [output_xml,
|
237
|
+
return [output_xml, input_xml]
|
242
238
|
end
|
243
239
|
end
|
244
240
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
245
|
-
if
|
241
|
+
if errors.include?(ex.class)
|
246
242
|
raise ex
|
247
243
|
else
|
248
244
|
return [output_xml, input_xml]
|
@@ -253,6 +249,41 @@ module ZuoraAPI
|
|
253
249
|
return [output_xml, input_xml]
|
254
250
|
end
|
255
251
|
|
252
|
+
def raise_errors(type: :SOAP, body: nil, response: nil)
|
253
|
+
case type
|
254
|
+
when :SOAP
|
255
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "INVALID_SESSION")
|
256
|
+
|
257
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "REQUEST_EXCEEDED_LIMIT")
|
258
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}") if (!body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text.blank? && body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text == "REQUEST_EXCEEDED_LIMIT")
|
259
|
+
|
260
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "LOCK_COMPETITION")
|
261
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}") if (!body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text.blank? && body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text == "LOCK_COMPETITION")
|
262
|
+
|
263
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if !body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank?
|
264
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body.xpath('//faultcode').text}::#{body.xpath('//faultstring').text}") if !body.xpath('//faultcode').text.blank?
|
265
|
+
|
266
|
+
when :JSON
|
267
|
+
#Zuora Regular REST API Unauthorized
|
268
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body["reasons"][0]["message"]}") if body.class != Array && (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 90000011 && response.code == 401)
|
269
|
+
#Zuora AQuA Unauthorized
|
270
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("Unauthorized") if response.code == 401
|
271
|
+
|
272
|
+
#Zuora REST API Limit Errors
|
273
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body["reasons"][0]["message"]}") if body.class != Array && (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 50000070 && response.code == 429)
|
274
|
+
|
275
|
+
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body["reasons"][0]["message"]}") if (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 53200050)
|
276
|
+
|
277
|
+
#Zuora REST Query Errors
|
278
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}") if body.class != Array && !body["faultcode"].blank?
|
279
|
+
#Zuora REST actions error
|
280
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["Errors"][0]["Code"]}::#{body["Errors"][0]["Message"]}") if body.class != Array && !body["Success"] && body["Errors"]
|
281
|
+
#Zuora All Other API Errors
|
282
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}") if response.code != 200
|
283
|
+
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
256
287
|
def aqua_query(queryName: '', query: '', version: '1.2', jobName: 'Aqua',partner: '', project: '')
|
257
288
|
params = {
|
258
289
|
"format" => 'csv',
|
@@ -329,7 +360,7 @@ module ZuoraAPI
|
|
329
360
|
return des_hash
|
330
361
|
end
|
331
362
|
|
332
|
-
def rest_call(method: :get, body: {},headers: {}, url: rest_endpoint("catalog/products?pageSize=4"), debug: true, z_session: true, **keyword_args)
|
363
|
+
def rest_call(method: :get, body: {},headers: {}, url: rest_endpoint("catalog/products?pageSize=4"), debug: true, errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError, ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition], z_session: true, **keyword_args)
|
333
364
|
tries ||= 2
|
334
365
|
headers["entityId"] = self.entity_id if !self.entity_id.blank?
|
335
366
|
raise "Method not supported, supported methods include: :get, :post, :put, :delete, :patch, :head, :options" if ![:get, :post, :put, :delete, :patch, :head, :options].include?(method)
|
@@ -338,32 +369,22 @@ module ZuoraAPI
|
|
338
369
|
output_json = JSON.parse(response.body)
|
339
370
|
Rails.logger.debug('Connect') {"Response JSON: #{output_json}"} if debug
|
340
371
|
|
341
|
-
|
342
|
-
|
343
|
-
#Zuora AQuA Unauthorized
|
344
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("Unauthorized") if response.code == 401
|
345
|
-
#Zuora REST API Limit Errors
|
346
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{output_json["reasons"][0]["message"]}") if output_json.class != Array && (!output_json["success"] && !output_json["reasons"].blank? && output_json["reasons"] == Array && output_json["reasons"][0]["code"] == 50000070 && response.code == 429)
|
347
|
-
#Zuora REST Query Errors
|
348
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{output_json["faultcode"]}::#{output_json["faultstring"]}") if output_json.class != Array && !output_json["faultcode"].blank?
|
349
|
-
#Zuora REST actions error
|
350
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{output_json["Errors"][0]["Code"]}::#{output_json["Errors"][0]["Message"]}") if output_json.class != Array && !output_json["Success"] && output_json["Errors"]
|
351
|
-
#Zuora All Other API Errors
|
352
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}") if response.code != 200
|
372
|
+
raise_errors(type: :JSON, body: output_json, response: response)
|
373
|
+
|
353
374
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
354
375
|
if !(tries -= 1).zero? && z_session
|
355
376
|
Rails.logger.debug {"Session Invalid"}
|
356
377
|
self.new_session
|
357
378
|
retry
|
358
379
|
else
|
359
|
-
if
|
380
|
+
if errors.include?(ex.class)
|
360
381
|
raise ex
|
361
382
|
else
|
362
383
|
return [output_json, response]
|
363
384
|
end
|
364
385
|
end
|
365
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit => ex
|
366
|
-
if
|
386
|
+
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
387
|
+
if errors.include?(ex.class)
|
367
388
|
raise ex
|
368
389
|
else
|
369
390
|
return [output_json, response]
|
@@ -393,7 +414,7 @@ module ZuoraAPI
|
|
393
414
|
while !response["nextPage"].blank?
|
394
415
|
url = self.rest_endpoint(response["nextPage"].split('/v1/').last)
|
395
416
|
Rails.logger.debug("Fetch Catalog URL #{url}")
|
396
|
-
output_json, response = self.rest_call(:debug => false, :url => url)
|
417
|
+
output_json, response = self.rest_call(:debug => false, :url => url, :errors => [ZuoraAPI::Exceptions::ZuoraAPISessionError])
|
397
418
|
if !output_json['success'] =~ (/(true|t|yes|y|1)$/i) || output_json['success'].class != TrueClass
|
398
419
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Error Getting Catalog: #{output_json}")
|
399
420
|
end
|
data/lib/zuora_api/version.rb
CHANGED