zuora_api 1.7.66m → 1.7.66
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 -2
- data/Gemfile +1 -1
- data/lib/zuora_api/exceptions.rb +2 -16
- data/lib/zuora_api/login.rb +223 -310
- data/lib/zuora_api/logins/basic.rb +101 -10
- data/lib/zuora_api/logins/oauth.rb +84 -24
- data/lib/zuora_api/version.rb +1 -1
- data/zuora_api.gemspec +2 -3
- metadata +10 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff05150108e2fbba1a069083c46b53d4b43d95d95d4cfb4bcd82d10881e80091
|
|
4
|
+
data.tar.gz: b8543c688b33ee85357716df5e1f93b7cafef3702074914355aa30960b8726dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b2a8309a4a1c88a13be63df6eb96c08d27e25076b379c740b7eddd1898a60f46249388e7279d98e67fd72469e49f1a6abdc5c7f3a62aa32905909c100de46ad
|
|
7
|
+
data.tar.gz: 0a706abfa46ed54f332f903a2af7c118dfda2aaa6f61a280b9c2f989fb19790484aefcabed72bbcdc9b5ab37a2befb46913d2771ab6a924095c34ec80a8a595c
|
data/.gitlab-ci.yml
CHANGED
data/Gemfile
CHANGED
data/lib/zuora_api/exceptions.rb
CHANGED
|
@@ -40,19 +40,6 @@ module ZuoraAPI
|
|
|
40
40
|
def to_s
|
|
41
41
|
@message || @default_message
|
|
42
42
|
end
|
|
43
|
-
|
|
44
|
-
def parse_message(message)
|
|
45
|
-
case message
|
|
46
|
-
when /^Invalid Oauth Client Id$/, /^Unable to generate token.$/
|
|
47
|
-
@message = "Invalid login, please check client ID and Client Secret or URL endpoint"
|
|
48
|
-
when /^Forbidden$/
|
|
49
|
-
@message = "The user associated to OAuth credential set has been deactivated."
|
|
50
|
-
when /^Invalid login. User name and password do not match.$/
|
|
51
|
-
@message = "Invalid login, please check username and password or URL endpoint"
|
|
52
|
-
else
|
|
53
|
-
@message = message
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
43
|
end
|
|
57
44
|
|
|
58
45
|
class BadEntityError < Error
|
|
@@ -190,15 +177,14 @@ module ZuoraAPI
|
|
|
190
177
|
end
|
|
191
178
|
|
|
192
179
|
class ZuoraAPITemporaryError < Error
|
|
193
|
-
attr_reader :code, :response
|
|
180
|
+
attr_reader :code, :response
|
|
194
181
|
attr_writer :default_message
|
|
195
182
|
|
|
196
|
-
def initialize(message = nil,
|
|
183
|
+
def initialize(message = nil,response=nil, errors = [], successes = [], *args)
|
|
197
184
|
@code = response.class.to_s == "HTTParty::Response" ? response.code : nil
|
|
198
185
|
@message = parse_message(message)
|
|
199
186
|
@response = response
|
|
200
187
|
@default_message = "There is a temporary error with zuora system."
|
|
201
|
-
@errors = errors
|
|
202
188
|
end
|
|
203
189
|
|
|
204
190
|
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
|
|
|
@@ -374,8 +374,8 @@ module ZuoraAPI
|
|
|
374
374
|
return domain ? endpoint.concat(prefix).concat(url) : prefix.concat(url)
|
|
375
375
|
end
|
|
376
376
|
|
|
377
|
-
def rest_domain
|
|
378
|
-
return URI(
|
|
377
|
+
def rest_domain
|
|
378
|
+
return URI(self.rest_endpoint).host
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
def fileURL(url="")
|
|
@@ -387,41 +387,10 @@ module ZuoraAPI
|
|
|
387
387
|
end
|
|
388
388
|
|
|
389
389
|
def new_session(auth_type: :basic, debug: false, zuora_track_id: nil)
|
|
390
|
-
tries ||= 2
|
|
391
|
-
yield
|
|
392
|
-
|
|
393
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
|
394
|
-
self.status = 'Inactive/Invalid'
|
|
395
|
-
self.current_error = ex.message
|
|
396
|
-
raise
|
|
397
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPIError => ex
|
|
398
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(ex.message, ex.response)
|
|
399
|
-
|
|
400
|
-
rescue ZuoraAPI::Exceptions::ZuoraAPIInternalServerError => ex
|
|
401
|
-
raise ex if tries.zero?
|
|
402
|
-
|
|
403
|
-
tries -= 1
|
|
404
|
-
sleep(self.timeout_sleep)
|
|
405
|
-
retry
|
|
406
|
-
|
|
407
|
-
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
|
408
|
-
self.log(location: "BasicLogin", exception: ex, message: "Timed out", level: :error)
|
|
409
|
-
|
|
410
|
-
self.current_error = "Request timed out. Try again"
|
|
411
|
-
self.status = 'Timeout'
|
|
412
|
-
|
|
413
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
|
|
414
|
-
|
|
415
|
-
rescue EOFError
|
|
416
|
-
if self.url.match?(/.*services\d{1,}.zuora.com*/)
|
|
417
|
-
self.current_error = "Services tenant '#{self.url.scan(/.*\/\/(services\d{1,}).zuora.com*/).last.first}' is no longer available."
|
|
418
|
-
self.status = 'Not Available'
|
|
419
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
|
|
420
|
-
end
|
|
421
|
-
|
|
422
390
|
end
|
|
423
391
|
|
|
424
392
|
def get_session(prefix: false, auth_type: :basic, zuora_track_id: nil)
|
|
393
|
+
Rails.logger.debug("Get session for #{auth_type} - #{self.class.to_s}") if Rails.env.to_s == 'development'
|
|
425
394
|
case auth_type
|
|
426
395
|
when :basic
|
|
427
396
|
if self.current_session.blank?
|
|
@@ -430,13 +399,14 @@ module ZuoraAPI
|
|
|
430
399
|
if self.bearer_token.blank? || self.oauth_expired?
|
|
431
400
|
self.new_session(auth_type: :bearer, zuora_track_id: zuora_track_id)
|
|
432
401
|
end
|
|
433
|
-
self.get_z_session(zuora_track_id: zuora_track_id)
|
|
402
|
+
self.get_z_session(zuora_track_id: zuora_track_id) if self.status == 'Active'
|
|
434
403
|
when 'ZuoraAPI::Basic'
|
|
435
404
|
self.new_session(auth_type: :basic, zuora_track_id: zuora_track_id)
|
|
436
405
|
else
|
|
437
406
|
self.new_session(auth_type: :basic, zuora_track_id: zuora_track_id)
|
|
438
407
|
end
|
|
439
408
|
end
|
|
409
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if self.status != 'Active'
|
|
440
410
|
return prefix ? "ZSession #{self.current_session}" : self.current_session.to_s
|
|
441
411
|
when :bearer
|
|
442
412
|
case self.class.to_s
|
|
@@ -449,6 +419,8 @@ module ZuoraAPI
|
|
|
449
419
|
else
|
|
450
420
|
raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Unknown Login, does not support Authentication of Type: #{auth_type}")
|
|
451
421
|
end
|
|
422
|
+
|
|
423
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if self.status != 'Active'
|
|
452
424
|
return prefix ? "Bearer #{self.bearer_token}" : self.bearer_token.to_s
|
|
453
425
|
end
|
|
454
426
|
end
|
|
@@ -456,18 +428,16 @@ module ZuoraAPI
|
|
|
456
428
|
def soap_call(
|
|
457
429
|
ns1: 'ns1',
|
|
458
430
|
ns2: 'ns2',
|
|
459
|
-
batch_size: nil,
|
|
460
|
-
headers: {},
|
|
431
|
+
batch_size: nil,
|
|
461
432
|
single_transaction: false,
|
|
462
433
|
debug: false,
|
|
463
434
|
zuora_track_id: nil,
|
|
464
435
|
errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError].concat(ZUORA_API_ERRORS),
|
|
465
436
|
z_session: true,
|
|
466
437
|
timeout_retry: false,
|
|
467
|
-
timeout:
|
|
438
|
+
timeout: 120,
|
|
468
439
|
timeout_sleep_interval: self.timeout_sleep,
|
|
469
440
|
output_exception_messages: true,
|
|
470
|
-
skip_session: false,
|
|
471
441
|
**keyword_args)
|
|
472
442
|
tries ||= 2
|
|
473
443
|
xml = Nokogiri::XML::Builder.new do |xml|
|
|
@@ -477,10 +447,8 @@ module ZuoraAPI
|
|
|
477
447
|
'xmlns:api' => "http://api.zuora.com/",
|
|
478
448
|
"xmlns:#{ns1}" => "http://api.zuora.com/") do
|
|
479
449
|
xml['SOAP-ENV'].Header do
|
|
480
|
-
|
|
481
|
-
xml["#{ns1}"].
|
|
482
|
-
xml["#{ns1}"].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: zuora_track_id)
|
|
483
|
-
end
|
|
450
|
+
xml["#{ns1}"].SessionHeader do
|
|
451
|
+
xml["#{ns1}"].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: zuora_track_id)
|
|
484
452
|
end
|
|
485
453
|
if single_transaction
|
|
486
454
|
xml["#{ns1}"].CallOptions do
|
|
@@ -498,11 +466,12 @@ module ZuoraAPI
|
|
|
498
466
|
end
|
|
499
467
|
end
|
|
500
468
|
end
|
|
469
|
+
|
|
501
470
|
input_xml = Nokogiri::XML(xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip)
|
|
502
471
|
input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
|
|
503
472
|
Rails.logger.debug("Request SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
|
|
504
473
|
|
|
505
|
-
headers
|
|
474
|
+
headers = { 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'}
|
|
506
475
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
|
507
476
|
|
|
508
477
|
request = HTTParty::Request.new(
|
|
@@ -519,11 +488,7 @@ module ZuoraAPI
|
|
|
519
488
|
Rails.logger.debug("Response SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
|
|
520
489
|
|
|
521
490
|
raise_errors(type: :SOAP, body: output_xml, response: response)
|
|
522
|
-
|
|
523
|
-
return output_xml, input_xml, response
|
|
524
|
-
|
|
525
491
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
|
526
|
-
raise if skip_session
|
|
527
492
|
if !tries.zero? && z_session
|
|
528
493
|
tries -= 1
|
|
529
494
|
Rails.logger.debug("SOAP Call - Session Invalid")
|
|
@@ -535,33 +500,39 @@ module ZuoraAPI
|
|
|
535
500
|
end
|
|
536
501
|
|
|
537
502
|
retry
|
|
503
|
+
else
|
|
504
|
+
if errors.include?(ex.class)
|
|
505
|
+
raise ex
|
|
506
|
+
else
|
|
507
|
+
return output_xml, input_xml, response
|
|
508
|
+
end
|
|
538
509
|
end
|
|
539
|
-
|
|
540
|
-
raise ex if errors.include?(ex.class)
|
|
541
|
-
|
|
542
|
-
return output_xml, input_xml, response
|
|
543
|
-
|
|
544
510
|
rescue *ZUORA_API_ERRORS => ex
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
511
|
+
if errors.include?(ex.class)
|
|
512
|
+
raise ex
|
|
513
|
+
else
|
|
514
|
+
response = ex.response unless response
|
|
515
|
+
return output_xml, input_xml, response
|
|
516
|
+
end
|
|
550
517
|
rescue *CONNECTION_EXCEPTIONS => ex
|
|
551
|
-
if
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
518
|
+
if tries.zero?
|
|
519
|
+
if output_exception_messages
|
|
520
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
521
|
+
Rails.logger.error("SOAP Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
|
522
|
+
else
|
|
523
|
+
Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
|
524
|
+
end
|
|
525
|
+
end
|
|
526
|
+
raise ex
|
|
556
527
|
end
|
|
557
528
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
529
|
+
tries -= 1
|
|
530
|
+
sleep(timeout_sleep_interval)
|
|
531
|
+
retry
|
|
561
532
|
rescue *CONNECTION_READ_EXCEPTIONS => ex
|
|
562
533
|
if !tries.zero?
|
|
563
534
|
tries -= 1
|
|
564
|
-
|
|
535
|
+
|
|
565
536
|
if ex.is_a?(Errno::ECONNRESET) && ex.message.include?('SSL_connect')
|
|
566
537
|
retry
|
|
567
538
|
elsif timeout_retry
|
|
@@ -570,79 +541,19 @@ module ZuoraAPI
|
|
|
570
541
|
end
|
|
571
542
|
end
|
|
572
543
|
|
|
573
|
-
|
|
574
|
-
|
|
544
|
+
if output_exception_messages
|
|
545
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
546
|
+
Rails.logger.error("SOAP Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
|
547
|
+
else
|
|
548
|
+
Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
|
549
|
+
end
|
|
550
|
+
end
|
|
551
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
|
575
552
|
raise ex
|
|
576
|
-
|
|
577
553
|
rescue => ex
|
|
578
554
|
raise ex
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
end
|
|
582
|
-
|
|
583
|
-
def error_logger(ex)
|
|
584
|
-
exception_args = Rails.logger.with_fields.merge(self.exception_args(ex))
|
|
585
|
-
case ex
|
|
586
|
-
when ZuoraAPI::Exceptions::ZuoraAPIUnkownError, ZuoraAPI::Exceptions::ZuoraDataIntegrity
|
|
587
|
-
Rails.logger.error('Zuora Unknown/Integrity Error', ex, exception_args)
|
|
588
|
-
when ZuoraAPI::Exceptions::ZuoraAPIRequestLimit
|
|
589
|
-
Rails.logger.info('Zuora APILimit Reached', exception_args)
|
|
590
|
-
when *(ZuoraAPI::Login::ZUORA_API_ERRORS-ZuoraAPI::Login::ZUORA_SERVER_ERRORS)
|
|
591
|
-
#Rails.logger.debug('Zuora API Error', ex, self.exception_args(ex))
|
|
592
|
-
when *ZuoraAPI::Login::ZUORA_SERVER_ERRORS
|
|
593
|
-
Rails.logger.error('Zuora Server Error', ex, exception_args)
|
|
594
|
-
end
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
def log(location: "Rest Call", exception: nil, message: "Timed out will retry after #{self.timeout_sleep} seconds", level: :info )
|
|
598
|
-
level = :debug if ![:debug, :info, :warn, :error, :fatal].include?(level)
|
|
599
|
-
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
600
|
-
Rails.logger.send(level.to_sym, "#{location} - #{message}", exception)
|
|
601
|
-
else
|
|
602
|
-
Rails.logger.send(level.to_sym, "#{location} - #{exception.class} #{message}")
|
|
603
|
-
end
|
|
604
|
-
end
|
|
605
|
-
|
|
606
|
-
def exception_args(ex)
|
|
607
|
-
args = {}
|
|
608
|
-
if ex.class == ZuoraAPI::Exceptions::ZuoraAPIRequestLimit
|
|
609
|
-
args.merge!({
|
|
610
|
-
zuora_trace_id: ex.response.headers["zuora-request-id"],
|
|
611
|
-
zuora_track_id: ex.response.request.options[:headers]["Zuora-Track-Id"]
|
|
612
|
-
})
|
|
613
|
-
elsif defined?(ex.response) && ex.response.present?
|
|
614
|
-
args.merge!({
|
|
615
|
-
request: {
|
|
616
|
-
path: ex.response.request.path.to_s,
|
|
617
|
-
method: ex.response.request.http_method.to_s.split("Net::HTTP::").last.upcase,
|
|
618
|
-
params: ex.response.request.raw_body.to_s,
|
|
619
|
-
headers: ex.response.request.options[:headers].map{|k,v| [k.to_s, k.to_s.downcase.strip == "authorization" ? "VALUE FILTERED" : v]}.to_h.to_s,
|
|
620
|
-
},
|
|
621
|
-
response: {
|
|
622
|
-
status: ex.response.code,
|
|
623
|
-
params: ex.response.body.to_s,
|
|
624
|
-
headers: ex.response.headers.to_s,
|
|
625
|
-
},
|
|
626
|
-
zuora_trace_id: ex.response.headers["zuora-request-id"],
|
|
627
|
-
zuora_track_id: ex.response.request.options[:headers]["Zuora-Track-Id"],
|
|
628
|
-
})
|
|
629
|
-
elsif defined?(ex.request) && ex.request.present?
|
|
630
|
-
args.merge!({
|
|
631
|
-
request: {
|
|
632
|
-
path: ex.request.path.to_s,
|
|
633
|
-
method: ex.request.http_method.to_s.split("Net::HTTP::").last.upcase,
|
|
634
|
-
params: ex.request.options[:body],
|
|
635
|
-
headers: ex.request.options[:headers].map{|k,v| [k.to_s, k.to_s.downcase.strip == "authorization" ? "VALUE FILTERED" : v]}.to_h.to_s
|
|
636
|
-
}
|
|
637
|
-
})
|
|
638
|
-
args.merge!({
|
|
639
|
-
zuora_track_id: ex.request.options[:headers]["Zuora-Track-Id"]
|
|
640
|
-
}) if ex.request.options[:headers]["Zuora-Track-Id"].present?
|
|
641
|
-
end
|
|
642
|
-
rescue => ex
|
|
643
|
-
Rails.logger.error("Failed to create exception arguments", ex, args)
|
|
644
|
-
ensure
|
|
645
|
-
return args
|
|
555
|
+
else
|
|
556
|
+
return output_xml, input_xml, response
|
|
646
557
|
end
|
|
647
558
|
|
|
648
559
|
def raise_errors(type: :SOAP, body: nil, response: nil)
|
|
@@ -659,13 +570,13 @@ module ZuoraAPI
|
|
|
659
570
|
end
|
|
660
571
|
|
|
661
572
|
if [502,503].include?(response.code)
|
|
662
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from
|
|
573
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{request_uri}", response)
|
|
663
574
|
end
|
|
664
575
|
|
|
665
576
|
# Check failure response code
|
|
666
577
|
case response.code
|
|
667
578
|
when 504
|
|
668
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from
|
|
579
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{request_uri}", response)
|
|
669
580
|
when 429
|
|
670
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)
|
|
671
582
|
when 401
|
|
@@ -686,10 +597,6 @@ module ZuoraAPI
|
|
|
686
597
|
when :SOAP
|
|
687
598
|
error, success, message = get_soap_error_and_message(body)
|
|
688
599
|
|
|
689
|
-
if body.xpath('//fns:LoginFault', 'fns' =>'http://fault.api.zuora.com/').present?
|
|
690
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response)
|
|
691
|
-
end
|
|
692
|
-
|
|
693
600
|
if body.xpath('//ns1:queryResponse', 'ns1' => 'http://api.zuora.com/').present? &&
|
|
694
601
|
body.xpath(
|
|
695
602
|
'//ns1:records[@xsi:type="ns2:Export"]',
|
|
@@ -697,12 +604,12 @@ module ZuoraAPI
|
|
|
697
604
|
).present?
|
|
698
605
|
result = body.xpath('//ns2:Status', 'ns2' => 'http://object.api.zuora.com/').text
|
|
699
606
|
if result == 'Failed'
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
error, message = ['UNEXPECTED_ERROR', new_message] if new_message.present?
|
|
607
|
+
reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
|
608
|
+
if reason.present?
|
|
609
|
+
message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
|
|
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'
|
|
705
611
|
else
|
|
612
|
+
error = 'FATAL_ERROR'
|
|
706
613
|
message = 'Export failed due to unknown reason. Consult api logs.'
|
|
707
614
|
end
|
|
708
615
|
end
|
|
@@ -751,10 +658,6 @@ module ZuoraAPI
|
|
|
751
658
|
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.
|
|
752
659
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(reporting_message, response) if reporting_message.present?
|
|
753
660
|
end
|
|
754
|
-
when /\/objects\/batch\//
|
|
755
|
-
if body['code'].present? && /61$/.match(body['code'].to_s).present? # if last 2 digits of code are 61
|
|
756
|
-
raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new(body['message'], nil, body['details'])
|
|
757
|
-
end
|
|
758
661
|
end
|
|
759
662
|
|
|
760
663
|
body = body.dig("results").present? ? body["results"] : body if body.class == Hash
|
|
@@ -794,11 +697,7 @@ module ZuoraAPI
|
|
|
794
697
|
end
|
|
795
698
|
|
|
796
699
|
if body['error'] == 'Unauthorized' && body['status'] == 401
|
|
797
|
-
|
|
798
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(body['message'], response)
|
|
799
|
-
else
|
|
800
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{messages_array.join(', ')}", response)
|
|
801
|
-
end
|
|
700
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{messages_array.join(', ')}", response)
|
|
802
701
|
end
|
|
803
702
|
#Authentication failed
|
|
804
703
|
if (codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(11) || response.code == 401) && !codes_array.include?(422)
|
|
@@ -925,8 +824,6 @@ module ZuoraAPI
|
|
|
925
824
|
raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
|
|
926
825
|
when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
|
|
927
826
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
|
928
|
-
when /414 Request-URI Too Large/
|
|
929
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Request URL is too long", response)
|
|
930
827
|
else
|
|
931
828
|
raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
|
|
932
829
|
end
|
|
@@ -996,7 +893,7 @@ module ZuoraAPI
|
|
|
996
893
|
raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
|
|
997
894
|
end
|
|
998
895
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
|
999
|
-
when
|
|
896
|
+
when /invalid/, /^DUPLICATE_VALUE/, /^REQUEST_REJECTED/, /INVALID_ID/, /MAX_RECORDS_EXCEEDED/, /INVALID_FIELD/, /MALFORMED_QUERY/, /NO_PERMISSION/, /PDF_QUERY_ERROR/, /MISSING_REQUIRED_VALUE/, /INVALID_TYPE/, /TRANSACTION_FAILED/, /API_DISABLED/, /CANNOT_DELETE/, /ACCOUNTING_PERIOD_CLOSED/
|
|
1000
897
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
|
|
1001
898
|
when /.*UNEXPECTED_ERROR/
|
|
1002
899
|
raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message, response, errors, success)
|
|
@@ -1056,7 +953,7 @@ module ZuoraAPI
|
|
|
1056
953
|
base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
|
|
1057
954
|
url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
|
|
1058
955
|
headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id, 'Content-Type' => "text/xml; charset=utf-8"} : {'Content-Type' => "text/xml; charset=utf-8"}
|
|
1059
|
-
response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic)}.merge(headers), :timeout =>
|
|
956
|
+
response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic)}.merge(headers), :timeout => 120)
|
|
1060
957
|
|
|
1061
958
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
|
|
1062
959
|
|
|
@@ -1089,31 +986,35 @@ module ZuoraAPI
|
|
|
1089
986
|
end
|
|
1090
987
|
des_hash[:related_objects] = output_xml.xpath(".//related-objects").xpath(".//object").map{ |x| [x.xpath(".//name").text.to_sym, [ [:url, x.attributes["href"].value], [:label, x.xpath(".//name").text ] ].to_h] }.to_h
|
|
1091
988
|
end
|
|
1092
|
-
|
|
1093
|
-
return des_hash
|
|
1094
989
|
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
|
1095
|
-
if
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
990
|
+
if tries.zero?
|
|
991
|
+
if log_errors
|
|
992
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
993
|
+
Rails.logger.error("Describe - Timed out will retry after #{self.timeout_sleep} seconds", ex)
|
|
994
|
+
else
|
|
995
|
+
Rails.logger.error("Describe - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
|
|
996
|
+
end
|
|
997
|
+
end
|
|
998
|
+
raise ex
|
|
1100
999
|
end
|
|
1101
1000
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1001
|
+
tries -= 1
|
|
1002
|
+
sleep(self.timeout_sleep)
|
|
1003
|
+
retry
|
|
1105
1004
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
|
1106
1005
|
if !tries.zero? && self.status == 'Active'
|
|
1107
1006
|
tries -= 1
|
|
1108
1007
|
Rails.logger.debug("Describe session expired. Starting new session.")
|
|
1109
1008
|
self.new_session
|
|
1110
1009
|
retry
|
|
1010
|
+
else
|
|
1011
|
+
Rails.logger.error("Describe session expired. Starting new session.") if log_errors
|
|
1012
|
+
raise ex
|
|
1111
1013
|
end
|
|
1112
|
-
|
|
1113
|
-
Rails.logger.error("Describe session expired. Starting new session.") if log_errors
|
|
1114
|
-
raise ex
|
|
1115
1014
|
rescue => ex
|
|
1116
1015
|
raise ex
|
|
1016
|
+
else
|
|
1017
|
+
return des_hash
|
|
1117
1018
|
end
|
|
1118
1019
|
|
|
1119
1020
|
def rest_call(
|
|
@@ -1126,12 +1027,11 @@ module ZuoraAPI
|
|
|
1126
1027
|
z_session: true,
|
|
1127
1028
|
session_type: :basic,
|
|
1128
1029
|
timeout_retry: false,
|
|
1129
|
-
timeout:
|
|
1030
|
+
timeout: 120,
|
|
1130
1031
|
timeout_sleep_interval: self.timeout_sleep,
|
|
1131
1032
|
multipart: false,
|
|
1132
1033
|
stream_body: false,
|
|
1133
1034
|
output_exception_messages: true,
|
|
1134
|
-
zuora_track_id: nil,
|
|
1135
1035
|
**keyword_args,
|
|
1136
1036
|
&block
|
|
1137
1037
|
)
|
|
@@ -1141,13 +1041,12 @@ module ZuoraAPI
|
|
|
1141
1041
|
|
|
1142
1042
|
authentication_headers = {}
|
|
1143
1043
|
if z_session
|
|
1144
|
-
authentication_headers = {"Authorization" => self.get_session(prefix: true, auth_type: session_type
|
|
1044
|
+
authentication_headers = {"Authorization" => self.get_session(prefix: true, auth_type: session_type) }
|
|
1145
1045
|
if self.entity_id.present?
|
|
1146
1046
|
authentication_headers["Zuora-Entity-Ids"] = self.entity_id if headers.dig("Zuora-Entity-Ids").nil?
|
|
1147
1047
|
authentication_headers.delete_if { |key, value| ["entityId", "entityName"].include?(key.to_s) }
|
|
1148
1048
|
end
|
|
1149
1049
|
end
|
|
1150
|
-
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
|
1151
1050
|
|
|
1152
1051
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
|
1153
1052
|
|
|
@@ -1173,20 +1072,18 @@ module ZuoraAPI
|
|
|
1173
1072
|
Rails.logger.debug("Response JSON: #{output_json}") if debug && output_json.present?
|
|
1174
1073
|
|
|
1175
1074
|
raise_errors(type: :JSON, body: output_json, response: response)
|
|
1176
|
-
rescue
|
|
1075
|
+
rescue
|
|
1177
1076
|
reset_files(body) if multipart
|
|
1178
1077
|
raise
|
|
1179
1078
|
end
|
|
1180
|
-
|
|
1181
|
-
return [output_json, response]
|
|
1182
1079
|
rescue ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError => ex
|
|
1183
1080
|
if self.class.to_s == 'ZuoraAPI::Oauth' && ex.message.include?("Authentication type is not supported by this Login")
|
|
1184
1081
|
session_type = :bearer
|
|
1185
1082
|
retry
|
|
1083
|
+
else
|
|
1084
|
+
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
|
1085
|
+
raise ex
|
|
1186
1086
|
end
|
|
1187
|
-
Rails.logger.debug("Rest Call - Session Bad Auth type")
|
|
1188
|
-
raise ex
|
|
1189
|
-
|
|
1190
1087
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
|
1191
1088
|
if !tries.zero? && z_session
|
|
1192
1089
|
tries -= 1
|
|
@@ -1199,35 +1096,40 @@ module ZuoraAPI
|
|
|
1199
1096
|
end
|
|
1200
1097
|
|
|
1201
1098
|
retry
|
|
1099
|
+
else
|
|
1100
|
+
if errors.include?(ex.class)
|
|
1101
|
+
raise ex
|
|
1102
|
+
else
|
|
1103
|
+
return [output_json, response]
|
|
1104
|
+
end
|
|
1202
1105
|
end
|
|
1203
|
-
|
|
1204
|
-
raise ex if errors.include?(ex.class)
|
|
1205
|
-
return [output_json, response]
|
|
1206
|
-
|
|
1207
1106
|
rescue *ZUORA_API_ERRORS => ex
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1107
|
+
if errors.include?(ex.class)
|
|
1108
|
+
raise ex
|
|
1109
|
+
else
|
|
1110
|
+
response = ex.response unless response
|
|
1111
|
+
return [output_json, response]
|
|
1112
|
+
end
|
|
1213
1113
|
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
|
1214
1114
|
raise ex
|
|
1215
1115
|
rescue *CONNECTION_EXCEPTIONS => ex
|
|
1216
|
-
if
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1116
|
+
if tries.zero?
|
|
1117
|
+
if output_exception_messages
|
|
1118
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
1119
|
+
Rails.logger.error("Rest Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
|
1120
|
+
else
|
|
1121
|
+
Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
|
1122
|
+
end
|
|
1123
|
+
end
|
|
1124
|
+
raise ex
|
|
1221
1125
|
end
|
|
1222
1126
|
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1127
|
+
tries -= 1
|
|
1128
|
+
sleep(timeout_sleep_interval)
|
|
1129
|
+
retry
|
|
1226
1130
|
rescue *CONNECTION_READ_EXCEPTIONS => ex
|
|
1227
|
-
|
|
1228
1131
|
if !tries.zero?
|
|
1229
1132
|
tries -= 1
|
|
1230
|
-
self.log(location: "Rest Call", exception: ex, message: "Timed out will retry after #{timeout_sleep_interval} seconds", level: :debug)
|
|
1231
1133
|
if ex.is_a?(Errno::ECONNRESET) && ex.message.include?('SSL_connect')
|
|
1232
1134
|
retry
|
|
1233
1135
|
elsif timeout_retry
|
|
@@ -1235,15 +1137,20 @@ module ZuoraAPI
|
|
|
1235
1137
|
retry
|
|
1236
1138
|
end
|
|
1237
1139
|
end
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1140
|
+
|
|
1141
|
+
if output_exception_messages
|
|
1142
|
+
if Rails.logger.class.to_s == "Ougai::Logger"
|
|
1143
|
+
Rails.logger.error("Rest Call - Timed out will retry after #{timeout_sleep_interval} seconds", ex)
|
|
1144
|
+
else
|
|
1145
|
+
Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{timeout_sleep_interval} seconds")
|
|
1146
|
+
end
|
|
1147
|
+
end
|
|
1148
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received read timeout from #{url}", nil, request) if ex.instance_of?(Net::ReadTimeout)
|
|
1241
1149
|
raise ex
|
|
1242
|
-
|
|
1243
1150
|
rescue => ex
|
|
1244
1151
|
raise ex
|
|
1245
|
-
|
|
1246
|
-
|
|
1152
|
+
else
|
|
1153
|
+
return [output_json, response]
|
|
1247
1154
|
end
|
|
1248
1155
|
|
|
1249
1156
|
def update_create_tenant
|
|
@@ -1265,9 +1172,8 @@ module ZuoraAPI
|
|
|
1265
1172
|
while !response["nextPage"].blank?
|
|
1266
1173
|
url = self.rest_endpoint(response["nextPage"].split('/v1/').last)
|
|
1267
1174
|
Rails.logger.debug("Fetch Catalog URL #{url}")
|
|
1268
|
-
output_json, response = self.rest_call(debug
|
|
1269
|
-
|
|
1270
|
-
if !/(true|t|yes|y|1)$/.match(output_json['success'].to_s) || output_json['success'].class != TrueClass
|
|
1175
|
+
output_json, response = self.rest_call(:debug => false, :url => url, :errors => [ZuoraAPI::Exceptions::ZuoraAPISessionError], :timeout_retry => true )
|
|
1176
|
+
if !output_json['success'] =~ (/(true|t|yes|y|1)$/i) || output_json['success'].class != TrueClass
|
|
1271
1177
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Error Getting Catalog: #{output_json}", response)
|
|
1272
1178
|
end
|
|
1273
1179
|
output_json["products"].each do |product|
|
|
@@ -1293,7 +1199,7 @@ module ZuoraAPI
|
|
|
1293
1199
|
return products, catalog_map
|
|
1294
1200
|
end
|
|
1295
1201
|
|
|
1296
|
-
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:
|
|
1202
|
+
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)
|
|
1297
1203
|
raise "file_path must be of class Pathname" if file_path.class != Pathname
|
|
1298
1204
|
|
|
1299
1205
|
retry_count ||= timeout_retries
|
|
@@ -1401,17 +1307,11 @@ module ZuoraAPI
|
|
|
1401
1307
|
if !(retry_count -= 1).zero?
|
|
1402
1308
|
self.new_session
|
|
1403
1309
|
raise response.class
|
|
1310
|
+
else
|
|
1311
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
|
|
1404
1312
|
end
|
|
1405
|
-
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
|
|
1406
|
-
end
|
|
1407
|
-
raise
|
|
1408
|
-
when Net::HTTPNotFound
|
|
1409
|
-
if url.include?(self.fileURL)
|
|
1410
|
-
raise ZuoraAPI::Exceptions::FileDownloadError.new(
|
|
1411
|
-
"The current tenant does not have a file with id '#{url.split('/').last}'"
|
|
1412
|
-
)
|
|
1413
1313
|
else
|
|
1414
|
-
raise
|
|
1314
|
+
raise
|
|
1415
1315
|
end
|
|
1416
1316
|
else
|
|
1417
1317
|
raise ZuoraAPI::Exceptions::FileDownloadError.new("File Download Failed #{response.class}")
|
|
@@ -1422,120 +1322,133 @@ module ZuoraAPI
|
|
|
1422
1322
|
sleep(5)
|
|
1423
1323
|
if (retry_count -= 1) >= 0
|
|
1424
1324
|
retry
|
|
1325
|
+
else
|
|
1326
|
+
Rails.logger.error("File Download Failed")
|
|
1327
|
+
raise
|
|
1425
1328
|
end
|
|
1426
|
-
Rails.logger.error("File Download Failed")
|
|
1427
|
-
raise
|
|
1428
1329
|
end
|
|
1429
1330
|
|
|
1430
1331
|
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
xml['SOAP-ENV'].
|
|
1435
|
-
xml['
|
|
1436
|
-
xml['ns1'].
|
|
1332
|
+
begin
|
|
1333
|
+
tries ||= 3
|
|
1334
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
|
1335
|
+
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
|
|
1336
|
+
xml['SOAP-ENV'].Header do
|
|
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
|
|
1437
1340
|
end
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1341
|
+
xml['SOAP-ENV'].Body do
|
|
1342
|
+
xml['ns1'].create do
|
|
1343
|
+
xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
|
|
1344
|
+
xml['ns2'].Format 'csv'
|
|
1345
|
+
xml['ns2'].Zip zip
|
|
1346
|
+
xml['ns2'].Name 'googman'
|
|
1347
|
+
xml['ns2'].Query query
|
|
1348
|
+
xml['ns2'].Encrypted encrypted
|
|
1349
|
+
end
|
|
1447
1350
|
end
|
|
1448
1351
|
end
|
|
1449
1352
|
end
|
|
1450
1353
|
end
|
|
1451
|
-
end
|
|
1452
1354
|
|
|
1453
|
-
|
|
1355
|
+
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)
|
|
1454
1356
|
|
|
1455
|
-
|
|
1456
|
-
|
|
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"
|
|
1457
1359
|
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1360
|
+
# raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
|
|
1361
|
+
|
|
1362
|
+
id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
|
1461
1363
|
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1364
|
+
confirmRequest = Nokogiri::XML::Builder.new do |xml|
|
|
1365
|
+
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
|
|
1366
|
+
xml['SOAP-ENV'].Header do
|
|
1367
|
+
xml['ns1'].SessionHeader do
|
|
1368
|
+
xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
|
|
1369
|
+
end
|
|
1467
1370
|
end
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1371
|
+
xml['SOAP-ENV'].Body do
|
|
1372
|
+
xml['ns1'].query do
|
|
1373
|
+
xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
|
|
1374
|
+
end
|
|
1472
1375
|
end
|
|
1473
1376
|
end
|
|
1474
1377
|
end
|
|
1475
|
-
|
|
1476
|
-
result = 'Waiting'
|
|
1378
|
+
result = 'Waiting'
|
|
1477
1379
|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
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)
|
|
1481
1383
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
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
|
|
1485
1387
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
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
|
|
1489
1391
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
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
|
|
1513
1416
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
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
|
|
1521
1425
|
|
|
1522
|
-
|
|
1523
|
-
|
|
1426
|
+
rescue *ZUORA_API_ERRORS => ex
|
|
1427
|
+
raise ex
|
|
1524
1428
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1429
|
+
rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
|
|
1430
|
+
if !(tries -= 1).zero?
|
|
1431
|
+
Rails.logger.info("Trace ID: #{z_track_id} Timed out will retry after 5 seconds")
|
|
1432
|
+
sleep 5
|
|
1433
|
+
retry
|
|
1434
|
+
else
|
|
1435
|
+
raise ex
|
|
1436
|
+
end
|
|
1532
1437
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1438
|
+
rescue Errno::ECONNRESET => ex
|
|
1439
|
+
if !(tries -= 1).zero? && ex.message.include?('SSL_connect')
|
|
1440
|
+
retry
|
|
1441
|
+
else
|
|
1442
|
+
raise ex
|
|
1443
|
+
end
|
|
1444
|
+
|
|
1445
|
+
rescue ZuoraAPI::Exceptions::BadEntityError => ex
|
|
1446
|
+
raise ex
|
|
1447
|
+
end
|
|
1535
1448
|
end
|
|
1536
1449
|
|
|
1537
1450
|
def query(query, parse = false)
|
|
1538
|
-
output_xml, input_xml = self.soap_call(debug
|
|
1451
|
+
output_xml, input_xml = self.soap_call({:debug => false, :timeout_retry => true}) do |xml|
|
|
1539
1452
|
xml['ns1'].query do
|
|
1540
1453
|
xml['ns1'].queryString query
|
|
1541
1454
|
end
|