zuora_api 1.7.65i → 1.7.65
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/Gemfile.lock +12 -12
- data/lib/zuora_api/exceptions.rb +2 -3
- data/lib/zuora_api/login.rb +149 -216
- data/lib/zuora_api/logins/oauth.rb +19 -13
- data/lib/zuora_api/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f825e33478662937ab98762bab71f5d10b55acedc5f14f51022f4e9a66bfb0e
|
4
|
+
data.tar.gz: 8a0edd6a1c0a7b11353b1057e14eb8d40cb47e85f3b7faac832532b1253e5ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz: '
|
6
|
+
metadata.gz: c7846e3e6df13eee656df3d122d98bf1f5694c83751836bd93810d6e3ec6ca6f88ba69b80d67cb04c9f30f4f94d2338c576eacd6d4401be0e27f9c2721f51fce
|
7
|
+
data.tar.gz: '0543405827032e0d71cf4f9462d565fb94ffb8ccdd76df9e59ccf2fd099ba8f608ff3ec057f1aa2b5577bb4448c583971e550cf69c1285b47736edc1ad3b9b1f'
|
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.65)
|
5
5
|
httparty
|
6
6
|
nokogiri
|
7
7
|
railties (>= 4.1.0, < 6)
|
@@ -10,20 +10,20 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionpack (5.2.4.
|
14
|
-
actionview (= 5.2.4.
|
15
|
-
activesupport (= 5.2.4.
|
13
|
+
actionpack (5.2.4.2)
|
14
|
+
actionview (= 5.2.4.2)
|
15
|
+
activesupport (= 5.2.4.2)
|
16
16
|
rack (~> 2.0, >= 2.0.8)
|
17
17
|
rack-test (>= 0.6.3)
|
18
18
|
rails-dom-testing (~> 2.0)
|
19
19
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
20
|
-
actionview (5.2.4.
|
21
|
-
activesupport (= 5.2.4.
|
20
|
+
actionview (5.2.4.2)
|
21
|
+
activesupport (= 5.2.4.2)
|
22
22
|
builder (~> 3.1)
|
23
23
|
erubi (~> 1.4)
|
24
24
|
rails-dom-testing (~> 2.0)
|
25
25
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
26
|
-
activesupport (5.2.4.
|
26
|
+
activesupport (5.2.4.2)
|
27
27
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
28
28
|
i18n (>= 0.7, < 2)
|
29
29
|
minitest (~> 5.1)
|
@@ -51,9 +51,9 @@ 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.
|
54
|
+
mime-types-data (3.2019.1009)
|
55
55
|
mini_portile2 (2.4.0)
|
56
|
-
minitest (5.14.
|
56
|
+
minitest (5.14.0)
|
57
57
|
multi_xml (0.6.0)
|
58
58
|
nokogiri (1.10.9)
|
59
59
|
mini_portile2 (~> 2.4.0)
|
@@ -66,9 +66,9 @@ GEM
|
|
66
66
|
nokogiri (>= 1.6)
|
67
67
|
rails-html-sanitizer (1.3.0)
|
68
68
|
loofah (~> 2.3)
|
69
|
-
railties (5.2.4.
|
70
|
-
actionpack (= 5.2.4.
|
71
|
-
activesupport (= 5.2.4.
|
69
|
+
railties (5.2.4.2)
|
70
|
+
actionpack (= 5.2.4.2)
|
71
|
+
activesupport (= 5.2.4.2)
|
72
72
|
method_source
|
73
73
|
rake (>= 0.8.7)
|
74
74
|
thor (>= 0.19.0, < 2.0)
|
data/lib/zuora_api/exceptions.rb
CHANGED
@@ -225,14 +225,13 @@ module ZuoraAPI
|
|
225
225
|
end
|
226
226
|
|
227
227
|
class ZuoraAPIReadTimeout < Net::ReadTimeout
|
228
|
-
attr_reader :code, :response
|
228
|
+
attr_reader :code, :response
|
229
229
|
attr_writer :default_message
|
230
230
|
|
231
|
-
def initialize(message = nil,
|
231
|
+
def initialize(message = nil,response=nil, errors = [], successes = [], *args)
|
232
232
|
@code = response.class.to_s == "HTTParty::Response" ? response.code : nil
|
233
233
|
@message = message
|
234
234
|
@response = response
|
235
|
-
@request = request
|
236
235
|
@default_message = "Authentication type is not supported by this Login"
|
237
236
|
end
|
238
237
|
|
data/lib/zuora_api/login.rb
CHANGED
@@ -474,16 +474,12 @@ 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
|
-
|
478
|
-
Net::HTTP::Post,
|
477
|
+
response = HTTParty.post(
|
479
478
|
self.url,
|
480
|
-
body
|
481
|
-
headers
|
482
|
-
timeout
|
479
|
+
:body => xml.doc.to_xml(:save_with => XML_SAVE_OPTIONS).strip,
|
480
|
+
:headers => headers,
|
481
|
+
:timeout => timeout
|
483
482
|
)
|
484
|
-
|
485
|
-
response = request.perform
|
486
|
-
|
487
483
|
output_xml = Nokogiri::XML(response.body)
|
488
484
|
Rails.logger.debug("Response SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
|
489
485
|
|
@@ -530,26 +526,34 @@ module ZuoraAPI
|
|
530
526
|
sleep(timeout_sleep_interval)
|
531
527
|
retry
|
532
528
|
rescue *CONNECTION_READ_EXCEPTIONS => ex
|
533
|
-
if
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
retry
|
529
|
+
if tries.zero?
|
530
|
+
if output_exception_messages
|
531
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
532
|
+
Rails.logger.error("SOAP Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
533
|
+
else
|
534
|
+
Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
535
|
+
end
|
541
536
|
end
|
537
|
+
raise ex
|
542
538
|
end
|
543
539
|
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
540
|
+
tries -= 1
|
541
|
+
|
542
|
+
if ex.is_a?(Errno::ECONNRESET) && ex.message.include?('SSL_connect')
|
543
|
+
retry
|
544
|
+
elsif timeout_retry
|
545
|
+
sleep(timeout_sleep_interval)
|
546
|
+
retry
|
547
|
+
else
|
548
|
+
if output_exception_messages
|
549
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
550
|
+
Rails.logger.error("SOAP Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
551
|
+
else
|
552
|
+
Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
553
|
+
end
|
549
554
|
end
|
555
|
+
raise ex
|
550
556
|
end
|
551
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
552
|
-
raise ex
|
553
557
|
rescue => ex
|
554
558
|
raise ex
|
555
559
|
else
|
@@ -557,33 +561,24 @@ module ZuoraAPI
|
|
557
561
|
end
|
558
562
|
|
559
563
|
def raise_errors(type: :SOAP, body: nil, response: nil)
|
560
|
-
|
561
|
-
|
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
|
564
|
+
request = response.request
|
565
|
+
match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request.path.path}"
|
571
566
|
|
572
567
|
if [502,503].include?(response.code)
|
573
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{
|
568
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{response.request.uri}", response)
|
574
569
|
end
|
575
570
|
|
576
571
|
# Check failure response code
|
577
572
|
case response.code
|
578
573
|
when 504
|
579
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{
|
574
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{response.request.uri}", response)
|
580
575
|
when 429
|
581
576
|
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)
|
582
577
|
when 401
|
583
578
|
|
584
579
|
else
|
585
580
|
if body.class == Hash
|
586
|
-
case
|
581
|
+
case response.request.path.path
|
587
582
|
when /^\/v1\/connections$/
|
588
583
|
response_headers = response.headers.to_h
|
589
584
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Missing cookies for authentication call", response) if response_headers['set-cookie'].blank?
|
@@ -607,7 +602,7 @@ module ZuoraAPI
|
|
607
602
|
reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
608
603
|
if reason.present?
|
609
604
|
message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
610
|
-
error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response
|
605
|
+
error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
|
611
606
|
else
|
612
607
|
error = 'FATAL_ERROR'
|
613
608
|
message = 'Export failed due to unknown reason. Consult api logs.'
|
@@ -629,10 +624,23 @@ module ZuoraAPI
|
|
629
624
|
end
|
630
625
|
end
|
631
626
|
|
632
|
-
|
633
|
-
|
627
|
+
if (response.code == 400 && response.headers.fetch('content-type', []).include?('text/html'))
|
628
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
629
|
+
elsif response.code == 500
|
630
|
+
if response.headers.fetch('content-type', []).include?('application/json')
|
631
|
+
begin
|
632
|
+
output_json = JSON.parse(response.body)
|
633
|
+
self.raise_errors(type: :JSON, body: output_json, response: response)
|
634
|
+
rescue JSON::ParserError => ex
|
635
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
636
|
+
end
|
637
|
+
else
|
638
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
634
642
|
when :JSON
|
635
|
-
case
|
643
|
+
case request.path.path
|
636
644
|
when /^\/query\/jobs.*/ #DataQuery Paths
|
637
645
|
return if body.class != Hash
|
638
646
|
case match_string
|
@@ -652,7 +660,7 @@ module ZuoraAPI
|
|
652
660
|
if reporting_message&.include?("com.zuora.rest.RestUsageException: The user does not have permissions for this API.")
|
653
661
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(reporting_message, response)
|
654
662
|
elsif reporting_message&.include?("500 Internal Server Error")
|
655
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Internal Server Error. The Reporting API is down. Contact Support."
|
663
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Internal Server Error. The Reporting API is down. Contact Support.")
|
656
664
|
end
|
657
665
|
case match_string
|
658
666
|
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.
|
@@ -718,6 +726,7 @@ module ZuoraAPI
|
|
718
726
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
|
719
727
|
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
|
720
728
|
end
|
729
|
+
|
721
730
|
#Internal Server Error
|
722
731
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(60)
|
723
732
|
if messages_array.uniq.size == 1
|
@@ -728,11 +737,6 @@ module ZuoraAPI
|
|
728
737
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("#{messages_array.join(', ')}", response)
|
729
738
|
end
|
730
739
|
|
731
|
-
#Retryiable Service Error
|
732
|
-
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(61)
|
733
|
-
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new("#{messages_array.join(', ')}", response)
|
734
|
-
end
|
735
|
-
|
736
740
|
#Request exceeded limit
|
737
741
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
|
738
742
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
|
@@ -785,56 +789,26 @@ module ZuoraAPI
|
|
785
789
|
end
|
786
790
|
end
|
787
791
|
|
788
|
-
if body.class == Hash && body['message'].present?
|
789
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response) if response.code == 500
|
790
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response) if ![200,201].include?(response.code)
|
791
|
-
end
|
792
|
-
|
793
|
-
self.errors_via_content_type(response: response, type: :json)
|
794
|
-
|
795
792
|
#All other errors
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
elsif response_content_types.include?('text/html')
|
812
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Akamai Error", response) if response.headers.fetch('server', '') == 'AkamaiGHost'
|
813
|
-
|
814
|
-
parse_body = Nokogiri::HTML(response.body)
|
815
|
-
error_title = parse_body.xpath('//h2').text
|
816
|
-
error_title = parse_body.xpath('//h1').text if error_title.blank?
|
817
|
-
error_message = parse_body.xpath('//p').text
|
818
|
-
|
819
|
-
error_message = error_title if error_message.blank?
|
820
|
-
|
821
|
-
if error_title.present?
|
822
|
-
case error_title
|
823
|
-
when /Service Unavailable/
|
824
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
|
825
|
-
when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
|
826
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
827
|
-
else
|
828
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
793
|
+
if response.code == 500
|
794
|
+
if body.class == Hash && body['message'].present?
|
795
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response)
|
796
|
+
else
|
797
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
798
|
+
end
|
799
|
+
elsif ![200,201].include?(response.code)
|
800
|
+
if body['message'].present?
|
801
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response)
|
802
|
+
else
|
803
|
+
if 403 == response.code && response.body.include?("Forbidden")
|
804
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
|
805
|
+
else
|
806
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response)
|
807
|
+
end
|
829
808
|
end
|
830
809
|
end
|
831
|
-
|
832
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Http response body is missing", response) if response.body.blank?
|
833
810
|
end
|
834
|
-
|
835
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response) if response.code == 500
|
836
811
|
end
|
837
|
-
|
838
812
|
|
839
813
|
def get_soap_error_and_message(body)
|
840
814
|
error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
|
@@ -898,9 +872,9 @@ module ZuoraAPI
|
|
898
872
|
when /.*UNEXPECTED_ERROR/
|
899
873
|
raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message, response, errors, success)
|
900
874
|
when /.*soapenv:Server.*/
|
901
|
-
if /^Invalid value.*for type.*|^Id is invalid
|
875
|
+
if /^Invalid value.*for type.*|^Id is invalid/.match(message).present?
|
902
876
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
903
|
-
elsif /^Invalid white space character \(.*\) in text to output
|
877
|
+
elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
|
904
878
|
raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
|
905
879
|
end
|
906
880
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
|
@@ -1051,7 +1025,7 @@ module ZuoraAPI
|
|
1051
1025
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
1052
1026
|
|
1053
1027
|
begin
|
1054
|
-
|
1028
|
+
response = HTTParty::Request.new(
|
1055
1029
|
"Net::HTTP::#{method.to_s.capitalize}".constantize,
|
1056
1030
|
url,
|
1057
1031
|
body: body,
|
@@ -1059,9 +1033,7 @@ module ZuoraAPI
|
|
1059
1033
|
timeout: timeout,
|
1060
1034
|
multipart: multipart,
|
1061
1035
|
stream_body: stream_body
|
1062
|
-
)
|
1063
|
-
|
1064
|
-
response = request.perform(&block)
|
1036
|
+
).perform(&block)
|
1065
1037
|
|
1066
1038
|
Rails.logger.debug("Response Code: #{response.code}") if debug
|
1067
1039
|
begin
|
@@ -1128,25 +1100,34 @@ module ZuoraAPI
|
|
1128
1100
|
sleep(timeout_sleep_interval)
|
1129
1101
|
retry
|
1130
1102
|
rescue *CONNECTION_READ_EXCEPTIONS => ex
|
1131
|
-
if
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1103
|
+
if tries.zero?
|
1104
|
+
if output_exception_messages
|
1105
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
1106
|
+
Rails.logger.error("Rest Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
1107
|
+
else
|
1108
|
+
Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
1109
|
+
end
|
1138
1110
|
end
|
1111
|
+
raise ex
|
1139
1112
|
end
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1113
|
+
|
1114
|
+
tries -= 1
|
1115
|
+
|
1116
|
+
if ex.is_a?(Errno::ECONNRESET) && ex.message.include?('SSL_connect')
|
1117
|
+
retry
|
1118
|
+
elsif timeout_retry
|
1119
|
+
sleep(timeout_sleep_interval)
|
1120
|
+
retry
|
1121
|
+
else
|
1122
|
+
if output_exception_messages
|
1123
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
1124
|
+
Rails.logger.error("Rest Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
1125
|
+
else
|
1126
|
+
Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
1127
|
+
end
|
1146
1128
|
end
|
1129
|
+
raise ex
|
1147
1130
|
end
|
1148
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
1149
|
-
raise ex
|
1150
1131
|
rescue => ex
|
1151
1132
|
raise ex
|
1152
1133
|
else
|
@@ -1202,8 +1183,6 @@ module ZuoraAPI
|
|
1202
1183
|
def get_file(url: nil, headers: {}, z_session: true, tempfile: true, output_file_name: nil, zuora_track_id: nil, add_timestamp: true, file_path: defined?(Rails.root.join('tmp')) ? Rails.root.join('tmp') : Pathname.new(Dir.pwd), timeout_retries: 3, timeout: 120, session_type: :basic, **execute_params)
|
1203
1184
|
raise "file_path must be of class Pathname" if file_path.class != Pathname
|
1204
1185
|
|
1205
|
-
retry_count ||= timeout_retries
|
1206
|
-
|
1207
1186
|
#Make sure directory exists
|
1208
1187
|
require 'fileutils'
|
1209
1188
|
FileUtils.mkdir_p(file_path) unless File.exists?(file_path)
|
@@ -1221,6 +1200,7 @@ module ZuoraAPI
|
|
1221
1200
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1222
1201
|
|
1223
1202
|
response_save = nil
|
1203
|
+
retry_count ||= timeout_retries
|
1224
1204
|
http.request_get(uri.request_uri, headers) do |response|
|
1225
1205
|
response_save = response
|
1226
1206
|
status_code = response.code if response
|
@@ -1328,122 +1308,75 @@ module ZuoraAPI
|
|
1328
1308
|
end
|
1329
1309
|
end
|
1330
1310
|
|
1331
|
-
def getDataSourceExport(query, extract: true, encrypted: false, zip: true
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
xml['ns1'].SessionHeader do
|
1338
|
-
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
1339
|
-
end
|
1311
|
+
def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
|
1312
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
1313
|
+
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
|
1314
|
+
xml['SOAP-ENV'].Header do
|
1315
|
+
xml['ns1'].SessionHeader do
|
1316
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
|
1340
1317
|
end
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1318
|
+
end
|
1319
|
+
xml['SOAP-ENV'].Body do
|
1320
|
+
xml['ns1'].create do
|
1321
|
+
xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
|
1322
|
+
xml['ns2'].Format 'csv'
|
1323
|
+
xml['ns2'].Zip zip
|
1324
|
+
xml['ns2'].Name 'googman'
|
1325
|
+
xml['ns2'].Query query
|
1326
|
+
xml['ns2'].Encrypted encrypted
|
1350
1327
|
end
|
1351
1328
|
end
|
1352
1329
|
end
|
1353
1330
|
end
|
1331
|
+
end
|
1354
1332
|
|
1355
|
-
|
1356
|
-
|
1357
|
-
output_xml = Nokogiri::XML(response_query.body)
|
1358
|
-
raise_errors(type: :SOAP, body: output_xml, response: response_query) if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
1333
|
+
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)
|
1359
1334
|
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1335
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1336
|
+
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"
|
1337
|
+
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1363
1338
|
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
end
|
1339
|
+
confirmRequest = Nokogiri::XML::Builder.new do |xml|
|
1340
|
+
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
|
1341
|
+
xml['SOAP-ENV'].Header do
|
1342
|
+
xml['ns1'].SessionHeader do
|
1343
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
|
1370
1344
|
end
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1345
|
+
end
|
1346
|
+
xml['SOAP-ENV'].Body do
|
1347
|
+
xml['ns1'].query do
|
1348
|
+
xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
|
1375
1349
|
end
|
1376
1350
|
end
|
1377
1351
|
end
|
1378
|
-
|
1379
|
-
|
1380
|
-
while result != "Completed"
|
1381
|
-
sleep 3
|
1382
|
-
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)
|
1383
|
-
|
1384
|
-
output_xml = Nokogiri::XML(response_query.body)
|
1385
|
-
result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
|
1386
|
-
status_code = response_query.code if response_query
|
1387
|
-
|
1388
|
-
raise_errors(type: :SOAP, body: output_xml, response: response_query) if result.blank? || result == "Failed"
|
1389
|
-
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if result.blank? || result == "Failed"
|
1390
|
-
end
|
1391
|
-
|
1392
|
-
file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
|
1393
|
-
export_file = get_file(:url => self.fileURL(file_id))
|
1394
|
-
export_file_path = export_file.path
|
1395
|
-
Rails.logger.debug("=====> Export path #{export_file.path}")
|
1396
|
-
|
1397
|
-
if extract && zip
|
1398
|
-
require "zip"
|
1399
|
-
new_path = export_file_path.partition('.zip').first
|
1400
|
-
zipped = Zip::File.open(export_file_path)
|
1401
|
-
file_handle = zipped.entries.first
|
1402
|
-
file_handle.extract(new_path)
|
1403
|
-
File.delete(export_file_path)
|
1404
|
-
return new_path
|
1405
|
-
else
|
1406
|
-
return export_file_path
|
1407
|
-
end
|
1408
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
1409
|
-
if !(tries -= 1).zero?
|
1410
|
-
Rails.logger.info("Export call failed - Trace ID: #{z_track_id}")
|
1411
|
-
self.new_session
|
1412
|
-
retry
|
1413
|
-
else
|
1414
|
-
raise ex
|
1415
|
-
end
|
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
|
-
|
1426
|
-
rescue *ZUORA_API_ERRORS => ex
|
1427
|
-
raise ex
|
1352
|
+
end
|
1353
|
+
result = 'Waiting'
|
1428
1354
|
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
sleep 5
|
1433
|
-
retry
|
1434
|
-
else
|
1435
|
-
raise ex
|
1436
|
-
end
|
1355
|
+
while result != "Completed"
|
1356
|
+
sleep 3
|
1357
|
+
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)
|
1437
1358
|
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
end
|
1359
|
+
output_xml = Nokogiri::XML(response_query.body)
|
1360
|
+
result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
|
1361
|
+
status_code = response_query.code if response_query
|
1362
|
+
raise "Export Creation Unsuccessful : #{output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}" if result.blank? || result == "Failed"
|
1363
|
+
end
|
1444
1364
|
|
1445
|
-
|
1446
|
-
|
1365
|
+
file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
|
1366
|
+
export_file = get_file(:url => self.fileURL(file_id))
|
1367
|
+
export_file_path = export_file.path
|
1368
|
+
Rails.logger.debug("=====> Export path #{export_file.path}")
|
1369
|
+
|
1370
|
+
if extract && zip
|
1371
|
+
require "zip"
|
1372
|
+
new_path = export_file_path.partition('.zip').first
|
1373
|
+
zipped = Zip::File.open(export_file_path)
|
1374
|
+
file_handle = zipped.entries.first
|
1375
|
+
file_handle.extract(new_path)
|
1376
|
+
File.delete(export_file_path)
|
1377
|
+
return new_path
|
1378
|
+
else
|
1379
|
+
return export_file_path
|
1447
1380
|
end
|
1448
1381
|
end
|
1449
1382
|
|
@@ -46,28 +46,34 @@ 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
|
49
55
|
end
|
50
|
-
raise ex if errors.include?(ex.class)
|
51
|
-
return [output_json, response]
|
52
|
-
|
53
56
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
if errors.include?(ex.class)
|
58
|
+
raise ex
|
59
|
+
else
|
60
|
+
return [output_json, response]
|
61
|
+
end
|
57
62
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
58
63
|
if !tries.zero?
|
59
64
|
tries -= 1
|
60
65
|
sleep(self.timeout_sleep)
|
61
66
|
retry
|
62
|
-
end
|
63
|
-
if Rails.logger.class.to_s == "Ougai::Logger"
|
64
|
-
Rails.logger.error("OAuthLogin - Timed out", ex)
|
65
67
|
else
|
66
|
-
Rails.logger.
|
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
|
67
76
|
end
|
68
|
-
self.current_error = "Request timed out. Try again"
|
69
|
-
self.status = 'Timeout'
|
70
|
-
return self.status
|
71
77
|
end
|
72
78
|
|
73
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.65
|
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-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,9 +182,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: '0'
|
188
188
|
requirements: []
|
189
189
|
rubygems_version: 3.0.3
|
190
190
|
signing_key:
|