zuora_api 1.10.1 → 1.10.2

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: c3b3400576f3df87efec934f2e76fc13b6e427c20cb36dff8e4c81dc95abfc1d
4
- data.tar.gz: 9250a4ef4c4b1dc7de382e2325533536e646d3f36ada93afeb59a0aa90a87166
3
+ metadata.gz: 8cf78cb3b1e25a9394f07c8557a23b8822d4f5cf48839bfad5e6f8e2ab3ad1e7
4
+ data.tar.gz: 76d6cd10a87cbae7dc3a5898192c9cc1c8683c374ae0008b116bef46ecc79cda
5
5
  SHA512:
6
- metadata.gz: a1ad5caf8f7689f9522e5b880cf742d9bd3a20f52b662dfb59f091c17c986ae972b66f97adc2752a16aee77fcd019934e338276ae61ba802918e65543df1ccbf
7
- data.tar.gz: 2ec1e093f0bfb3d7815434addb8372e5cf6ddee2b06957add664c86b411e2c026e8e018ad0c7a9508c12a660d4bf1373f8099e10ca191a462c338d9a6ac99a58
6
+ metadata.gz: 4e53ec1c8acb9ba3d7ce1247f5516162d85095567421082b025fd04117a4cdc463854ec136dc09f3283b09af493a1d68b17cda7c29f0d18d48faabfef949dea5
7
+ data.tar.gz: 0be11b3df708385da409848b1c953be59cd3efe4c8b658d55dd06e781a9c347df58cd809f32edb88063be4ea6ea11fada13396177ddb08233534afffd3458463
@@ -125,6 +125,12 @@ module ZuoraAPI
125
125
  end
126
126
  end
127
127
 
128
+ class ZuoraAPIRequestConcurrentLimit < ZuoraAPIRequestLimit
129
+ end
130
+
131
+ class ZuoraAPIRequestRateLimit < ZuoraAPIRequestLimit
132
+ end
133
+
128
134
  class ZuoraAPIUnkownError < Error
129
135
  attr_reader :code, :response
130
136
  attr_writer :default_message
@@ -7,7 +7,7 @@ module ZuoraAPI
7
7
  class Login
8
8
  ENVIRONMENTS = [TEST = 'Test', SANDBOX = 'Sandbox', PRODUCTION = 'Production', PREFORMANCE = 'Preformance', SERVICES = 'Services', UNKNOWN = 'Unknown', STAGING = 'Staging' ]
9
9
  REGIONS = [EU = 'EU', US = 'US', NA = 'NA' ]
10
- MIN_Endpoints = {'Test': '108.0', 'Sandbox': '108.0', 'Production': '108.0', 'Performance': '108.0', 'Services': '96.0', 'Unknown': '96.0', 'Staging': '108.0'}.freeze
10
+ MIN_Endpoints = {'Test': '114.0', 'Sandbox': '114.0', 'Production': '114.0', 'Performance': '114.0', 'Services': '96.0', 'Unknown': '96.0', 'Staging': '114.0'}.freeze
11
11
  XML_SAVE_OPTIONS = Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
12
12
  USER_AGENT = "Zuora#{ENV['Z_APPLICATION_NAME']&.capitalize}/#{ENV['Z_APPLICATION_VERSION']&.delete('v')}"
13
13
 
@@ -30,6 +30,8 @@ module ZuoraAPI
30
30
  ZUORA_API_ERRORS = [
31
31
  ZuoraAPI::Exceptions::ZuoraAPIError,
32
32
  ZuoraAPI::Exceptions::ZuoraAPIRequestLimit,
33
+ ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit,
34
+ ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit,
33
35
  ZuoraAPI::Exceptions::ZuoraAPILockCompetition,
34
36
  ZuoraAPI::Exceptions::ZuoraAPITemporaryError,
35
37
  ZuoraAPI::Exceptions::ZuoraDataIntegrity,
@@ -457,6 +459,7 @@ module ZuoraAPI
457
459
  headers.merge!({ 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'})
458
460
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
459
461
  headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
462
+
460
463
  headers["User-Agent"] = USER_AGENT
461
464
 
462
465
  request = HTTParty::Request.new(
@@ -617,10 +620,7 @@ module ZuoraAPI
617
620
  case response.code
618
621
  when 504
619
622
  raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from 'https://#{rest_domain(endpoint: request_uri)}'", response)
620
- when 429
621
- 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)
622
- when 401
623
-
623
+ when 401, 429
624
624
  else
625
625
  if body.class == Hash
626
626
  case request_path
@@ -637,6 +637,21 @@ module ZuoraAPI
637
637
  when :SOAP
638
638
  error, success, message = get_soap_error_and_message(body)
639
639
 
640
+ if response.code == 429
641
+ if message.to_s.downcase.include?('concurrent')
642
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit.new(
643
+ "The total number of concurrent requests has exceeded the limit allowed by the system. " \
644
+ "Please resubmit your request later.",
645
+ response
646
+ )
647
+ else
648
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new(
649
+ "Rate limiting. Please resubmit your request later.",
650
+ response
651
+ )
652
+ end
653
+ end
654
+
640
655
  if body.xpath('//fns:LoginFault', 'fns' =>'http://fault.api.zuora.com/').present?
641
656
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response)
642
657
  end
@@ -729,7 +744,12 @@ module ZuoraAPI
729
744
  codes_array = codes_array.push(body.dig("error", 'code')).compact
730
745
  end
731
746
 
732
- if body['message'] == 'request exceeded limit'
747
+ body_message = body.fetch('message', '').downcase
748
+ if body_message.include?('rate limit exceeded')
749
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new("The total number of requests has exceeded the rate limit allowed by the system. Please resubmit your request later.", response)
750
+ end
751
+
752
+ if body_message.include?('request exceeded limit')
733
753
  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)
734
754
  end
735
755
 
@@ -801,7 +821,7 @@ module ZuoraAPI
801
821
 
802
822
  #Request exceeded limit
803
823
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
804
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
824
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit.new("#{messages_array.join(', ')}", response)
805
825
  end
806
826
 
807
827
  #All Errors catch
@@ -809,6 +829,10 @@ module ZuoraAPI
809
829
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{messages_array.join(', ')}", response)
810
830
  end
811
831
 
832
+ if response.code == 429
833
+ 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)
834
+ end
835
+
812
836
  #Zuora REST Query Errors
