zuora_api 1.7.65g → 1.7.66d
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/.gitlab-ci.yml +1 -0
- data/lib/zuora_api/exceptions.rb +3 -2
- data/lib/zuora_api/login.rb +93 -69
- data/lib/zuora_api/logins/oauth.rb +10 -6
- 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: 899b9f7281ac70fc96cedd3a94fefd95184be57b4b8e596d3a33c4d140252faf
|
4
|
+
data.tar.gz: c1c3a2fac114b367e084208b806fe30e64a5441710b85e4d1c3a74ac24f5a6c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09d7e01c4c7592705644eafc7310de8de7c02b9d3f938cd6aa7388aa05cc64ca8d43f1485680f2f17210744073ee7a0e541525eaad83d7b0c7548fd626fb38cb'
|
7
|
+
data.tar.gz: 1831e616a849cc266b126fe085b8765a6493dcc578d5875315f44ef53c698908ede7eb1b47bcff254e71ff1c27eaee2abbdabcc35994f78f89d7d8894c5a6978
|
data/.gitlab-ci.yml
CHANGED
data/lib/zuora_api/exceptions.rb
CHANGED
@@ -177,14 +177,15 @@ module ZuoraAPI
|
|
177
177
|
end
|
178
178
|
|
179
179
|
class ZuoraAPITemporaryError < Error
|
180
|
-
attr_reader :code, :response
|
180
|
+
attr_reader :code, :response, :errors
|
181
181
|
attr_writer :default_message
|
182
182
|
|
183
|
-
def initialize(message = nil,response=nil, errors = [], successes = [], *args)
|
183
|
+
def initialize(message = nil, response = nil, errors = [], successes = [], *args)
|
184
184
|
@code = response.class.to_s == "HTTParty::Response" ? response.code : nil
|
185
185
|
@message = parse_message(message)
|
186
186
|
@response = response
|
187
187
|
@default_message = "There is a temporary error with zuora system."
|
188
|
+
@errors = errors
|
188
189
|
end
|
189
190
|
|
190
191
|
def to_s
|
data/lib/zuora_api/login.rb
CHANGED
@@ -39,8 +39,8 @@ module ZuoraAPI
|
|
39
39
|
|
40
40
|
ZUORA_SERVER_ERRORS = [
|
41
41
|
ZuoraAPI::Exceptions::ZuoraAPIInternalServerError,
|
42
|
-
|
43
|
-
|
42
|
+
ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout,
|
43
|
+
ZuoraAPI::Exceptions::ZuoraAPIReadTimeout,
|
44
44
|
ZuoraAPI::Exceptions::ZuoraUnexpectedError
|
45
45
|
].freeze
|
46
46
|
|
@@ -428,7 +428,8 @@ module ZuoraAPI
|
|
428
428
|
def soap_call(
|
429
429
|
ns1: 'ns1',
|
430
430
|
ns2: 'ns2',
|
431
|
-
batch_size: nil,
|
431
|
+
batch_size: nil,
|
432
|
+
headers: {},
|
432
433
|
single_transaction: false,
|
433
434
|
debug: false,
|
434
435
|
zuora_track_id: nil,
|
@@ -471,7 +472,7 @@ module ZuoraAPI
|
|
471
472
|
input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
|
472
473
|
Rails.logger.debug("Request SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
|
473
474
|
|
474
|
-
headers
|
475
|
+
headers.merge!({ 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'})
|
475
476
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
476
477
|
|
477
478
|
request = HTTParty::Request.new(
|
@@ -500,20 +501,18 @@ module ZuoraAPI
|
|
500
501
|
end
|
501
502
|
|
502
503
|
retry
|
503
|
-
else
|
504
|
-
if errors.include?(ex.class)
|
505
|
-
raise ex
|
506
|
-
else
|
507
|
-
return output_xml, input_xml, response
|
508
|
-
end
|
509
504
|
end
|
505
|
+
|
506
|
+
raise ex if errors.include?(ex.class)
|
507
|
+
|
508
|
+
return output_xml, input_xml, response
|
509
|
+
|
510
510
|
rescue *ZUORA_API_ERRORS => ex
|
511
|
-
if errors.include?(ex.class)
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
end
|
511
|
+
raise ex if errors.include?(ex.class)
|
512
|
+
|
513
|
+
response = ex.response unless response
|
514
|
+
return output_xml, input_xml, response
|
515
|
+
|
517
516
|
rescue *CONNECTION_EXCEPTIONS => ex
|
518
517
|
if tries.zero?
|
519
518
|
if output_exception_messages
|
@@ -629,21 +628,8 @@ module ZuoraAPI
|
|
629
628
|
end
|
630
629
|
end
|
631
630
|
|
632
|
-
|
633
|
-
|
634
|
-
elsif response.code == 500
|
635
|
-
if response.headers.fetch('content-type', []).include?('application/json')
|
636
|
-
begin
|
637
|
-
output_json = JSON.parse(response.body)
|
638
|
-
self.raise_errors(type: :JSON, body: output_json, response: response)
|
639
|
-
rescue JSON::ParserError => ex
|
640
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
641
|
-
end
|
642
|
-
else
|
643
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
644
|
-
end
|
645
|
-
end
|
646
|
-
|
631
|
+
self.errors_via_content_type(response: response, type: :xml)
|
632
|
+
|
647
633
|
when :JSON
|
648
634
|
case request_path
|
649
635
|
when /^\/query\/jobs.*/ #DataQuery Paths
|
@@ -671,6 +657,10 @@ module ZuoraAPI
|
|
671
657
|
when /^GET::400::\/api\/rest\/v1\/reports\/(reportlabels\/)?([a-zA-Z0-9\-_]+)\/report-details$/ # Get report, capture of the id is present if needed in future error responses.
|
672
658
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(reporting_message, response) if reporting_message.present?
|
673
659
|
end
|
660
|
+
when /\/objects\/batch\//
|
661
|
+
if body['code'].present? && /61$/.match(body['code'].to_s).present? # if last 2 digits of code are 61
|
662
|
+
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new(body['message'], nil, body['details'])
|
663
|
+
end
|
674
664
|
end
|
675
665
|
|
676
666
|
body = body.dig("results").present? ? body["results"] : body if body.class == Hash
|
@@ -731,7 +721,6 @@ module ZuoraAPI
|
|
731
721
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
|
732
722
|
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
|
733
723
|
end
|
734
|
-
|
735
724
|
#Internal Server Error
|
736
725
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(60)
|
737
726
|
if messages_array.uniq.size == 1
|
@@ -742,6 +731,11 @@ module ZuoraAPI
|
|
742
731
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("#{messages_array.join(', ')}", response)
|
743
732
|
end
|
744
733
|
|
734
|
+
#Retryiable Service Error
|
735
|
+
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(61)
|
736
|
+
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new("#{messages_array.join(', ')}", response)
|
737
|
+
end
|
738
|
+
|
745
739
|
#Request exceeded limit
|
746
740
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
|
747
741
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
|
@@ -794,32 +788,56 @@ module ZuoraAPI
|
|
794
788
|
end
|
795
789
|
end
|
796
790
|
|
791
|
+
if body.class == Hash && body['message'].present?
|
792
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response) if response.code == 500
|
793
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response) if ![200,201].include?(response.code)
|
794
|
+
end
|
795
|
+
|
796
|
+
self.errors_via_content_type(response: response, type: :json)
|
797
|
+
|
797
798
|
#All other errors
|
798
|
-
if response.code
|
799
|
-
|
800
|
-
|
801
|
-
else
|
802
|
-
response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ''
|
799
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response) if ![200,201].include?(response.code)
|
800
|
+
end
|
801
|
+
end
|
803
802
|
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
803
|
+
def errors_via_content_type(response: nil, type: :xml)
|
804
|
+
response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ""
|
805
|
+
|
806
|
+
if response_content_types.include?('application/json') && type != :json
|
807
|
+
output_json = JSON.parse(response.body)
|
808
|
+
self.raise_errors(type: :JSON, body: output_json, response: response)
|
809
|
+
|
810
|
+
elsif (response_content_types.include?('application/xml') || response_content_types.include?('text/xml')) and type != :xml
|
811
|
+
output_xml = Nokogiri::XML(response.body)
|
812
|
+
self.raise_errors(type: :SOAP, body: output_xml, response: response)
|
813
|
+
|
814
|
+
elsif response_content_types.include?('text/html')
|
815
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Akamai Error", response) if response.headers.fetch('server', '') == 'AkamaiGHost'
|
816
|
+
|
817
|
+
parse_body = Nokogiri::HTML(response.body)
|
818
|
+
error_title = parse_body.xpath('//h2').text
|
819
|
+
error_title = parse_body.xpath('//h1').text if error_title.blank?
|
820
|
+
error_message = parse_body.xpath('//p').text
|
821
|
+
|
822
|
+
error_message = error_title if error_message.blank?
|
823
|
+
|
824
|
+
if error_title.present?
|
825
|
+
case error_title
|
826
|
+
when /Service Unavailable/
|
827
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
|
828
|
+
when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
|
829
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
830
|
+
else
|
831
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
819
832
|
end
|
820
833
|
end
|
834
|
+
|
835
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Http response body is missing", response) if response.body.blank?
|
821
836
|
end
|
837
|
+
|
838
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response) if response.code == 500
|
822
839
|
end
|
840
|
+
|
823
841
|
|
824
842
|
def get_soap_error_and_message(body)
|
825
843
|
error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
|
@@ -885,7 +903,7 @@ module ZuoraAPI
|
|
885
903
|
when /.*soapenv:Server.*/
|
886
904
|
if /^Invalid value.*for type.*|^Id is invalid|^date string can not be less than 19 charactors$/.match(message).present?
|
887
905
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
888
|
-
elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
|
906
|
+
elsif /^Invalid white space character \(.*\) in text to output$|^Invalid null character in text to output$/.match(message).present?
|
889
907
|
raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
|
890
908
|
end
|
891
909
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
|
@@ -1065,10 +1083,10 @@ module ZuoraAPI
|
|
1065
1083
|
if self.class.to_s == 'ZuoraAPI::Oauth' && ex.message.include?("Authentication type is not supported by this Login")
|
1066
1084
|
session_type = :bearer
|
1067
1085
|
retry
|
1068
|
-
else
|
1069
|
-
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
1070
|
-
raise ex
|
1071
1086
|
end
|
1087
|
+
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
1088
|
+
raise ex
|
1089
|
+
|
1072
1090
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
1073
1091
|
if !tries.zero? && z_session
|
1074
1092
|
tries -= 1
|
@@ -1081,20 +1099,17 @@ module ZuoraAPI
|
|
1081
1099
|
end
|
1082
1100
|
|
1083
1101
|
retry
|
1084
|
-
else
|
1085
|
-
if errors.include?(ex.class)
|
1086
|
-
raise ex
|
1087
|
-
else
|
1088
|
-
return [output_json, response]
|
1089
|
-
end
|
1090
1102
|
end
|
1103
|
+
|
1104
|
+
raise ex if errors.include?(ex.class)
|
1105
|
+
return [output_json, response]
|
1106
|
+
|
1091
1107
|
rescue *ZUORA_API_ERRORS => ex
|
1092
|
-
if errors.include?(ex.class)
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
end
|
1108
|
+
raise ex if errors.include?(ex.class)
|
1109
|
+
|
1110
|
+
response = ex.response unless response
|
1111
|
+
return [output_json, response]
|
1112
|
+
|
1098
1113
|
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
1099
1114
|
raise ex
|
1100
1115
|
rescue *CONNECTION_EXCEPTIONS => ex
|
@@ -1313,7 +1328,7 @@ module ZuoraAPI
|
|
1313
1328
|
end
|
1314
1329
|
end
|
1315
1330
|
|
1316
|
-
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id:
|
1331
|
+
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
|
1317
1332
|
begin
|
1318
1333
|
tries ||= 3
|
1319
1334
|
request = Nokogiri::XML::Builder.new do |xml|
|
@@ -1399,6 +1414,15 @@ module ZuoraAPI
|
|
1399
1414
|
raise ex
|
1400
1415
|
end
|
1401
1416
|
|
1417
|
+
rescue ZuoraAPI::Exceptions::ZuoraUnexpectedError => ex
|
1418
|
+
if !(tries -= 1).zero?
|
1419
|
+
Rails.logger.info("Trace ID: #{z_track_id} UnexpectedError, will retry after 10 seconds")
|
1420
|
+
sleep 10
|
1421
|
+
retry
|
1422
|
+
else
|
1423
|
+
raise ex
|
1424
|
+
end
|
1425
|
+
|
1402
1426
|
rescue *ZUORA_API_ERRORS => ex
|
1403
1427
|
raise ex
|
1404
1428
|
|
@@ -37,7 +37,13 @@ module ZuoraAPI
|
|
37
37
|
begin
|
38
38
|
self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
|
39
39
|
rescue NoMethodError => ex
|
40
|
-
Rails.logger.fatal("Failure Parsing Cookie Headers",
|
40
|
+
Rails.logger.fatal("Failure Parsing Cookie Headers", {
|
41
|
+
response: {
|
42
|
+
status: response.code,
|
43
|
+
params: response.body.to_s,
|
44
|
+
headers: response.headers.to_s,
|
45
|
+
}
|
46
|
+
})
|
41
47
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Failure Parsing Cookie Headers")
|
42
48
|
end
|
43
49
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
@@ -47,12 +53,10 @@ module ZuoraAPI
|
|
47
53
|
self.new_session(auth_type: :bearer)
|
48
54
|
retry
|
49
55
|
end
|
50
|
-
raise ex
|
51
|
-
return [output_json, response]
|
56
|
+
raise ex
|
52
57
|
|
53
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition
|
54
|
-
raise ex
|
55
|
-
return [output_json, response]
|
58
|
+
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
59
|
+
raise ex
|
56
60
|
|
57
61
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
58
62
|
if !tries.zero?
|
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.66d
|
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-
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|