Package not found. Please check the package name and try again.

zuora_api 1.7.00 → 1.7.01

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecec87283f238f546be12e3fadb16e9fabbee7aec1129d47401876359271f868
4
- data.tar.gz: 98d980959dcf672fad54bdc87fa89061f6aee4627eebb4ef89da8573c204419b
3
+ metadata.gz: 98ada8f975604d10b0cb60b4b58eacef95a917f2509c3ee578b44cb9ae00dac2
4
+ data.tar.gz: f114390047aeec864c19a1b04e9e8ab93cdf2a4c8c46c84fc471593d893651fe
5
5
  SHA512:
6
- metadata.gz: 0f18782b6e2bc5d2433c4f0b632fe931205392db8b334edf524accec0e17821394a064f82cb45983d0a0ae7cbbc106b8ae8911b90c35651445e139bf94d261d7
7
- data.tar.gz: 56555f10ce5434a30a54d4cad556170987a033f1cbfef34dc0b246fd935878ae4e7bd989e4c7ba7f3f95a73d291c25983d39260b41a8c91a1dcb9a019e879eab
6
+ metadata.gz: 85c08a97f372728e3d40ab433bf18d30ad58dddd1297e9cb241b8b031ce3baa1cd60f21405c4f8909fc350177fb8294897aee0baba06194d54365e0fa987d0ed
7
+ data.tar.gz: 50f70103f0984d99a1e2ca3df4889c58c3c2c5387db2ffbc37b56db3e46fb7cb02ccfa25071a4820184ff62b1909b88106eda2d665e9ec7ddd2f9b6bc991eea0
@@ -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.
@@ -352,8 +352,7 @@ module ZuoraAPI
352
352
  end
353
353
 
354
354
  def rest_domain
355
- require 'addressable/uri'
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: {}, count: 3, 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: 2, timeout: 120, session_type: :basic, **execute_params)
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
- begin
901
- status_code = nil
902
- uri = URI.parse(url)
903
- http = Net::HTTP.new(uri.host, uri.port)
904
- http.read_timeout = timeout #Seconds
905
- http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
906
- if z_session
907
- headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
908
- headers = headers.merge({"Zuora-Entity-Ids" => self.entity_id}) if !self.entity_id.blank?
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
- response_save = nil
912
- begin
913
- http.request_get(uri.request_uri, headers) do |response|
914
- response_save = response
915
- status_code = response.code if response
916
-
917
- case response
918
- when Net::HTTPNotFound
919
- raise
920
-
921
- when Net::HTTPUnauthorized
922
- if count <= 0
923
- if z_session
924
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error)
925
- else
926
- raise
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
- when Net::HTTPClientError
933
- raise
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
- when Net::HTTPOK
936
- headers = {}
937
- response.each_header do |k,v|
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
- size, export_progress = [0, 0]
947
- encoding, type, full_filename = [nil, nil, nil]
948
- if response.header["Content-Disposition"].present?
949
- case response.header["Content-Disposition"]
950
- when /.*; filename\*=.*/
951
- full_filename ||= /.*; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[2].strip
952
- encoding = /.*; filename\*=(.*)''(.*)/.match(response.header["Content-Disposition"])[1].strip
953
- when /.*; filename=/
954
- full_filename ||= /.*; filename=(.*)/.match(response.header["Content-Disposition"])[1].strip
955
- else
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
- #If user supplied a filename use it, else default to content header filename, else default to uri pattern
963
- file_ending ||= uri.path.end_with?(".csv.zip") ? ".csv.zip" : File.extname(uri.path)
964
- filename ||= File.basename(uri.path, file_ending)
965
-
966
- if response.header["Content-Type"].present?
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
- if response.header["Content-Length"].present?
978
- export_size = response.header["Content-Length"].to_i
979
- elsif response.header["ContentLength"].present?
980
- export_size = response.header["ContentLength"].to_i
981
- end
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
- Rails.logger.info("File: #{filename}#{file_ending} #{encoding} #{type} #{export_size}")
974
+ response.read_body do |chunk|
975
+ file_handle << chunk
984
976
 
985
- file_prefix = add_timestamp ? "#{filename}_#{Time.now.to_i}" : filename
986
- if tempfile
987
- require 'tempfile'
988
- file_handle = ::Tempfile.new([file_prefix, "#{file_ending}"], file_path)
989
- else
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
- file_handle.close
1008
- Rails.logger.debug("Filepath: #{file_handle.path} Size: #{File.size(file_handle.path).to_f/1000000} mb")
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
- return file_handle
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
- rescue => ex
1023
- Rails.logger.fatal(ex)
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
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.7.00"
2
+ VERSION = "1.7.01"
3
3
  end
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.00
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-05 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler