zuora_api 1.6.26 → 1.6.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e86b5da627b9f51c342da05d5e4110e3385a35a4
4
- data.tar.gz: 9ccf40e8d6dfca789d16207421dc07352ad8c921
3
+ metadata.gz: fa6e502f281056139b4e18a986bb6d129837df06
4
+ data.tar.gz: 7893fb708b15af2e2931097108fa5cebc56200fd
5
5
  SHA512:
6
- metadata.gz: 35a3fb0d447a8a52d11762133e0fe11cccea7e5970c74aa31bc121153dc62d3aece97adaf08fa1a8cc6562c5eee2b74c9c24144ff981d503083530b10c1e3bb3
7
- data.tar.gz: ef0b5f9af4d236df06de046d3afd6e8e649a007281036c9770df4cb289d31df99f3f1ae535eae55ff28154b6f098b60e0e46f90724b894d0b1dc27a0743b3795
6
+ metadata.gz: 807901369ca7d585cf77f08004f13b708567ea5fc39ad0117f58d1d8ca2c498cd5666b1efbe596d6abd51dfd4b22c2d10fbf92dacadcbef32d3a7346b8db838d
7
+ data.tar.gz: 279127003d4cf2a0786e7d519853efe5ddb06b23f33a945ce93482bba35ce600f6b061b3c4f2634cb38a4b6bc10e5a0b112030627301b1a3faae6d65a60e7870
data/CHANGELOG.md CHANGED
@@ -1,15 +1,14 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [1.6.16] - 2018-12-09
4
+ ## [1.6.28] - 2018-3-12
5
5
  ### Added
6
- - Example
6
+ - Way to avoid force encoding for filedownload
7
7
 
8
+ ## [1.6.22] - 2019-01-03
8
9
  ### Changed
9
- - Example
10
-
11
- ### Removed
12
- - Example
10
+ - get_identity method - supports ZSession auth now
11
+ - updated rspecs accordingly
13
12
 
14
13
  ## [1.6.18] - 2018-12-06
15
14
  ### Added
@@ -24,15 +23,4 @@ All notable changes to this project will be documented in this file.
24
23
  ### Changed
25
24
  - The way environment and region are set
26
25
 
27
- ## [1.6.22] - 2019-01-03
28
26
 
29
- ### Changed
30
- - get_identity method - supports ZSession auth now
31
- - updated rspecs accordingly
32
-
33
- ## [1.6.26] - 2019-03-04
34
-
35
- ### Changed
36
- - fixed get_oauth_client for non-staging environments
37
- - fixed to use correct rest endpoint without version for oauth creation api
38
- - changed get_oauth_client to no longer accept client id and secret as parameters
@@ -156,11 +156,13 @@ module ZuoraAPI
156
156
  end
157
157
 
158
158
  # There are two ways to call this method. The first way is best.
159
- # 1. Pass in cookies, name, and description
160
- # 2. Pass in user_id, entity_ids, an existing client_id and client_secret, name, and description
159
+ # 1. Pass in cookies and optionally custom_authorities, name, and description
160
+ # 2. Pass in user_id, entity_ids, client_id, client_secret, and optionally custom_authorities, name, and description
161
161
  # https://intranet.zuora.com/confluence/display/Sunburst/Create+an+OAuth+Client+through+API+Gateway#CreateanOAuthClientthroughAPIGateway-ZSession
162
- def get_oauth_client (info_name: "No Name", info_desc: "This client was created without a description.", user_id: nil, entity_ids: nil, client_id: nil, client_secret: nil, cookies: nil)
162
+ def get_oauth_client (custom_authorities = [], info_name: "No Name", info_desc: "This client was created without a description.", user_id: nil, entity_ids: nil, client_id: nil, client_secret: nil, new_client_id: nil, new_client_secret: nil, cookies: nil)
163
163
  authorization = ""
164
+ new_client_id = SecureRandom.uuid if new_client_id.blank?
165
+ new_client_secret = SecureRandom.hex(10) if new_client_secret.blank?
164
166
 
165
167
  if !cookies.nil?
166
168
  authorization = cookies["ZSession"]
@@ -176,18 +178,18 @@ module ZuoraAPI
176
178
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Zuora User ID not provided", {}, 400)
177
179
  end
178
180
  elsif !client_id.nil? && !client_secret.nil?
179
- endpoint = self.rest_endpoint("oauth/token").gsub("v1/", "")
180
- bearer_response = HTTParty.post(endpoint, :headers => {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}, :body => {'client_id' => client_id, 'client_secret' => URI::encode(client_secret), 'grant_type' => 'client_credentials'})
181
+ bearer_response = HTTParty.post("https://#{self.hostname}/oauth/token", :headers => {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}, :body => {'client_id' => client_id, 'client_secret' => URI::encode(client_secret), 'grant_type' => 'client_credentials'})
181
182
  bearer_hash = JSON.parse(bearer_response.body)