813
837
  if body["faultcode"].present?
814
838
  raise_errors_helper(error: body["faultcode"], message: body["faultstring"], response: response)
@@ -944,7 +968,11 @@ module ZuoraAPI
944
968
  when /.*INVALID_SESSION/
945
969
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response, errors, success)
946
970
  when /.*REQUEST_EXCEEDED_LIMIT/
947
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new(message, response, errors, success)
971
+ if message.to_s.downcase.include?('concurrent')
972
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit.new(message, response, errors, success)
973
+ else
974
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new(message, response, errors, success)
975
+ end
948
976
  when /.*LOCK_COMPETITION/
949
977
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new(message, response, errors, success)
950
978
  when /.*BATCH_FAIL_ERROR/
@@ -1151,6 +1179,7 @@ module ZuoraAPI
1151
1179
  end
1152
1180
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
1153
1181
  headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
1182
+
1154
1183
  headers['User-Agent'] = USER_AGENT
1155
1184
 
1156
1185
  modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
@@ -1319,6 +1348,7 @@ module ZuoraAPI
1319
1348
 
1320
1349
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
1321
1350
  headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
1351
+
1322
1352
  headers["User-Agent"] = USER_AGENT
1323
1353
 
1324
1354
  response_save = nil
@@ -1434,6 +1464,56 @@ module ZuoraAPI
1434
1464
  raise
1435
1465
  end
1436
1466
 
1467
+ def create_data_source_export(query: "", encrypted: false, zip: true, z_track_id: "")
1468
+ begin
1469
+ output_xml, input_xml = self.soap_call(debug: false, timeout_retry: true, zuora_track_id: z_track_id) do |xml|
1470
+ xml['ns1'].create do
1471
+ xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
1472
+ xml['ns2'].Format 'csv'
1473
+ xml['ns2'].Zip zip
1474
+ xml['ns2'].Name 'googman'
1475
+ xml['ns2'].Query query
1476
+ xml['ns2'].Encrypted encrypted
1477
+ end
1478
+ end
1479
+ end
1480
+
1481
+ return output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
1482
+ rescue Exception => ex
1483
+ raise ex.class.new("#{z_track_id} #{ex.message}")
1484
+ end
1485
+ end
1486
+
1487
+ def check_export_status(export_id: "")
1488
+ begin
1489
+ response, full_response = self.rest_call(method: :get,url: self.rest_endpoint("object/export/#{export_id}"))
1490
+
1491
+ return full_response.parsed_response
1492
+ rescue Exception => ex
1493
+ raise ex
1494
+ end
1495
+ end
1496
+
1497
+ def get_export_file(file_id: "", extract: true, zip: true)
1498
+ begin
1499
+ export_file_path = self.get_file(:url => self.rest_endpoint("files/#{file_id}")).path
1500
+
1501
+ if extract && zip
1502
+ require "zip"
1503
+ new_path = export_file_path.partition('.zip').first
1504
+ zipped = Zip::File.open(export_file_path)
1505
+ file_handle = zipped.entries.first
1506
+ file_handle.extract(new_path)
1507
+ File.delete(export_file_path)
1508
+ return new_path
1509
+ else
1510
+ return export_file_path
1511
+ end
1512
+ rescue Exception => ex
1513
+ raise ex
1514
+ end
1515
+ end
1516
+
1437
1517
  def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
1438
1518
  tries ||= 3
1439
1519
 
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.10.1"
2
+ VERSION = "1.10.2"
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.10.1
4
+ version: 1.10.2
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: 2021-12-06 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler