zuora_api 1.4.12b → 1.4.12
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 +0 -13
- data/lib/zuora_api.rb +0 -1
- data/lib/zuora_api/login.rb +30 -181
- data/lib/zuora_api/version.rb +1 -1
- data/zuora_api.gemspec +0 -1
- metadata +4 -19
- data/lib/zuora_api/metrics_helper.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc4bb86fbbf7590bc62e08d4f0a0159e9685d1c
|
4
|
+
data.tar.gz: 10c3a81d25f0cfd3503a4ee1ae0661249ddf8b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e52ba82573b4d98dd54417145b081488c3f8d7a3b0e4cb2fd0e92bbfd624652bbec24b165bb3281e52d505d9515ef24d89448d2a588aa41d0ea0005ccd54e5
|
7
|
+
data.tar.gz: f1dd71d072f2dea943722cf9fbc6bad92a8f536a2a02a479a03a340fa8e9111eee5c5761cf99a54f085bd9b2d77f49571ac85762b180358eab9bdf9c5e1106eb
|
data/.gitlab-ci.yml
CHANGED
@@ -48,16 +48,3 @@ rubygems-deploy:
|
|
48
48
|
- gem push $version
|
49
49
|
only:
|
50
50
|
- master
|
51
|
-
|
52
|
-
rubygems-deploy:
|
53
|
-
stage: deploy
|
54
|
-
allow_failure: false
|
55
|
-
when: manual
|
56
|
-
script:
|
57
|
-
- bundle install
|
58
|
-
- gem install rake
|
59
|
-
- version=$(rake install | grep -o 'pkg/zuora_api-.*gem')
|
60
|
-
- curl -u $USERNAME:$PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
|
61
|
-
- gem push $version
|
62
|
-
only:
|
63
|
-
- staging
|
data/lib/zuora_api.rb
CHANGED
data/lib/zuora_api/login.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require "httparty"
|
2
2
|
require "nokogiri"
|
3
|
-
require "uri"
|
4
|
-
|
5
3
|
module ZuoraAPI
|
6
4
|
class Login
|
7
5
|
ENVIRONMENTS = [SANDBOX = 'Sandbox', PRODUCTION = 'Production', PREFORMANCE = 'Preformance', SERVICES = 'Services', UNKNOWN = 'Unknown' ]
|
8
6
|
REGIONS = [EU = 'EU', US = 'US' ]
|
9
|
-
XML_SAVE_OPTIONS = Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
|
7
|
+
XML_SAVE_OPTIONS = Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
|
10
8
|
attr_accessor :username, :password, :region,:url, :wsdl_number, :current_session, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id, :timeout_sleep
|
11
9
|
|
12
10
|
def initialize(username: nil, password: nil, status: nil, url: nil, entity_id: nil, session: nil, **keyword_args)
|
@@ -43,6 +41,7 @@ module ZuoraAPI
|
|
43
41
|
}
|
44
42
|
end
|
45
43
|
|
44
|
+
|
46
45
|
def update_environment
|
47
46
|
if !self.url.blank?
|
48
47
|
env_path = self.url.split('https://').last.split('.zuora.com').first
|
@@ -115,12 +114,12 @@ module ZuoraAPI
|
|
115
114
|
end
|
116
115
|
end
|
117
116
|
end
|
118
|
-
|
117
|
+
|
119
118
|
|
120
119
|
input_xml = Nokogiri::XML(request.to_xml(:save_with => XML_SAVE_OPTIONS).strip)
|
121
120
|
input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
|
122
121
|
Rails.logger.debug('Connect') {"Request SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
123
|
-
|
122
|
+
|
124
123
|
@response_query = HTTParty.post(self.url,:body => request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => 10)
|
125
124
|
@output_xml = Nokogiri::XML(@response_query.body)
|
126
125
|
Rails.logger.debug('Connect') {"Response SOAP XML: #{@output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
@@ -175,16 +174,16 @@ module ZuoraAPI
|
|
175
174
|
else
|
176
175
|
#If Session only is used for Gem TODO Depercate
|
177
176
|
if (self.password.blank? && self.current_session.present?)
|
178
|
-
self.current_session = self.current_session
|
177
|
+
self.current_session = self.current_session
|
179
178
|
self.username = @output_xml.xpath('//ns1:Username', 'ns1' =>'http://api.zuora.com/').text if self.username.blank?
|
180
|
-
|
179
|
+
|
181
180
|
#Username & password combo
|
182
181
|
elsif (self.password.present? && self.username.present?)
|
183
182
|
retrieved_session = @output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text
|
184
183
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("No session found for api call.") if retrieved_session.blank?
|
185
184
|
self.current_session = retrieved_session
|
186
185
|
end
|
187
|
-
|
186
|
+
|
188
187
|
self.current_error = nil
|
189
188
|
self.status = 'Active'
|
190
189
|
end
|
@@ -210,9 +209,6 @@ module ZuoraAPI
|
|
210
209
|
|
211
210
|
def soap_call(ns1: 'ns1', ns2: 'ns2', batch_size: nil, single_transaction: false, debug: true, errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError, ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition], z_session: true, timeout_retry: false, timeout: 120,**keyword_args)
|
212
211
|
tries ||= 2
|
213
|
-
error_type = ""
|
214
|
-
start_time = Time.now
|
215
|
-
|
216
212
|
xml = Nokogiri::XML::Builder.new do |xml|
|
217
213
|
xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/",
|
218
214
|
"xmlns:#{ns2}" => "http://object.api.zuora.com/",
|
@@ -243,15 +239,13 @@ module ZuoraAPI
|
|
243
239
|
input_xml = Nokogiri::XML(xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip)
|
244
240
|
input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
|
245
241
|
Rails.logger.debug('Connect') {"Request SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
246
|
-
|
247
242
|
response = HTTParty.post(self.url,:body => xml.doc.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => timeout)
|
248
243
|
output_xml = Nokogiri::XML(response.body)
|
249
244
|
Rails.logger.debug('Connect') {"Response SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug
|
250
245
|
|
251
246
|
raise_errors(type: :SOAP, body: output_xml, response: response)
|
252
|
-
|
247
|
+
|
253
248
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
254
|
-
error_type = "#{ex.class}"
|
255
249
|
if !(tries -= 1).zero? && z_session
|
256
250
|
Rails.logger.debug {"Session Invalid"}
|
257
251
|
self.new_session
|
@@ -264,14 +258,12 @@ module ZuoraAPI
|
|
264
258
|
end
|
265
259
|
end
|
266
260
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
267
|
-
error_type = "#{ex.class}"
|
268
261
|
if errors.include?(ex.class)
|
269
262
|
raise ex
|
270
263
|
else
|
271
264
|
return output_xml, input_xml, response
|
272
265
|
end
|
273
266
|
rescue Net::OpenTimeout, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => ex
|
274
|
-
error_type = "#{ex.class}"
|
275
267
|
if !(tries -= 1).zero? && timeout_retry
|
276
268
|
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
277
269
|
sleep(self.timeout_sleep)
|
@@ -280,21 +272,9 @@ module ZuoraAPI
|
|
280
272
|
raise ex
|
281
273
|
end
|
282
274
|
rescue => ex
|
283
|
-
error_type = "#{ex.class}"
|
284
275
|
raise ex
|
285
276
|
else
|
286
277
|
return output_xml, input_xml, response
|
287
|
-
ensure
|
288
|
-
# Writing to telegraf
|
289
|
-
begin
|
290
|
-
end_time = Time.now
|
291
|
-
response_time = end_time - start_time
|
292
|
-
status_code = response.code if response
|
293
|
-
endpoint_name = url.present? ? URI(url).host : url
|
294
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST")
|
295
|
-
rescue
|
296
|
-
Rails.logger.info {"Failed to send metric"}
|
297
|
-
end
|
298
278
|
end
|
299
279
|
|
300
280
|
def raise_errors(type: :SOAP, body: nil, response: nil)
|
@@ -307,7 +287,7 @@ module ZuoraAPI
|
|
307
287
|
error = body.xpath('//faultcode').text
|
308
288
|
message = body.xpath('//faultstring').text
|
309
289
|
end
|
310
|
-
|
290
|
+
|
311
291
|
if error.blank? || message.blank?
|
312
292
|
error = body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text
|
313
293
|
message = body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text
|
@@ -318,9 +298,9 @@ module ZuoraAPI
|
|
318
298
|
error = []
|
319
299
|
success = []
|
320
300
|
body.xpath('//ns1:result', 'ns1' =>'http://api.zuora.com/').each_with_index do |call, object_index|
|
321
|
-
|
301
|
+
|
322
302
|
if call.xpath('./ns1:Success', 'ns1' =>'http://api.zuora.com/').text == 'false'
|
323
|
-
message = "#{call.xpath('./*/ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{call.xpath('./*/ns1:Message', 'ns1' =>'http://api.zuora.com/').text}"
|
303
|
+
message = "#{call.xpath('./*/ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{call.xpath('./*/ns1:Message', 'ns1' =>'http://api.zuora.com/').text}"
|
324
304
|
error.push(message)
|
325
305
|
else
|
326
306
|
success.push(call.xpath('./ns1:Id', 'ns1' =>'http://api.zuora.com/').text)
|
@@ -352,7 +332,7 @@ module ZuoraAPI
|
|
352
332
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", body, response.code)
|
353
333
|
end
|
354
334
|
|
355
|
-
when :JSON
|
335
|
+
when :JSON
|
356
336
|
if body.class == Hash && (!body["success"] || !body["Success"] || response.code != 200)
|
357
337
|
messages_array = (body["reasons"] || []).map {|error| error['message']}.compact
|
358
338
|
codes_array = (body["reasons"] || []).map {|error| error['code']}.compact
|
@@ -378,7 +358,7 @@ module ZuoraAPI
|
|
378
358
|
end
|
379
359
|
|
380
360
|
#All Errors catch
|
381
|
-
if codes_array.size > 0
|
361
|
+
if codes_array.size > 0
|
382
362
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{messages_array.join(', ')}", body, response.code)
|
383
363
|
end
|
384
364
|
|
@@ -395,7 +375,7 @@ module ZuoraAPI
|
|
395
375
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
396
376
|
else
|
397
377
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}", body, response.code)
|
398
|
-
end
|
378
|
+
end
|
399
379
|
end
|
400
380
|
|
401
381
|
if body["Errors"].present? || body["errors"].present?
|
@@ -407,14 +387,14 @@ module ZuoraAPI
|
|
407
387
|
end
|
408
388
|
end
|
409
389
|
end
|
410
|
-
|
390
|
+
|
411
391
|
#Zuora REST Actions error (Create, Update, Delete)
|
412
392
|
if body.class == Array
|
413
393
|
all_errors = body.select {|obj| !obj['Success'] || !obj['success'] }.map {|obj| obj['Errors'] || obj['errors'] }.compact
|
414
394
|
all_success = body.select {|obj| obj['Success'] || obj['success']}.compact
|
415
395
|
|
416
|
-
if all_errors.size > 0
|
417
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{all_errors.flatten.group_by {|error| error['Message']}.keys.uniq.join(' ')}", body, response.code, all_errors, all_success )
|
396
|
+
if all_errors.size > 0
|
397
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{all_errors.flatten.group_by {|error| error['Message']}.keys.uniq.join(' ')}", body, response.code, all_errors, all_success )
|
418
398
|
end
|
419
399
|
end
|
420
400
|
|
@@ -422,7 +402,7 @@ module ZuoraAPI
|
|
422
402
|
if response.code != 200
|
423
403
|
if response.code == 429
|
424
404
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", body, response.code)
|
425
|
-
else
|
405
|
+
else
|
426
406
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}", body, response.code)
|
427
407
|
end
|
428
408
|
end
|
@@ -469,16 +449,11 @@ module ZuoraAPI
|
|
469
449
|
|
470
450
|
def describe_call(object = nil)
|
471
451
|
tries ||= 2
|
472
|
-
|
473
|
-
error_type = ""
|
474
|
-
start_time = Time.now
|
475
|
-
|
476
452
|
self.get_session
|
477
453
|
base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
|
478
454
|
url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
|
479
455
|
headers = !self.entity_id.blank? ? {"entityId" => self.entity_id, 'Content-Type' => "text/xml; charset=utf-8"} : {'Content-Type' => "text/xml; charset=utf-8"}
|
480
|
-
response = HTTParty.get(url, :headers => headers , basic_auth: {:username => self.username, :password => self.password}, :timeout =>
|
481
|
-
|
456
|
+
response = HTTParty.get(url, :headers => headers , basic_auth: {:username => self.username, :password => self.password}, :timeout => 120)
|
482
457
|
output_xml = Nokogiri::XML(response.body)
|
483
458
|
des_hash = Hash.new
|
484
459
|
if object == nil
|
@@ -509,7 +484,6 @@ module ZuoraAPI
|
|
509
484
|
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
|
510
485
|
end
|
511
486
|
rescue Net::ReadTimeout, Net::OpenTimeout, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => ex
|
512
|
-
error_type = "#{ex.class}"
|
513
487
|
if !(tries -= 1).zero?
|
514
488
|
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
515
489
|
sleep(self.timeout_sleep)
|
@@ -518,32 +492,18 @@ module ZuoraAPI
|
|
518
492
|
raise ex
|
519
493
|
end
|
520
494
|
rescue => ex
|
521
|
-
error_type = "#{ex.class}"
|
522
495
|
raise ex
|
523
496
|
else
|
524
497
|
return des_hash
|
525
|
-
ensure
|
526
|
-
# Writing to telegraf
|
527
|
-
begin
|
528
|
-
end_time = Time.now
|
529
|
-
response_time = end_time - start_time
|
530
|
-
status_code = response.code if response
|
531
|
-
endpoint_name = url.present? ? URI(url).host : url
|
532
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "GET")
|
533
|
-
rescue
|
534
|
-
Rails.logger.info {"Failed to send metric"}
|
535
|
-
end
|
536
498
|
end
|
537
499
|
|
538
500
|
def rest_call(method: :get, body: {},headers: {}, url: rest_endpoint("catalog/products?pageSize=4"), debug: true, errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError, ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition], z_session: true, timeout_retry: false, timeout: 120, **keyword_args)
|
539
501
|
tries ||= 2
|
540
502
|
headers["entityId"] = self.entity_id if !self.entity_id.blank?
|
541
503
|
raise "Method not supported, supported methods include: :get, :post, :put, :delete, :patch, :head, :options" if ![:get, :post, :put, :delete, :patch, :head, :options].include?(method)
|
542
|
-
|
543
|
-
error_type = ""
|
544
|
-
start_time = Time.now
|
545
504
|
response = HTTParty::Request.new("Net::HTTP::#{method.to_s.capitalize}".constantize, url, body: body, headers: {'Content-Type' => "application/json; charset=utf-8"}.merge(z_session ? {"Authorization" => "ZSession #{self.get_session}"} : {}).merge(headers), timeout: timeout).perform
|
546
505
|
|
506
|
+
Rails.logger.debug('Connect') {"Response Code: #{response.code}" } if debug
|
547
507
|
begin
|
548
508
|
output_json = JSON.parse(response.body)
|
549
509
|
rescue JSON::ParserError => ex
|
@@ -554,7 +514,6 @@ module ZuoraAPI
|
|
554
514
|
raise_errors(type: :JSON, body: output_json, response: response)
|
555
515
|
|
556
516
|
rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
|
557
|
-
error_type = "#{ex.class}"
|
558
517
|
if !(tries -= 1).zero? && z_session
|
559
518
|
Rails.logger.debug {"Session Invalid"}
|
560
519
|
self.new_session
|
@@ -567,14 +526,12 @@ module ZuoraAPI
|
|
567
526
|
end
|
568
527
|
end
|
569
528
|
rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
|
570
|
-
error_type = "#{ex.class}"
|
571
529
|
if errors.include?(ex.class)
|
572
530
|
raise ex
|
573
531
|
else
|
574
532
|
return [output_json, response]
|
575
533
|
end
|
576
534
|
rescue Net::OpenTimeout, Errno::ECONNRESET, Errno::ECONNREFUSED, SocketError => ex
|
577
|
-
error_type = "#{ex.class}"
|
578
535
|
if !(tries -= 1).zero? && timeout_retry
|
579
536
|
Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"}
|
580
537
|
sleep(self.timeout_sleep)
|
@@ -583,21 +540,9 @@ module ZuoraAPI
|
|
583
540
|
raise ex
|
584
541
|
end
|
585
542
|
rescue => ex
|
586
|
-
error_type = "#{ex.class}"
|
587
543
|
raise ex
|
588
544
|
else
|
589
545
|
return [output_json, response]
|
590
|
-
ensure
|
591
|
-
# Writing to telegraf
|
592
|
-
begin
|
593
|
-
end_time = Time.now
|
594
|
-
response_time = end_time - start_time
|
595
|
-
status_code = response.code if response
|
596
|
-
endpoint_name = url.present? ? URI(url).host : url
|
597
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "#{method.upcase}")
|
598
|
-
rescue
|
599
|
-
Rails.logger.info {"Failed to send metric"}
|
600
|
-
end
|
601
546
|
end
|
602
547
|
|
603
548
|
def update_create_tenant
|
@@ -653,12 +598,9 @@ module ZuoraAPI
|
|
653
598
|
require 'fileutils'
|
654
599
|
FileUtils.mkdir_p(file_path) unless File.exists?(file_path)
|
655
600
|
|
656
|
-
error_type = ""
|
657
|
-
start_time = Time.now
|
658
|
-
|
659
601
|
begin
|
660
|
-
status_code = nil
|
661
602
|
uri = URI.parse(url)
|
603
|
+
|
662
604
|
http = Net::HTTP.new(uri.host, uri.port)
|
663
605
|
http.read_timeout = timeout #Seconds
|
664
606
|
http.use_ssl = true if uri.scheme.downcase == 'https'
|
@@ -667,8 +609,6 @@ module ZuoraAPI
|
|
667
609
|
response_save = nil
|
668
610
|
http.request_get(uri.path, headers) do |response|
|
669
611
|
response_save = response
|
670
|
-
status_code = response.code if response
|
671
|
-
|
672
612
|
case response
|
673
613
|
when Net::HTTPNotFound
|
674
614
|
Rails.logger.fatal("404 - Not Found")
|
@@ -754,32 +694,18 @@ module ZuoraAPI
|
|
754
694
|
|
755
695
|
file_handle.close
|
756
696
|
Rails.logger.info("Filepath: #{file_handle.path} Size: #{File.size(file_handle.path).to_f/1000000} mb")
|
757
|
-
|
697
|
+
|
758
698
|
return file_handle
|
759
699
|
end
|
760
700
|
end
|
761
701
|
rescue Exception => e
|
762
|
-
error_type = "#{e.class}"
|
763
702
|
Rails.logger.fatal('GetFile') {"Download Failed: #{response_save} - #{e.class} : #{e.message}"}
|
764
703
|
Rails.logger.fatal('GetFile') {"Download Failed: #{e.backtrace.join("\n")}"}
|
765
704
|
raise
|
766
|
-
ensure
|
767
|
-
# Writing to telegraf
|
768
|
-
begin
|
769
|
-
end_time = Time.now
|
770
|
-
response_time = end_time - start_time
|
771
|
-
status_code = response.code if response
|
772
|
-
endpoint_name = url.present? ? URI(url).host : url
|
773
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "GET")
|
774
|
-
rescue
|
775
|
-
Rails.logger.info {"Failed to send metric"}
|
776
|
-
end
|
777
705
|
end
|
778
706
|
end
|
779
707
|
|
780
708
|
def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
|
781
|
-
error_type = ""
|
782
|
-
start_time = Time.now
|
783
709
|
Rails.logger.info('Export') {"Build export"}
|
784
710
|
Rails.logger.debug('Export query') {"#{query}"}
|
785
711
|
request = Nokogiri::XML::Builder.new do |xml|
|
@@ -802,23 +728,7 @@ module ZuoraAPI
|
|
802
728
|
end
|
803
729
|
end
|
804
730
|
end
|
805
|
-
|
806
|
-
begin
|
807
|
-
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)
|
808
|
-
rescue => e
|
809
|
-
error_type = "#{e.class}"
|
810
|
-
ensure
|
811
|
-
begin
|
812
|
-
end_time = Time.now
|
813
|
-
response_time = end_time - start_time
|
814
|
-
status_code = response.code if response
|
815
|
-
endpoint_name = url.present? ? URI(url).host : url
|
816
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST")
|
817
|
-
rescue
|
818
|
-
Rails.logger.info {"Failed to send metric"}
|
819
|
-
end
|
820
|
-
end
|
821
|
-
|
731
|
+
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)
|
822
732
|
output_xml = Nokogiri::XML(response_query.body)
|
823
733
|
|
824
734
|
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"
|
@@ -839,35 +749,15 @@ module ZuoraAPI
|
|
839
749
|
end
|
840
750
|
end
|
841
751
|
result = 'Waiting'
|
842
|
-
|
843
|
-
start_time = Time.now
|
844
|
-
error_type = ""
|
845
|
-
|
846
752
|
while result != "Completed"
|
847
753
|
sleep 3
|
848
|
-
|
849
|
-
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)
|
850
|
-
rescue => e
|
851
|
-
error_type = "#{e.class}"
|
852
|
-
end
|
754
|
+
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)
|
853
755
|
output_xml = Nokogiri::XML(response_query.body)
|
756
|
+
|
854
757
|
result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
|
855
|
-
status_code = response_query.code if response_query
|
856
758
|
raise "Export Creation Unsuccessful : #{output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}" if result.blank? || result == "Failed"
|
857
759
|
end
|
858
760
|
|
859
|
-
begin
|
860
|
-
end_time = Time.now
|
861
|
-
response_time = end_time - start_time
|
862
|
-
status_code = response.code if response
|
863
|
-
endpoint_name = url.present? ? URI(url).host : url
|
864
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST")
|
865
|
-
rescue
|
866
|
-
Rails.logger.info {"Failed to send metric"}
|
867
|
-
end
|
868
|
-
|
869
|
-
|
870
|
-
|
871
761
|
file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
|
872
762
|
Rails.logger.info('Export') {'=====> Export finished'}
|
873
763
|
export_file = get_file(:url => self.fileURL(file_id))
|
@@ -895,7 +785,7 @@ module ZuoraAPI
|
|
895
785
|
end
|
896
786
|
end
|
897
787
|
if parse
|
898
|
-
return [] if output_xml.xpath('//ns1:size', 'ns1' =>'http://api.zuora.com/').text == '0'
|
788
|
+
return [] if output_xml.xpath('//ns1:size', 'ns1' =>'http://api.zuora.com/').text == '0'
|
899
789
|
data = output_xml.xpath('//ns1:records', 'ns1' =>'http://api.zuora.com/').map {|record| record.children.map {|element| [element.name, element.text]}.to_h}
|
900
790
|
return data
|
901
791
|
else
|
@@ -904,33 +794,14 @@ module ZuoraAPI
|
|
904
794
|
end
|
905
795
|
|
906
796
|
def createJournalRun(call)
|
907
|
-
error_type = ""
|
908
|
-
start_time = Time.now
|
909
|
-
|
910
797
|
url = rest_endpoint("/journal-runs")
|
911
798
|
uri = URI(url)
|
912
799
|
req = Net::HTTP::Post.new(uri,initheader = {'Content-Type' =>'application/json'})
|
913
800
|
req.basic_auth self.username, self.password
|
914
801
|
req.body = call
|
915
|
-
|
916
|
-
|
917
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
918
|
-
http.request req
|
919
|
-
end
|
920
|
-
rescue => e
|
921
|
-
error_type = "#{e.class}"
|
922
|
-
ensure
|
923
|
-
begin
|
924
|
-
end_time = Time.now
|
925
|
-
response_time = end_time - start_time
|
926
|
-
status_code = response.code if response
|
927
|
-
endpoint_name = url.present? ? URI(url).host : url
|
928
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "POST")
|
929
|
-
rescue
|
930
|
-
Rails.logger.info {"Failed to send metric"}
|
931
|
-
end
|
802
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
803
|
+
http.request req
|
932
804
|
end
|
933
|
-
|
934
805
|
Rails.logger.debug('Journal Run') {"Response #{response.code} #{response.message}:
|
935
806
|
#{response.body}"}
|
936
807
|
|
@@ -943,39 +814,17 @@ module ZuoraAPI
|
|
943
814
|
Rails.logger.debug('Journal Run') {"Journal Run failed with message #{message}"}
|
944
815
|
return result
|
945
816
|
end
|
946
|
-
|
947
817
|
end
|
948
818
|
|
949
819
|
def checkJRStatus(jrNumber)
|
950
|
-
error_type = ""
|
951
|
-
|
952
820
|
Rails.logger.info('Journal Run') {"Check for completion"}
|
953
|
-
|
954
|
-
start_time = Time.now
|
955
|
-
|
956
821
|
url = rest_endpoint("/journal-runs/#{jrNumber}")
|
957
822
|
uri = URI(url)
|
958
823
|
req = Net::HTTP::Get.new(uri,initheader = {'Content-Type' =>'application/json'})
|
959
824
|
req.basic_auth self.username, self.password
|
960
|
-
|
961
|
-
|
962
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
963
|
-
http.request req
|
964
|
-
end
|
965
|
-
rescue => e
|
966
|
-
error_type = "#{e.class}"
|
967
|
-
ensure
|
968
|
-
begin
|
969
|
-
end_time = Time.now
|
970
|
-
response_time = end_time - start_time
|
971
|
-
status_code = response.code if response
|
972
|
-
endpoint_name = url.present? ? URI(url).host : url
|
973
|
-
::MetricsHelpers::MetricsHelpers.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "function_name": "#{self.class}##{__method__}", "method_name": "GET")
|
974
|
-
rescue
|
975
|
-
Rails.logger.info {"Failed to send metric"}
|
976
|
-
end
|
825
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
826
|
+
http.request req
|
977
827
|
end
|
978
|
-
|
979
828
|
result = JSON.parse(response.body)
|
980
829
|
|
981
830
|
if result["success"]
|
data/lib/zuora_api/version.rb
CHANGED
data/zuora_api.gemspec
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.4.
|
4
|
+
version: 1.4.12
|
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: 2018-
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,20 +142,6 @@ dependencies:
|
|
142
142
|
- - "<"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '5.1'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: telegraf
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: 0.4.0
|
152
|
-
type: :runtime
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - "~>"
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: 0.4.0
|
159
145
|
description: Gem that provides easy integration to Zuora
|
160
146
|
email:
|
161
147
|
- connect@zuora.com
|
@@ -177,7 +163,6 @@ files:
|
|
177
163
|
- lib/zuora_api.rb
|
178
164
|
- lib/zuora_api/exceptions.rb
|
179
165
|
- lib/zuora_api/login.rb
|
180
|
-
- lib/zuora_api/metrics_helper.rb
|
181
166
|
- lib/zuora_api/version.rb
|
182
167
|
- zuora_api.gemspec
|
183
168
|
homepage: https://connect.zuora.com
|
@@ -194,9 +179,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
179
|
version: '0'
|
195
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
181
|
requirements:
|
197
|
-
- - "
|
182
|
+
- - ">="
|
198
183
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
184
|
+
version: '0'
|
200
185
|
requirements: []
|
201
186
|
rubyforge_project:
|
202
187
|
rubygems_version: 2.6.8
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module MetricsHelpers
|
2
|
-
|
3
|
-
class MetricsHelpers
|
4
|
-
def self.write_to_telegraf(response_time: nil, status_code: nil, endpoint_name: nil, direction: nil, error_type: nil, function_name: nil, method_name: nil)
|
5
|
-
if Gem.loaded_specs.has_key?('zuora_connect') && defined?(::ZuoraConnect::AppInstance.write_to_telegraf)
|
6
|
-
Thread.current[:appinstance].present? ? app_instance = Thread.current[:appinstance].id : app_instance = 0
|
7
|
-
ZuoraConnect::AppInstanceBase.write_to_telegraf("response_time": response_time, "status_code": status_code, "endpoint_name": endpoint_name, "direction": "outbound", "error_type": error_type, "app_instance": app_instance, "function_name": function_name, "method_name": method_name)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|