182
183
  bearer_token = bearer_hash["access_token"]
183
184
  authorization = "Bearer #{bearer_token}"
184
185
  end
185
186
 
186
187
  if !authorization.blank? && !user_id.blank? && !entity_ids.blank?
187
- endpoint = self.rest_endpoint("genesis/clients").gsub("v1/", "")
188
- oauth_response = HTTParty.post(endpoint, :headers => {'authorization' => authorization, 'Content-Type' => 'application/json'}, :body => {'userId' => user_id, 'entityIds' => entity_ids, 'additionalInformation' => {'description' => info_desc, 'name' => info_name}}.to_json)
188
+ endpoint = self.rest_endpoint("genesis/clients")
189
+ oauth_response = HTTParty.post(endpoint, :headers => {'authorization' => authorization, 'Content-Type' => 'application/json'}, :body => {'clientId' => new_client_id, 'clientSecret' => new_client_secret, 'userId' => user_id, 'entityIds' => entity_ids, 'customAuthorities' => custom_authorities, 'additionalInformation' => {'description' => info_desc, 'name' => info_name}}.to_json)
189
190
  output_json = JSON.parse(oauth_response.body)
190
191
  if oauth_response.code == 201
192
+ output_json["clientSecret"] = new_client_secret
191
193
  return output_json
192
194
  elsif oauth_response.code == 401 && !oauth_response.message.blank?
193
195
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(output_json["message"], {}, oauth_response.code)
@@ -843,7 +845,7 @@ module ZuoraAPI
843
845
  return products, catalog_map
844
846
  end
845
847
 
846
- 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)
848
+ 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, force_encoding: true, **execute_params)
847
849
  raise "file_path must be of class Pathname" if file_path.class != Pathname
848
850
 
849
851
  #Make sure directory exists
@@ -882,7 +884,7 @@ module ZuoraAPI
882
884
  end
883
885
  Rails.logger.fatal("Unauthorized: Retry")
884
886
  self.new_session if z_session
885
- 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)
887
+ 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, :force_encoding => force_encoding)
886
888
 
887
889
  when Net::HTTPClientError
888
890
  raise
@@ -893,7 +895,6 @@ module ZuoraAPI
893
895
  headers[k] = v
894
896
  end
895
897
  Rails.logger.debug("Headers: #{headers.to_s}")
896
-
897
898
  if output_file_name.present?
898
899
  file_ending ||= output_file_name.end_with?(".csv.zip") ? ".csv.zip" : File.extname(output_file_name)
899
900
  filename ||= File.basename(output_file_name, file_ending)
@@ -929,7 +930,6 @@ module ZuoraAPI
929
930
  encoding ||= 'UTF-8'
930
931
  end
931
932
  end
932
- Rails.logger.info("File: #{filename}#{file_ending} #{encoding} #{type}")
933
933
 
934
934
  if response.header["Content-Length"].present?
935
935
  export_size = response.header["Content-Length"].to_i
@@ -937,6 +937,8 @@ module ZuoraAPI
937
937
  export_size = response.header["ContentLength"].to_i
938
938
  end
939
939
 
940
+ Rails.logger.info("File: #{filename}#{file_ending} #{encoding} #{type} #{export_size}")
941
+
940
942
  file_prefix = add_timestamp ? "#{filename}_#{Time.now.to_i}" : filename
941
943
  if tempfile
942
944
  require 'tempfile'
@@ -947,7 +949,11 @@ module ZuoraAPI
947
949
  file_handle.binmode
948
950
 
949
951
  response.read_body do |chunk|
950
- file_handle << chunk.force_encoding(encoding)
952
+ if force_encoding
953
+ file_handle << chunk.force_encoding(encoding)
954
+ else
955
+ file_handle << chunk
956
+ end
951
957
 
952
958
  if defined?(export_size) && export_size != 0 && export_size.class == Integer
953
959
  size += chunk.size
@@ -965,7 +971,7 @@ module ZuoraAPI
965
971
  return file_handle
966
972
  end
967
973
  end
968
- rescue *(CONNECTION_EXCEPTIONS).concat(CONNECTION_READ_EXCEPTIONS) => e
974
+ rescue *(CONNECTION_EXCEPTIONS).concat(CONNECTION_READ_EXCEPTIONS).concat([Net::HTTPBadResponse]) => e
969
975
  sleep(5)
970
976
  if (timeout_retries -= 1) >= 0
971
977
  Rails.logger.warn("Download Failed: #{e.class} : #{e.message}")
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.6.26"
2
+ VERSION = "1.6.28"
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.6.26
4
+ version: 1.6.28
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-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler