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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d938d4f3650b7d013c75dd8331ff79d18892c3608f4a37e2709e5053203d4e
4
- data.tar.gz: 97d6019971a7d1fe835e4dad6c58aa3768851dbd2193708811927baaafa864b8
3
+ metadata.gz: 844d4f29e48548bf298907952d760386687b8d9f0cc4b6f1ce26defe42d9ce30
4
+ data.tar.gz: 38661f9da6c4032fe418941f1dddb1581680df7297e6eb8164deab377f82c54a
5
5
  SHA512:
6
- metadata.gz: f6926089bf23d4762906a3f292f42b8e66a7b6ec7c55e0fab3e38b78785f8fdb0e18e669e98227b13d0dc3e467476606e0634297ab1ca4535e8f09fa95faff9a
7
- data.tar.gz: 6803980d193339f1eba377d6591716660cca17a21fb9b873f112d6308883314336fb308d97fd222d2009e2772a24c595dc4751428d502a900ccd3cc3f8e05e12
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.65f)
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.0425)
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)
@@ -557,24 +557,33 @@ module ZuoraAPI
557
557
  end
558
558
 
559
559
  def raise_errors(type: :SOAP, body: nil, response: nil)
560
- request = response.request
561
- match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request.path.path}"
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 #{response.request.uri}", response)
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 #{response.request.uri}", response)
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 response.request.path.path
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 request.path.path
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/.match(message).present?
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
- request = Nokogiri::XML::Builder.new do |xml|
1309
- 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
1310
- xml['SOAP-ENV'].Header do
1311
- xml['ns1'].SessionHeader do
1312
- xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
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
- end
1315
- xml['SOAP-ENV'].Body do
1316
- xml['ns1'].create do
1317
- xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
1318
- xml['ns2'].Format 'csv'
1319
- xml['ns2'].Zip zip
1320
- xml['ns2'].Name 'googman'
1321
- xml['ns2'].Query query
1322
- xml['ns2'].Encrypted encrypted
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
- response_query = HTTParty.post(self.url, body: request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8"}, :timeout => 120)
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
- output_xml = Nokogiri::XML(response_query.body)
1332
- 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"
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
- confirmRequest = Nokogiri::XML::Builder.new do |xml|
1336
- 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
1337
- xml['SOAP-ENV'].Header do
1338
- xml['ns1'].SessionHeader do
1339
- xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
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
- end
1342
- xml['SOAP-ENV'].Body do
1343
- xml['ns1'].query do
1344
- xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
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
- end
1349
- result = 'Waiting'
1363
+ result = 'Waiting'
1350
1364
 
1351
- while result != "Completed"
1352
- sleep 3
1353
- response_query = HTTParty.post(self.url, body: confirmRequest.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8"}, :timeout => 120)
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
- output_xml = Nokogiri::XML(response_query.body)
1356
- result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
1357
- status_code = response_query.code if response_query
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
- file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
1362
- export_file = get_file(:url => self.fileURL(file_id))
1363
- export_file_path = export_file.path
1364
- Rails.logger.debug("=====> Export path #{export_file.path}")
1365
-
1366
- if extract && zip
1367
- require "zip"
1368
- new_path = export_file_path.partition('.zip').first
1369
- zipped = Zip::File.open(export_file_path)
1370
- file_handle = zipped.entries.first
1371
- file_handle.extract(new_path)
1372
- File.delete(export_file_path)
1373
- return new_path
1374
- else
1375
- return export_file_path
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
- raise ex
59
- else
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
- if Rails.logger.class.to_s == "Ougai::Logger"
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)
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.7.65f"
2
+ VERSION = "1.7.65g"
3
3
  end
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.65f
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-12 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler