zuora_api 1.7.65e → 1.7.66b
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zuora_api/exceptions.rb +6 -4
- data/lib/zuora_api/login.rb +212 -136
- data/lib/zuora_api/logins/oauth.rb +20 -20
- 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: e57efb2492106ced22eaf4a943801d0f639eab7c8e1e6c5a4a927fe556963007
|
4
|
+
data.tar.gz: e21363cc410dd6c49e5513db1fd3561ea9d13ec7390e57b7abf6b966a44314b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1869137cefa3e67accb4bd917e4466df8627cf198eff2409420c0176c8e4fe728f8a56d53297a7f7418d7f7b207a1843383c74379cfc5662ec38c19e3e05300a
|
7
|
+
data.tar.gz: 037fa29a6add8b326da59402cdd2207c65385d3046869866c3cb2a5cbc2e8935855aeba549fda5239579cf4e3aabd86ce992b3dc1c9284ee166bf8c333b95bbd
|
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
|
@@ -225,13 +226,14 @@ module ZuoraAPI
|
|
225
226
|
end
|
226
227
|
|
227
228
|
class ZuoraAPIReadTimeout < Net::ReadTimeout
|
228
|
-
attr_reader :code, :response
|
229
|
+
attr_reader :code, :response, :request
|
229
230
|
attr_writer :default_message
|
230
231
|
|
231
|
-
def initialize(message = nil,response=nil, errors = [], successes = [], *args)
|
232
|
+
def initialize(message = nil, response = nil, request = nil, errors = [], successes = [], *args)
|
232
233
|
@code = response.class.to_s == "HTTParty::Response" ? response.code : nil
|
233
234
|
@message = message
|
234
235
|
@response = response
|
236
|
+
@request = request
|
235
237
|
@default_message = "Authentication type is not supported by this Login"
|
236
238
|
end
|
237
239
|
|
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
|
|
@@ -474,12 +474,16 @@ module ZuoraAPI
|
|
474
474
|
headers = { 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'}
|
475
475
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
476
476
|
|
477
|
-
|
477
|
+
request = HTTParty::Request.new(
|
478
|
+
Net::HTTP::Post,
|
478
479
|
self.url,
|
479
|
-
:
|
480
|
-
:
|
481
|
-
:
|
480
|
+
body: xml.doc.to_xml(:save_with => XML_SAVE_OPTIONS).strip,
|
481
|
+
headers: headers,
|
482
|
+
timeout: timeout,
|
482
483
|
)
|
484
|
+
|
485
|
+
response = request.perform
|
486
|
+
|
483
487
|
output_xml = Nokogiri::XML(response.body)
|
484
488
|
Rails.logger.debug("Response SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
|
485
489
|
|
@@ -496,20 +500,18 @@ module ZuoraAPI
|
|
496
500
|
end
|
497
501
|
|
498
502
|
retry
|
499
|
-
else
|
500
|
-
if errors.include?(ex.class)
|
501
|
-
raise ex
|
502
|
-
else
|
503
|
-
return output_xml, input_xml, response
|
504
|
-
end
|
505
503
|
end
|
504
|
+
|
505
|
+
raise ex if errors.include?(ex.class)
|
506
|
+
|
507
|
+
return output_xml, input_xml, response
|
508
|
+
|
506
509
|
rescue *ZUORA_API_ERRORS => ex
|
507
|
-
if errors.include?(ex.class)
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
end
|
510
|
+
raise ex if errors.include?(ex.class)
|
511
|
+
|
512
|
+
response = ex.response unless response
|
513
|
+
return output_xml, input_xml, response
|
514
|
+
|
513
515
|
rescue *CONNECTION_EXCEPTIONS => ex
|
514
516
|
if tries.zero?
|
515
517
|
if output_exception_messages
|
@@ -544,7 +546,7 @@ module ZuoraAPI
|
|
544
546
|
Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
545
547
|
end
|
546
548
|
end
|
547
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}") if ex.instance_of?(Net::ReadTimeout)
|
549
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
548
550
|
raise ex
|
549
551
|
rescue => ex
|
550
552
|
raise ex
|
@@ -553,24 +555,33 @@ module ZuoraAPI
|
|
553
555
|
end
|
554
556
|
|
555
557
|
def raise_errors(type: :SOAP, body: nil, response: nil)
|
556
|
-
|
557
|
-
|
558
|
+
request_uri, request_path, match_string = "", "", ""
|
559
|
+
if response.class.to_s == "HTTP::Message"
|
560
|
+
request_uri = response.http_header.request_uri.to_s
|
561
|
+
request_path = response.http_header.request_uri.path
|
562
|
+
match_string = "#{response.http_header.request_method}::#{response.code}::#{request_uri}"
|
563
|
+
else
|
564
|
+
request = response.request
|
565
|
+
request_uri = response.request.uri
|
566
|
+
request_path = request.path.path
|
567
|
+
match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request_path}"
|
568
|
+
end
|
558
569
|
|
559
570
|
if [502,503].include?(response.code)
|
560
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{
|
571
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{request_uri}", response)
|
561
572
|
end
|
562
573
|
|
563
574
|
# Check failure response code
|
564
575
|
case response.code
|
565
576
|
when 504
|
566
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{
|
577
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{request_uri}", response)
|
567
578
|
when 429
|
568
579
|
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)
|
569
580
|
when 401
|
570
581
|
|
571
582
|
else
|
572
583
|
if body.class == Hash
|
573
|
-
case
|
584
|
+
case request_path
|
574
585
|
when /^\/v1\/connections$/
|
575
586
|
response_headers = response.headers.to_h
|
576
587
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Missing cookies for authentication call", response) if response_headers['set-cookie'].blank?
|
@@ -594,7 +605,7 @@ module ZuoraAPI
|
|
594
605
|
reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
595
606
|
if reason.present?
|
596
607
|
message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
597
|
-
error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response|Socket Timeout)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
|
608
|
+
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'
|
598
609
|
else
|
599
610
|
error = 'FATAL_ERROR'
|
600
611
|
message = 'Export failed due to unknown reason. Consult api logs.'
|
@@ -616,23 +627,10 @@ module ZuoraAPI
|
|
616
627
|
end
|
617
628
|
end
|
618
629
|
|
619
|
-
|
620
|
-
|
621
|
-
elsif response.code == 500
|
622
|
-
if response.headers.fetch('content-type', []).include?('application/json')
|
623
|
-
begin
|
624
|
-
output_json = JSON.parse(response.body)
|
625
|
-
self.raise_errors(type: :JSON, body: output_json, response: response)
|
626
|
-
rescue JSON::ParserError => ex
|
627
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
628
|
-
end
|
629
|
-
else
|
630
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
631
|
-
end
|
632
|
-
end
|
633
|
-
|
630
|
+
self.errors_via_content_type(response: response, type: :xml)
|
631
|
+
|
634
632
|
when :JSON
|
635
|
-
case
|
633
|
+
case request_path
|
636
634
|
when /^\/query\/jobs.*/ #DataQuery Paths
|
637
635
|
return if body.class != Hash
|
638
636
|
case match_string
|
@@ -658,6 +656,10 @@ module ZuoraAPI
|
|
658
656
|
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.
|
659
657
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(reporting_message, response) if reporting_message.present?
|
660
658
|
end
|
659
|
+
when /\/objects\/batch\//
|
660
|
+
if body['code'].present? && /61$/.match(body['code'].to_s).present? # if last 2 digits of code are 61
|
661
|
+
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new(body['message'], nil, body['details'])
|
662
|
+
end
|
661
663
|
end
|
662
664
|
|
663
665
|
body = body.dig("results").present? ? body["results"] : body if body.class == Hash
|
@@ -718,7 +720,6 @@ module ZuoraAPI
|
|
718
720
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
|
719
721
|
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
|
720
722
|
end
|
721
|
-
|
722
723
|
#Internal Server Error
|
723
724
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(60)
|
724
725
|
if messages_array.uniq.size == 1
|
@@ -729,6 +730,11 @@ module ZuoraAPI
|
|
729
730
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("#{messages_array.join(', ')}", response)
|
730
731
|
end
|
731
732
|
|
733
|
+
#Retryiable Service Error
|
734
|
+
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(61)
|
735
|
+
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new("#{messages_array.join(', ')}", response)
|
736
|
+
end
|
737
|
+
|
732
738
|
#Request exceeded limit
|
733
739
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
|
734
740
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
|
@@ -781,32 +787,56 @@ module ZuoraAPI
|
|
781
787
|
end
|
782
788
|
end
|
783
789
|
|
790
|
+
if body.class == Hash && body['message'].present?
|
791
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response) if response.code == 500
|
792
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response) if ![200,201].include?(response.code)
|
793
|
+
end
|
794
|
+
|
795
|
+
self.errors_via_content_type(response: response, type: :json)
|
796
|
+
|
784
797
|
#All other errors
|
785
|
-
if response.code
|
786
|
-
|
787
|
-
|
788
|
-
else
|
789
|
-
response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ''
|
798
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response) if ![200,201].include?(response.code)
|
799
|
+
end
|
800
|
+
end
|
790
801
|
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
802
|
+
def errors_via_content_type(response: nil, type: :xml)
|
803
|
+
response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ""
|
804
|
+
|
805
|
+
if response_content_types.include?('application/json') && type != :json
|
806
|
+
output_json = JSON.parse(response.body)
|
807
|
+
self.raise_errors(type: :JSON, body: output_json, response: response)
|
808
|
+
|
809
|
+
elsif (response_content_types.include?('application/xml') || response_content_types.include?('text/xml')) and type != :xml
|
810
|
+
output_xml = Nokogiri::XML(response.body)
|
811
|
+
self.raise_errors(type: :SOAP, body: output_xml, response: response)
|
812
|
+
|
813
|
+
elsif response_content_types.include?('text/html')
|
814
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Akamai Error", response) if response.headers.fetch('server', '') == 'AkamaiGHost'
|
815
|
+
|
816
|
+
parse_body = Nokogiri::HTML(response.body)
|
817
|
+
error_title = parse_body.xpath('//h2').text
|
818
|
+
error_title = parse_body.xpath('//h1').text if error_title.blank?
|
819
|
+
error_message = parse_body.xpath('//p').text
|
820
|
+
|
821
|
+
error_message = error_title if error_message.blank?
|
822
|
+
|
823
|
+
if error_title.present?
|
824
|
+
case error_title
|
825
|
+
when /Service Unavailable/
|
826
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
|
827
|
+
when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
|
828
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
829
|
+
else
|
830
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
806
831
|
end
|
807
832
|
end
|
833
|
+
|
834
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Http response body is missing", response) if response.body.blank?
|
808
835
|
end
|
836
|
+
|
837
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response) if response.code == 500
|
809
838
|
end
|
839
|
+
|
810
840
|
|
811
841
|
def get_soap_error_and_message(body)
|
812
842
|
error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
|
@@ -870,9 +900,9 @@ module ZuoraAPI
|
|
870
900
|
when /.*UNEXPECTED_ERROR/
|
871
901
|
raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message, response, errors, success)
|
872
902
|
when /.*soapenv:Server.*/
|
873
|
-
if /^Invalid value.*for type.*|^Id is invalid
|
903
|
+
if /^Invalid value.*for type.*|^Id is invalid|^date string can not be less than 19 charactors$/.match(message).present?
|
874
904
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
875
|
-
elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
|
905
|
+
elsif /^Invalid white space character \(.*\) in text to output$|^Invalid null character in text to output$/.match(message).present?
|
876
906
|
raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
|
877
907
|
end
|
878
908
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
|
@@ -1023,7 +1053,7 @@ module ZuoraAPI
|
|
1023
1053
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
1024
1054
|
|
1025
1055
|
begin
|
1026
|
-
|
1056
|
+
request = HTTParty::Request.new(
|
1027
1057
|
"Net::HTTP::#{method.to_s.capitalize}".constantize,
|
1028
1058
|
url,
|
1029
1059
|
body: body,
|
@@ -1031,7 +1061,9 @@ module ZuoraAPI
|
|
1031
1061
|
timeout: timeout,
|
1032
1062
|
multipart: multipart,
|
1033
1063
|
stream_body: stream_body
|
1034
|
-
)
|
1064
|
+
)
|
1065
|
+
|
1066
|
+
response = request.perform(&block)
|
1035
1067
|
|
1036
1068
|
Rails.logger.debug("Response Code: #{response.code}") if debug
|
1037
1069
|
begin
|
@@ -1050,10 +1082,10 @@ module ZuoraAPI
|
|
1050
1082
|
if self.class.to_s == 'ZuoraAPI::Oauth' && ex.message.include?("Authentication type is not supported by this Login")
|
1051
1083
|
session_type = :bearer
|
1052
1084
|
retry
|
1053
|
-
else
|
1054
|
-
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
1055
|
-
raise ex
|
1056
1085
|
end
|
1086
|
+
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
1087
|
+
raise ex
|
1088
|
+
|
1057
1089
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
1058
1090
|
if !tries.zero? && z_session
|
1059
1091
|
tries -= 1
|
@@ -1066,20 +1098,17 @@ module ZuoraAPI
|
|
1066
1098
|
end
|
1067
1099
|
|
1068
1100
|
retry
|
1069
|
-
else
|
1070
|
-
if errors.include?(ex.class)
|
1071
|
-
raise ex
|
1072
|
-
else
|
1073
|
-
return [output_json, response]
|
1074
|
-
end
|
1075
1101
|
end
|
1102
|
+
|
1103
|
+
raise ex if errors.include?(ex.class)
|
1104
|
+
return [output_json, response]
|
1105
|
+
|
1076
1106
|
rescue *ZUORA_API_ERRORS => ex
|
1077
|
-
if errors.include?(ex.class)
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
end
|
1107
|
+
raise ex if errors.include?(ex.class)
|
1108
|
+
|
1109
|
+
response = ex.response unless response
|
1110
|
+
return [output_json, response]
|
1111
|
+
|
1083
1112
|
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
1084
1113
|
raise ex
|
1085
1114
|
rescue *CONNECTION_EXCEPTIONS => ex
|
@@ -1115,7 +1144,7 @@ module ZuoraAPI
|
|
1115
1144
|
Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
1116
1145
|
end
|
1117
1146
|
end
|
1118
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}") if ex.instance_of?(Net::ReadTimeout)
|
1147
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
1119
1148
|
raise ex
|
1120
1149
|
rescue => ex
|
1121
1150
|
raise ex
|
@@ -1298,75 +1327,122 @@ module ZuoraAPI
|
|
1298
1327
|
end
|
1299
1328
|
end
|
1300
1329
|
|
1301
|
-
def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1330
|
+
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
|
1331
|
+
begin
|
1332
|
+
tries ||= 3
|
1333
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
1334
|
+
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
|
1335
|
+
xml['SOAP-ENV'].Header do
|
1336
|
+
xml['ns1'].SessionHeader do
|
1337
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
1338
|
+
end
|
1307
1339
|
end
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1340
|
+
xml['SOAP-ENV'].Body do
|
1341
|
+
xml['ns1'].create do
|
1342
|
+
xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
|
1343
|
+
xml['ns2'].Format 'csv'
|
1344
|
+
xml['ns2'].Zip zip
|
1345
|
+
xml['ns2'].Name 'googman'
|
1346
|
+
xml['ns2'].Query query
|
1347
|
+
xml['ns2'].Encrypted encrypted
|
1348
|
+
end
|
1317
1349
|
end
|
1318
1350
|
end
|
1319
1351
|
end
|
1320
1352
|
end
|
1321
|
-
end
|
1322
1353
|
|
1323
|
-
|
1354
|
+
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)
|
1324
1355
|
|
1325
|
-
|
1326
|
-
|
1327
|
-
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1356
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1357
|
+
raise_errors(type: :SOAP, body: output_xml, response: response_query) if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
1328
1358
|
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1359
|
+
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
1360
|
+
|
1361
|
+
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1362
|
+
|
1363
|
+
confirmRequest = Nokogiri::XML::Builder.new do |xml|
|
1364
|
+
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
|
1365
|
+
xml['SOAP-ENV'].Header do
|
1366
|
+
xml['ns1'].SessionHeader do
|
1367
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
1368
|
+
end
|
1334
1369
|
end
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1370
|
+
xml['SOAP-ENV'].Body do
|
1371
|
+
xml['ns1'].query do
|
1372
|
+
xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
|
1373
|
+
end
|
1339
1374
|
end
|
1340
1375
|
end
|
1341
1376
|
end
|
1342
|
-
|
1343
|
-
result = 'Waiting'
|
1377
|
+
result = 'Waiting'
|
1344
1378
|
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1379
|
+
while result != "Completed"
|
1380
|
+
sleep 3
|
1381
|
+
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)
|
1348
1382
|
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
raise "Export Creation Unsuccessful : #{output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}" if result.blank? || result == "Failed"
|
1353
|
-
end
|
1383
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1384
|
+
result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
|
1385
|
+
status_code = response_query.code if response_query
|
1354
1386
|
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1387
|
+
raise_errors(type: :SOAP, body: output_xml, response: response_query) if result.blank? || result == "Failed"
|
1388
|
+
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if result.blank? || result == "Failed"
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
|
1392
|
+
export_file = get_file(:url => self.fileURL(file_id))
|
1393
|
+
export_file_path = export_file.path
|
1394
|
+
Rails.logger.debug("=====> Export path #{export_file.path}")
|
1395
|
+
|
1396
|
+
if extract && zip
|
1397
|
+
require "zip"
|
1398
|
+
new_path = export_file_path.partition('.zip').first
|
1399
|
+
zipped = Zip::File.open(export_file_path)
|
1400
|
+
file_handle = zipped.entries.first
|
1401
|
+
file_handle.extract(new_path)
|
1402
|
+
File.delete(export_file_path)
|
1403
|
+
return new_path
|
1404
|
+
else
|
1405
|
+
return export_file_path
|
1406
|
+
end
|
1407
|
+
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
1408
|
+
if !(tries -= 1).zero?
|
1409
|
+
Rails.logger.info("Export call failed - Trace ID: #{z_track_id}")
|
1410
|
+
self.new_session
|
1411
|
+
retry
|
1412
|
+
else
|
1413
|
+
raise ex
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
rescue ZuoraAPI::Exceptions::ZuoraUnexpectedError => ex
|
1417
|
+
if !(tries -= 1).zero?
|
1418
|
+
Rails.logger.info("Trace ID: #{z_track_id} UnexpectedError, will retry after 10 seconds")
|
1419
|
+
sleep 10
|
1420
|
+
retry
|
1421
|
+
else
|
1422
|
+
raise ex
|
1423
|
+
end
|
1424
|
+
|
1425
|
+
rescue *ZUORA_API_ERRORS => ex
|
1426
|
+
raise ex
|
1427
|
+
|
1428
|
+
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
1429
|
+
if !(tries -= 1).zero?
|
1430
|
+
Rails.logger.info("Trace ID: #{z_track_id} Timed out will retry after 5 seconds")
|
1431
|
+
sleep 5
|
1432
|
+
retry
|
1433
|
+
else
|
1434
|
+
raise ex
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
rescue Errno::ECONNRESET => ex
|
1438
|
+
if !(tries -= 1).zero? && ex.message.include?('SSL_connect')
|
1439
|
+
retry
|
1440
|
+
else
|
1441
|
+
raise ex
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
1445
|
+
raise ex
|
1370
1446
|
end
|
1371
1447
|
end
|
1372
1448
|
|
@@ -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
|
@@ -46,34 +52,28 @@ module ZuoraAPI
|
|
46
52
|
Rails.logger.debug {"Session Invalid"}
|
47
53
|
self.new_session(auth_type: :bearer)
|
48
54
|
retry
|
49
|
-
else
|
50
|
-
if errors.include?(ex.class)
|
51
|
-
raise ex
|
52
|
-
else
|
53
|
-
return [output_json, response]
|
54
|
-
end
|
55
55
|
end
|
56
|
+
raise ex if errors.include?(ex.class)
|
57
|
+
return [output_json, response]
|
58
|
+
|
56
59
|
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
|
60
|
+
raise ex if errors.include?(ex.class)
|
61
|
+
return [output_json, response]
|
62
|
+
|
62
63
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
63
64
|
if !tries.zero?
|
64
65
|
tries -= 1
|
65
66
|
sleep(self.timeout_sleep)
|
66
67
|
retry
|
68
|
+
end
|
69
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
70
|
+
Rails.logger.error("OAuthLogin - Timed out", ex)
|
67
71
|
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
|
72
|
+
Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
|
76
73
|
end
|
74
|
+
self.current_error = "Request timed out. Try again"
|
75
|
+
self.status = 'Timeout'
|
76
|
+
return self.status
|
77
77
|
end
|
78
78
|
|
79
79
|
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.66b
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|