zuora_api 1.7.65f → 1.7.65g
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/zuora_api/login.rb +109 -62
- data/lib/zuora_api/logins/oauth.rb +13 -19
- data/lib/zuora_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844d4f29e48548bf298907952d760386687b8d9f0cc4b6f1ce26defe42d9ce30
|
4
|
+
data.tar.gz: 38661f9da6c4032fe418941f1dddb1581680df7297e6eb8164deab377f82c54a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c149b5fbb73d911e7b55dd10bf3f2d2149695a2d42866936dc43eeb1916191b54d3f666e187c08db69d84467f6e90e13750ab8f5c127b7d3610cc0484b07853
|
7
|
+
data.tar.gz: ab1ecee455a237c5b2077a8e331b25d9aa2fbc82ec46ad5be9579898d1b8c4c879f8c213efe2dd494c3941f9376557af1ee5d698ec093f60729b8f198ac8b174
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zuora_api (1.7.
|
4
|
+
zuora_api (1.7.65g)
|
5
5
|
httparty
|
6
6
|
nokogiri
|
7
7
|
railties (>= 4.1.0, < 6)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
method_source (1.0.0)
|
52
52
|
mime-types (3.3.1)
|
53
53
|
mime-types-data (~> 3.2015)
|
54
|
-
mime-types-data (3.2020.
|
54
|
+
mime-types-data (3.2020.0512)
|
55
55
|
mini_portile2 (2.4.0)
|
56
56
|
minitest (5.14.0)
|
57
57
|
multi_xml (0.6.0)
|
data/lib/zuora_api/login.rb
CHANGED
@@ -557,24 +557,33 @@ module ZuoraAPI
|
|
557
557
|
end
|
558
558
|
|
559
559
|
def raise_errors(type: :SOAP, body: nil, response: nil)
|
560
|
-
|
561
|
-
|
560
|
+
request_uri, request_path, match_string = "", "", ""
|
561
|
+
if response.class.to_s == "HTTP::Message"
|
562
|
+
request_uri = response.http_header.request_uri.to_s
|
563
|
+
request_path = response.http_header.request_uri.path
|
564
|
+
match_string = "#{response.http_header.request_method}::#{response.code}::#{request_uri}"
|
565
|
+
else
|
566
|
+
request = response.request
|
567
|
+
request_uri = response.request.uri
|
568
|
+
request_path = request.path.path
|
569
|
+
match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request_path}"
|
570
|
+
end
|
562
571
|
|
563
572
|
if [502,503].include?(response.code)
|
564
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{
|
573
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{request_uri}", response)
|
565
574
|
end
|
566
575
|
|
567
576
|
# Check failure response code
|
568
577
|
case response.code
|
569
578
|
when 504
|
570
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{
|
579
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{request_uri}", response)
|
571
580
|
when 429
|
572
581
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", response)
|
573
582
|
when 401
|
574
583
|
|
575
584
|
else
|
576
585
|
if body.class == Hash
|
577
|
-
case
|
586
|
+
case request_path
|
578
587
|
when /^\/v1\/connections$/
|
579
588
|
response_headers = response.headers.to_h
|
580
589
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Missing cookies for authentication call", response) if response_headers['set-cookie'].blank?
|
@@ -598,7 +607,7 @@ module ZuoraAPI
|
|
598
607
|
reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
599
608
|
if reason.present?
|
600
609
|
message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
601
|
-
error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response|Socket Timeout)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
|
610
|
+
error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response|Socket Timeout|There is an internal error, please try again later)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
|
602
611
|
else
|
603
612
|
error = 'FATAL_ERROR'
|
604
613
|
message = 'Export failed due to unknown reason. Consult api logs.'
|
@@ -636,7 +645,7 @@ module ZuoraAPI
|
|
636
645
|
end
|
637
646
|
|
638
647
|
when :JSON
|
639
|
-
case
|
648
|
+
case request_path
|
640
649
|
when /^\/query\/jobs.*/ #DataQuery Paths
|
641
650
|
return if body.class != Hash
|
642
651
|
case match_string
|
@@ -874,7 +883,7 @@ module ZuoraAPI
|
|
874
883
|
when /.*UNEXPECTED_ERROR/
|
875
884
|
raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message, response, errors, success)
|
876
885
|
when /.*soapenv:Server.*/
|
877
|
-
if /^Invalid value.*for type.*|^Id is invalid
|
886
|
+
if /^Invalid value.*for type.*|^Id is invalid|^date string can not be less than 19 charactors$/.match(message).present?
|
878
887
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
879
888
|
elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
|
880
889
|
raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
|
@@ -1304,75 +1313,113 @@ module ZuoraAPI
|
|
1304
1313
|
end
|
1305
1314
|
end
|
1306
1315
|
|
1307
|
-
def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1316
|
+
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: nil)
|
1317
|
+
begin
|
1318
|
+
tries ||= 3
|
1319
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
1320
|
+
xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
|
1321
|
+
xml['SOAP-ENV'].Header do
|
1322
|
+
xml['ns1'].SessionHeader do
|
1323
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
1324
|
+
end
|
1313
1325
|
end
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1326
|
+
xml['SOAP-ENV'].Body do
|
1327
|
+
xml['ns1'].create do
|
1328
|
+
xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
|
1329
|
+
xml['ns2'].Format 'csv'
|
1330
|
+
xml['ns2'].Zip zip
|
1331
|
+
xml['ns2'].Name 'googman'
|
1332
|
+
xml['ns2'].Query query
|
1333
|
+
xml['ns2'].Encrypted encrypted
|
1334
|
+
end
|
1323
1335
|
end
|
1324
1336
|
end
|
1325
1337
|
end
|
1326
1338
|
end
|
1327
|
-
end
|
1328
1339
|
|
1329
|
-
|
1340
|
+
response_query = HTTParty.post(self.url, body: request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8", "Z-Track-Id" => z_track_id}, :timeout => 120)
|
1330
1341
|
|
1331
|
-
|
1332
|
-
|
1333
|
-
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1342
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1343
|
+
raise_errors(type: :SOAP, body: output_xml, response: response_query) if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
1334
1344
|
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1345
|
+
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
1346
|
+
|
1347
|
+
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1348
|
+
|
1349
|
+
confirmRequest = Nokogiri::XML::Builder.new do |xml|
|
1350
|
+
xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
|
1351
|
+
xml['SOAP-ENV'].Header do
|
1352
|
+
xml['ns1'].SessionHeader do
|
1353
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
1354
|
+
end
|
1340
1355
|
end
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1356
|
+
xml['SOAP-ENV'].Body do
|
1357
|
+
xml['ns1'].query do
|
1358
|
+
xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
|
1359
|
+
end
|
1345
1360
|
end
|
1346
1361
|
end
|
1347
1362
|
end
|
1348
|
-
|
1349
|
-
result = 'Waiting'
|
1363
|
+
result = 'Waiting'
|
1350
1364
|
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1365
|
+
while result != "Completed"
|
1366
|
+
sleep 3
|
1367
|
+
response_query = HTTParty.post(self.url, body: confirmRequest.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8", "Z-Track-Id" => z_track_id}, :timeout => 120)
|
1354
1368
|
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
raise "Export Creation Unsuccessful : #{output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}" if result.blank? || result == "Failed"
|
1359
|
-
end
|
1369
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1370
|
+
result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
|
1371
|
+
status_code = response_query.code if response_query
|
1360
1372
|
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1373
|
+
raise_errors(type: :SOAP, body: output_xml, response: response_query) if result.blank? || result == "Failed"
|
1374
|
+
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if result.blank? || result == "Failed"
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
|
1378
|
+
export_file = get_file(:url => self.fileURL(file_id))
|
1379
|
+
export_file_path = export_file.path
|
1380
|
+
Rails.logger.debug("=====> Export path #{export_file.path}")
|
1381
|
+
|
1382
|
+
if extract && zip
|
1383
|
+
require "zip"
|
1384
|
+
new_path = export_file_path.partition('.zip').first
|
1385
|
+
zipped = Zip::File.open(export_file_path)
|
1386
|
+
file_handle = zipped.entries.first
|
1387
|
+
file_handle.extract(new_path)
|
1388
|
+
File.delete(export_file_path)
|
1389
|
+
return new_path
|
1390
|
+
else
|
1391
|
+
return export_file_path
|
1392
|
+
end
|
1393
|
+
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
1394
|
+
if !(tries -= 1).zero?
|
1395
|
+
Rails.logger.info("Export call failed - Trace ID: #{z_track_id}")
|
1396
|
+
self.new_session
|
1397
|
+
retry
|
1398
|
+
else
|
1399
|
+
raise ex
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
rescue *ZUORA_API_ERRORS => ex
|
1403
|
+
raise ex
|
1404
|
+
|
1405
|
+
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
1406
|
+
if !(tries -= 1).zero?
|
1407
|
+
Rails.logger.info("Trace ID: #{z_track_id} Timed out will retry after 5 seconds")
|
1408
|
+
sleep 5
|
1409
|
+
retry
|
1410
|
+
else
|
1411
|
+
raise ex
|
1412
|
+
end
|
1413
|
+
|
1414
|
+
rescue Errno::ECONNRESET => ex
|
1415
|
+
if !(tries -= 1).zero? && ex.message.include?('SSL_connect')
|
1416
|
+
retry
|
1417
|
+
else
|
1418
|
+
raise ex
|
1419
|
+
end
|
1420
|
+
|
1421
|
+
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
1422
|
+
raise ex
|
1376
1423
|
end
|
1377
1424
|
end
|
1378
1425
|
|
@@ -46,34 +46,28 @@ module ZuoraAPI
|
|
46
46
|
Rails.logger.debug {"Session Invalid"}
|
47
47
|
self.new_session(auth_type: :bearer)
|
48
48
|
retry
|
49
|
-
else
|
50
|
-
if errors.include?(ex.class)
|
51
|
-
raise ex
|
52
|
-
else
|
53
|
-
return [output_json, response]
|
54
|
-
end
|
55
49
|
end
|
50
|
+
raise ex if errors.include?(ex.class)
|
51
|
+
return [output_json, response]
|
52
|
+
|
56
53
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
57
|
-
if errors.include?(ex.class)
|
58
|
-
|
59
|
-
|
60
|
-
return [output_json, response]
|
61
|
-
end
|
54
|
+
raise ex if errors.include?(ex.class)
|
55
|
+
return [output_json, response]
|
56
|
+
|
62
57
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
63
58
|
if !tries.zero?
|
64
59
|
tries -= 1
|
65
60
|
sleep(self.timeout_sleep)
|
66
61
|
retry
|
62
|
+
end
|
63
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
64
|
+
Rails.logger.error("OAuthLogin - Timed out", ex)
|
67
65
|
else
|
68
|
-
|
69
|
-
Rails.logger.error("OAuthLogin - Timed out", ex)
|
70
|
-
else
|
71
|
-
Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
|
72
|
-
end
|
73
|
-
self.current_error = "Request timed out. Try again"
|
74
|
-
self.status = 'Timeout'
|
75
|
-
return self.status
|
66
|
+
Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
|
76
67
|
end
|
68
|
+
self.current_error = "Request timed out. Try again"
|
69
|
+
self.status = 'Timeout'
|
70
|
+
return self.status
|
77
71
|
end
|
78
72
|
|
79
73
|
def get_bearer_token(zuora_track_id: nil)
|
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.65g
|
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-05-
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|