zuora_api 1.7.00 → 1.7.01
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/zuora_api/login.rb +101 -111
- data/lib/zuora_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ada8f975604d10b0cb60b4b58eacef95a917f2509c3ee578b44cb9ae00dac2
|
4
|
+
data.tar.gz: f114390047aeec864c19a1b04e9e8ab93cdf2a4c8c46c84fc471593d893651fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c08a97f372728e3d40ab433bf18d30ad58dddd1297e9cb241b8b031ce3baa1cd60f21405c4f8909fc350177fb8294897aee0baba06194d54365e0fa987d0ed
|
7
|
+
data.tar.gz: 50f70103f0984d99a1e2ca3df4889c58c3c2c5387db2ffbc37b56db3e46fb7cb02ccfa25071a4820184ff62b1909b88106eda2d665e9ec7ddd2f9b6bc991eea0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.7.01] - 2018-8-06
|
5
|
+
### Changed
|
6
|
+
- Changed library used to determine host
|
7
|
+
- Added retry for 504 timouts in file download
|
8
|
+
|
4
9
|
## [1.7.00] - 2018-8-05
|
5
10
|
### Changed
|
6
11
|
- Raise proper exception when oauth client is from deactivated user.
|
data/lib/zuora_api/login.rb
CHANGED
@@ -352,8 +352,7 @@ module ZuoraAPI
|
|
352
352
|
end
|
353
353
|
|
354
354
|
def rest_domain
|
355
|
-
|
356
|
-
return ::Addressable::URI.parse(self.rest_endpoint).host
|
355
|
+
return URI(self.rest_endpoint).host
|
357
356
|
end
|
358
357
|
|
359
358
|
def fileURL(url="")
|
@@ -890,137 +889,128 @@ module ZuoraAPI
|
|
890
889
|
return products, catalog_map
|
891
890
|
end
|
892
891
|
|
893
|
-
def get_file(url: nil, headers: {},
|
892
|
+
def get_file(url: nil, headers: {}, z_session: true, tempfile: true, output_file_name: 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)
|
894
893
|
raise "file_path must be of class Pathname" if file_path.class != Pathname
|
895
894
|
|
896
895
|
#Make sure directory exists
|
897
896
|
require 'fileutils'
|
898
897
|
FileUtils.mkdir_p(file_path) unless File.exists?(file_path)
|
899
898
|
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
end
|
899
|
+
status_code = nil
|
900
|
+
uri = URI.parse(url)
|
901
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
902
|
+
http.read_timeout = timeout #Seconds
|
903
|
+
http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
|
904
|
+
if z_session
|
905
|
+
headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
|
906
|
+
headers = headers.merge({"Zuora-Entity-Ids" => self.entity_id}) if !self.entity_id.blank?
|
907
|
+
end
|
910
908
|
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
end
|
928
|
-
end
|
929
|
-
self.new_session if z_session
|
930
|
-
return get_file(:url => url, :headers => headers, :count => count - 1, :z_session => z_session, :tempfile => tempfile, :file_path => file_path, :timeout_retries => timeout_retries, :timeout => timeout)
|
909
|
+
response_save = nil
|
910
|
+
retry_count ||= timeout_retries
|
911
|
+
http.request_get(uri.request_uri, headers) do |response|
|
912
|
+
response_save = response
|
913
|
+
status_code = response.code if response
|
914
|
+
case response
|
915
|
+
when Net::HTTPOK
|
916
|
+
headers = {}
|
917
|
+
response.each_header do |k,v|
|
918
|
+
headers[k] = v
|
919
|
+
end
|
920
|
+
Rails.logger.debug("Headers: #{headers.to_s}")
|
921
|
+
if output_file_name.present?
|
922
|
+
file_ending ||= output_file_name.end_with?(".csv.zip") ? ".csv.zip" : File.extname(output_file_name)
|
923
|
+
filename ||= File.basename(output_file_name, file_ending)
|
924
|
+
end
|
931
925
|
|
932
|
-
|
933
|
-
|
926
|
+
size, export_progress = [0, 0]
|
927
|
+
encoding, type, full_filename = [nil, nil, nil]
|
928
|
+
if response.header["Content-Disposition"].present?
|
929
|
+
case response.header["Content-Disposition"]
|
930
|
+
when /.*; filename\*=.*/
|
931
|
+
full_filename ||= /.*; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[2].strip
|
932
|
+
encoding = /.*; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[1].strip
|
933
|
+
when /.*; filename=/
|
934
|
+
full_filename ||= /.*; filename=(.*)/.match(response.header["Content-Disposition"])[1].strip
|
935
|
+
else
|
936
|
+
raise "Can't parse Content-Disposition header: #{response.header["Content-Disposition"]}"
|
937
|
+
end
|
938
|
+
file_ending ||= full_filename.end_with?(".csv.zip") ? ".csv.zip" : File.extname(full_filename)
|
939
|
+
filename ||= File.basename(full_filename, file_ending)
|
940
|
+
end
|
934
941
|
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
headers[k] = v
|
939
|
-
end
|
940
|
-
Rails.logger.debug("Headers: #{headers.to_s}")
|
941
|
-
if output_file_name.present?
|
942
|
-
file_ending ||= output_file_name.end_with?(".csv.zip") ? ".csv.zip" : File.extname(output_file_name)
|
943
|
-
filename ||= File.basename(output_file_name, file_ending)
|
944
|
-
end
|
942
|
+
#If user supplied a filename use it, else default to content header filename, else default to uri pattern
|
943
|
+
file_ending ||= uri.path.end_with?(".csv.zip") ? ".csv.zip" : File.extname(uri.path)
|
944
|
+
filename ||= File.basename(uri.path, file_ending)
|
945
945
|
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
raise "Can't parse Content-Disposition header: #{response.header["Content-Disposition"]}"
|
957
|
-
end
|
958
|
-
file_ending ||= full_filename.end_with?(".csv.zip") ? ".csv.zip" : File.extname(full_filename)
|
959
|
-
filename ||= File.basename(full_filename, file_ending)
|
960
|
-
end
|
946
|
+
if response.header["Content-Type"].present?
|
947
|
+
case response.header["Content-Type"]
|
948
|
+
when /.*;charset=.*/
|
949
|
+
type = /(.*);charset=(.*)/.match(response.header["Content-Type"])[1]
|
950
|
+
encoding = /(.*);charset=(.*)/.match(response.header["Content-Type"])[2]
|
951
|
+
else
|
952
|
+
type = response.header["Content-Type"]
|
953
|
+
encoding ||= 'UTF-8'
|
954
|
+
end
|
955
|
+
end
|
961
956
|
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
case response.header["Content-Type"]
|
968
|
-
when /.*;charset=.*/
|
969
|
-
type = /(.*);charset=(.*)/.match(response.header["Content-Type"])[1]
|
970
|
-
encoding = /(.*);charset=(.*)/.match(response.header["Content-Type"])[2]
|
971
|
-
else
|
972
|
-
type = response.header["Content-Type"]
|
973
|
-
encoding ||= 'UTF-8'
|
974
|
-
end
|
975
|
-
end
|
957
|
+
if response.header["Content-Length"].present?
|
958
|
+
export_size = response.header["Content-Length"].to_i
|
959
|
+
elsif response.header["ContentLength"].present?
|
960
|
+
export_size = response.header["ContentLength"].to_i
|
961
|
+
end
|
976
962
|
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
963
|
+
Rails.logger.info("File: #{filename}#{file_ending} #{encoding} #{type} #{export_size}")
|
964
|
+
|
965
|
+
file_prefix = add_timestamp ? "#{filename}_#{Time.now.to_i}" : filename
|
966
|
+
if tempfile
|
967
|
+
require 'tempfile'
|
968
|
+
file_handle = ::Tempfile.new([file_prefix, "#{file_ending}"], file_path)
|
969
|
+
else
|
970
|
+
file_handle = File.new(file_path.join("#{file_prefix}#{file_ending}"), "w+")
|
971
|
+
end
|
972
|
+
file_handle.binmode
|
982
973
|
|
983
|
-
|
974
|
+
response.read_body do |chunk|
|
975
|
+
file_handle << chunk
|
984
976
|
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
file_handle = File.new(file_path.join("#{file_prefix}#{file_ending}"), "w+")
|
991
|
-
end
|
992
|
-
file_handle.binmode
|
993
|
-
|
994
|
-
response.read_body do |chunk|
|
995
|
-
file_handle << chunk
|
996
|
-
|
997
|
-
if defined?(export_size) && export_size != 0 && export_size.class == Integer
|
998
|
-
size += chunk.size
|
999
|
-
new_progress = (size * 100) / export_size
|
1000
|
-
unless new_progress == export_progress
|
1001
|
-
Rails.logger.debug("Login: Export Downloading %s (%3d%%)" % [filename, new_progress])
|
1002
|
-
end
|
1003
|
-
export_progress = new_progress
|
1004
|
-
end
|
977
|
+
if defined?(export_size) && export_size != 0 && export_size.class == Integer
|
978
|
+
size += chunk.size
|
979
|
+
new_progress = (size * 100) / export_size
|
980
|
+
unless new_progress == export_progress
|
981
|
+
Rails.logger.debug("Login: Export Downloading %s (%3d%%)" % [filename, new_progress])
|
1005
982
|
end
|
983
|
+
export_progress = new_progress
|
984
|
+
end
|
985
|
+
end
|
1006
986
|
|
1007
|
-
|
1008
|
-
|
987
|
+
file_handle.close
|
988
|
+
Rails.logger.debug("Filepath: #{file_handle.path} Size: #{File.size(file_handle.path).to_f/1000000} mb")
|
1009
989
|
|
1010
|
-
|
990
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Downloaded file is not a file: #{file_handle.class}") if !["Tempfile", "File"].include?(file_handle.class.to_s)
|
991
|
+
return file_handle
|
992
|
+
when Net::HTTPUnauthorized
|
993
|
+
if z_session
|
994
|
+
if !(retry_count -= 1).zero?
|
995
|
+
self.new_session
|
996
|
+
raise response.class
|
997
|
+
else
|
998
|
+
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
|
1011
999
|
end
|
1012
|
-
end
|
1013
|
-
rescue *(CONNECTION_EXCEPTIONS).concat(CONNECTION_READ_EXCEPTIONS).concat([Net::HTTPBadResponse]) => e
|
1014
|
-
sleep(5)
|
1015
|
-
if (timeout_retries -= 1) >= 0
|
1016
|
-
Rails.logger.warn("Download Failed: #{e.class} : #{e.message}")
|
1017
|
-
retry
|
1018
1000
|
else
|
1019
1001
|
raise
|
1020
1002
|
end
|
1003
|
+
else
|
1004
|
+
raise StandardError.new("File Download Failed #{response.class}")
|
1021
1005
|
end
|
1022
|
-
|
1023
|
-
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
rescue => ex
|
1009
|
+
sleep(5)
|
1010
|
+
if (retry_count -= 1) >= 0
|
1011
|
+
retry
|
1012
|
+
else
|
1013
|
+
Rails.logger.error("File Download Failed")
|
1024
1014
|
raise
|
1025
1015
|
end
|
1026
1016
|
end
|
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.01
|
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: 2019-08-
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|