zuora_api 1.3.98 → 1.3.99
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/lib/zuora_api/login.rb +38 -8
- data/lib/zuora_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8981ecd148fac5717a22a5b90cce3802094ef926
|
4
|
+
data.tar.gz: ae14c625556803728169189a2db657a98c8422a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71c0ce69b97507a8156ffdc8890d24aff1360ddeeabe831bf4badc91d2f49cad397e4607a6e9fe6abf48a6f589c7c532fc7ed1e8b0a0e5ab0ee3a8268a4504aa
|
7
|
+
data.tar.gz: 46fdd7c68d9ef8bde2713741646acf01cfa4117fa0d259c941d5fa5a3ed869c7cfba395cbdb8c034c406da2c827c0a78f0390a36e16d4ff7df050acc7ebf1a22
|
data/lib/zuora_api/login.rb
CHANGED
@@ -421,10 +421,11 @@ module ZuoraAPI
|
|
421
421
|
return products, catalog_map
|
422
422
|
end
|
423
423
|
|
424
|
-
def get_file(file_name: nil, url: nil, headers: {}, count: 3,
|
424
|
+
def get_file(file_name: nil, file_type: nil, url: nil, headers: {}, count: 3, z_session: true, tempfile: true, file_path: Rails.root.join('tmp'))
|
425
|
+
raise "file_path must be of class Pathname" if file_path.class != Pathname
|
426
|
+
|
425
427
|
begin
|
426
428
|
uri = URI.parse(url)
|
427
|
-
filename = !file_name.blank? ? file_name : File.basename(uri.path).rpartition('.').first
|
428
429
|
|
429
430
|
http = Net::HTTP.new(uri.host, uri.port)
|
430
431
|
http.read_timeout = 120 #Seconds
|
@@ -443,25 +444,54 @@ module ZuoraAPI
|
|
443
444
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if count <= 0
|
444
445
|
Rails.logger.fatal("Unauthorized: Retry")
|
445
446
|
self.new_session
|
446
|
-
return get_file(:url => url, :count => count - 1, :
|
447
|
+
return get_file(:file_name => file_name, :file_type => file_type, :url => url, :headers => headers, :count => count - 1, :z_session => z_session, :tempfile => tempfile. :file_path => file_path)
|
447
448
|
|
448
449
|
when Net::HTTPClientError
|
449
450
|
Rails.logger.debug("Login: #{self.username} Export")
|
450
451
|
raise response
|
451
452
|
|
452
453
|
when Net::HTTPOK
|
453
|
-
|
454
|
-
temp_file.binmode
|
454
|
+
Rails.logger.debug("Headers: #{response}")
|
455
455
|
|
456
456
|
size, export_progress = [0, 0]
|
457
|
+
encoding, type, full_filename = [nil, nil, nil]
|
458
|
+
if response.header["Content-Disposition"].present?
|
459
|
+
case response.header["Content-Disposition"]
|
460
|
+
when /attachment; filename\*=.*/
|
461
|
+
full_filename = /attachment; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[2].strip
|
462
|
+
encoding = /attachment; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[1].strip
|
463
|
+
when /attachment; filename=/
|
464
|
+
full_filename = /attachment; filename=(.*)/.match(response.header["Content-Disposition"])[1].strip
|
465
|
+
end
|
466
|
+
file_ending = file_type.present? ? ".#{file_type}" : /.*(\..*)$/.match(full_filename)[-1]
|
467
|
+
end
|
468
|
+
#If user supplied a filename use it, else default to content header filename, else default to uri pattern
|
469
|
+
filename = file_name.present? ? file_name : full_filename.present? ? full_filename.split(file_ending).first : File.basename(uri.path).rpartition('.').first
|
470
|
+
|
471
|
+
if response.header["Content-Type"].present?
|
472
|
+
type = /(.*);charset=(.*)/.match(response.header["Content-Type"])[1]
|
473
|
+
encoding = /(.*);charset=(.*)/.match(response.header["Content-Type"])[2]
|
474
|
+
end
|
475
|
+
Rails.logger.debug("File: #{filename}#{file_ending} #{encoding} #{type}")
|
476
|
+
|
457
477
|
if response.header["Content-Length"].present?
|
458
478
|
export_size = response.header["Content-Length"].to_i
|
459
479
|
elsif response.header["ContentLength"].present?
|
460
480
|
export_size = response.header["ContentLength"].to_i
|
461
481
|
end
|
462
482
|
|
483
|
+
file_handle = nil
|
484
|
+
timestamp = Time.now.to_i
|
485
|
+
if tempfile
|
486
|
+
file_handle = Tempfile.new(["#{filename}_#{timestamp}", "#{file_ending}"], file_path)
|
487
|
+
file_handle.binmode
|
488
|
+
else
|
489
|
+
file_handle = File.new(file_path.join("#{filename}_#{timestamp}#{file_ending}"), "w+")
|
490
|
+
file_handle.binmode
|
491
|
+
end
|
492
|
+
|
463
493
|
response.read_body do |chunk|
|
464
|
-
|
494
|
+
file_handle << chunk.force_encoding(encoding)
|
465
495
|
|
466
496
|
if defined?(export_size) && export_size != 0 && export_size.class == Integer
|
467
497
|
size += chunk.size
|
@@ -473,8 +503,8 @@ module ZuoraAPI
|
|
473
503
|
end
|
474
504
|
end
|
475
505
|
|
476
|
-
|
477
|
-
return
|
506
|
+
file_handle.close
|
507
|
+
return file_handle
|
478
508
|
end
|
479
509
|
end
|
480
510
|
rescue Exception => e
|
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.3.
|
4
|
+
version: 1.3.99
|
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: 2017-
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|