zuora_api 1.9.06 → 1.10.0
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 +52 -18
- data/lib/zuora_api/logins/oauth.rb +1 -1
- data/lib/zuora_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17131e6d6129f3831868f5a029b5c1f781e7fb31ca31fddd682b8bd0a3994f68
|
4
|
+
data.tar.gz: 748d5ac46b7647dd5ebfaf2338de458a2ff42e65d138b045dcd40e1eb5741f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289f4b0e533dbc666d649017ca97669525adc14976d135bbd9191955f5fe70384c3506261d65b89071752e1a23137593d70cb4afd47805a67a2b400e34e7fe3f
|
7
|
+
data.tar.gz: c85623dad76f6c4d02a49bbdddb602191c709576717cc2fad66a2b5324ff9824469fb3d1a70e98ad07c477a3b0191e47e1c5890e93bd7a13aaf5937302d0b8e4
|
data/lib/zuora_api/login.rb
CHANGED
@@ -7,8 +7,9 @@ module ZuoraAPI
|
|
7
7
|
class Login
|
8
8
|
ENVIRONMENTS = [TEST = 'Test', SANDBOX = 'Sandbox', PRODUCTION = 'Production', PREFORMANCE = 'Preformance', SERVICES = 'Services', UNKNOWN = 'Unknown', STAGING = 'Staging' ]
|
9
9
|
REGIONS = [EU = 'EU', US = 'US', NA = 'NA' ]
|
10
|
-
MIN_Endpoints = {'Test': '
|
10
|
+
MIN_Endpoints = {'Test': '108.0', 'Sandbox': '108.0', 'Production': '108.0', 'Performance': '108.0', 'Services': '96.0', 'Unknown': '96.0', 'Staging': '108.0'}.freeze
|
11
11
|
XML_SAVE_OPTIONS = Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
|
12
|
+
USER_AGENT = "Zuora#{ENV['Z_APPLICATION_NAME']&.capitalize}/#{ENV['Z_APPLICATION_VERSION']&.delete('v')}"
|
12
13
|
|
13
14
|
CONNECTION_EXCEPTIONS = [
|
14
15
|
Net::OpenTimeout,
|
@@ -44,9 +45,9 @@ module ZuoraAPI
|
|
44
45
|
ZuoraAPI::Exceptions::ZuoraUnexpectedError
|
45
46
|
].freeze
|
46
47
|
|
47
|
-
attr_accessor :region, :url, :wsdl_number, :current_session, :bearer_token, :oauth_session_expires_at, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id, :timeout_sleep, :hostname, :zconnect_provider
|
48
|
+
attr_accessor :region, :url, :wsdl_number, :current_session, :bearer_token, :oauth_session_expires_at, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id, :entity_identifier, :entity_header_type, :timeout_sleep, :hostname, :zconnect_provider
|
48
49
|
|
49
|
-
def initialize(url: nil, entity_id: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
|
50
|
+
def initialize(url: nil, entity_id: nil, entity_identifier: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
|
50
51
|
raise "URL is nil or empty, but URL is required" if url.nil? || url.empty?
|
51
52
|
# raise "URL is improper. URL must contain zuora.com, zuora.eu, or zuora.na" if /zuora.com|zuora.eu|zuora.na/ === url
|
52
53
|
self.hostname = /(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url)[0] if !/(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url).nil?
|
@@ -60,6 +61,8 @@ module ZuoraAPI
|
|
60
61
|
self.url = url
|
61
62
|
end
|
62
63
|
self.entity_id = get_entity_id(entity_id: entity_id)
|
64
|
+
self.entity_identifier = entity_identifier
|
65
|
+
self.entity_header_type = :entity_id
|
63
66
|
self.errors = Hash.new
|
64
67
|
self.current_session = session
|
65
68
|
self.bearer_token = bearer_token
|
@@ -75,7 +78,7 @@ module ZuoraAPI
|
|
75
78
|
zsession = cookies["ZSession"]
|
76
79
|
begin
|
77
80
|
if !zsession.blank?
|
78
|
-
response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
81
|
+
response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
79
82
|
output_json = JSON.parse(response.body)
|
80
83
|
else
|
81
84
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -91,7 +94,7 @@ module ZuoraAPI
|
|
91
94
|
zsession = cookies["ZSession"]
|
92
95
|
begin
|
93
96
|
if zsession.present?
|
94
|
-
response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
97
|
+
response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
95
98
|
output_json = JSON.parse(response.body)
|
96
99
|
else
|
97
100
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -107,7 +110,7 @@ module ZuoraAPI
|
|
107
110
|
zsession = cookies["ZSession"]
|
108
111
|
begin
|
109
112
|
if !zsession.blank?
|
110
|
-
response = HTTParty.put("https://#{self.hostname}/apps/v1/preference/navigation", :body => state.to_json, :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
113
|
+
response = HTTParty.put("https://#{self.hostname}/apps/v1/preference/navigation", :body => state.to_json, :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
111
114
|
output_json = JSON.parse(response.body)
|
112
115
|
else
|
113
116
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -123,7 +126,7 @@ module ZuoraAPI
|
|
123
126
|
zsession = cookies["ZSession"]
|
124
127
|
begin
|
125
128
|
if !zsession.blank?
|
126
|
-
response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
129
|
+
response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
127
130
|
output_json = JSON.parse(response.body)
|
128
131
|
else
|
129
132
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -176,7 +179,7 @@ module ZuoraAPI
|
|
176
179
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Zuora User ID not provided")
|
177
180
|
end
|
178
181
|
elsif !client_id.nil? && !client_secret.nil?
|
179
|
-
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'})
|
182
|
+
bearer_response = HTTParty.post("https://#{self.hostname}/oauth/token", :headers => {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json', "User-Agent" => USER_AGENT}, :body => {'client_id' => client_id, 'client_secret' => URI::encode(client_secret), 'grant_type' => 'client_credentials'})
|
180
183
|
bearer_hash = JSON.parse(bearer_response.body)
|
181
184
|
bearer_token = bearer_hash["access_token"]
|
182
185
|
authorization = "Bearer #{bearer_token}"
|
@@ -184,7 +187,7 @@ module ZuoraAPI
|
|
184
187
|
|
185
188
|
if !authorization.blank? && !user_id.blank? && !entity_ids.blank?
|
186
189
|
endpoint = chomp_v1_from_genesis_endpoint ? self.rest_endpoint.chomp("v1/").concat("genesis/clients") : self.rest_endpoint("genesis/clients")
|
187
|
-
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)
|
190
|
+
oauth_response = HTTParty.post(endpoint, :headers => {'authorization' => authorization, 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT}, :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)
|
188
191
|
output_json = JSON.parse(oauth_response.body)
|
189
192
|
if oauth_response.code == 201
|
190
193
|
output_json["clientSecret"] = new_client_secret if !use_api_generated_client_secret
|
@@ -433,12 +436,12 @@ module ZuoraAPI
|
|
433
436
|
end
|
434
437
|
if single_transaction
|
435
438
|
xml["#{ns1}"].CallOptions do
|
436
|
-
xml.useSingleTransaction single_transaction
|
439
|
+
xml["#{ns1}"].useSingleTransaction single_transaction
|
437
440
|
end
|
438
441
|
end
|
439
442
|
if batch_size
|
440
443
|
xml["#{ns1}"].QueryOptions do
|
441
|
-
xml.batchSize batch_size
|
444
|
+
xml["#{ns1}"].batchSize batch_size
|
442
445
|
end
|
443
446
|
end
|
444
447
|
end
|
@@ -453,6 +456,7 @@ module ZuoraAPI
|
|
453
456
|
|
454
457
|
headers.merge!({ 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'})
|
455
458
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
459
|
+
headers["User-Agent"] = USER_AGENT
|
456
460
|
|
457
461
|
request = HTTParty::Request.new(
|
458
462
|
Net::HTTP::Post,
|
@@ -1020,13 +1024,42 @@ module ZuoraAPI
|
|
1020
1024
|
return self.get_file(url: self.aqua_endpoint("file/#{fileId}"))
|
1021
1025
|
end
|
1022
1026
|
|
1027
|
+
def entity_header
|
1028
|
+
if self.entity_header_type == :entity_name && self.entity_identifier.present?
|
1029
|
+
{ "entityName" => self.entity_identifier }
|
1030
|
+
elsif self.entity_id.present?
|
1031
|
+
{ "Zuora-Entity-Ids" => self.entity_id }
|
1032
|
+
else
|
1033
|
+
{}
|
1034
|
+
end
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
def insert_entity_header(destination_headers, lookup_headers: nil)
|
1038
|
+
# The entity header may be added to a place other than where we look for it
|
1039
|
+
lookup_headers = destination_headers if lookup_headers.nil?
|
1040
|
+
|
1041
|
+
entity_header_options = %w(zuora-entity-ids entityid entityname)
|
1042
|
+
# If the customer doesn't supply an entity header, fill it in
|
1043
|
+
if (entity_header_options & lookup_headers.keys.map(&:downcase)).blank?
|
1044
|
+
entity_header = self.entity_header
|
1045
|
+
if entity_header.present?
|
1046
|
+
destination_headers.merge!(entity_header)
|
1047
|
+
entity_header_options_to_exclude =
|
1048
|
+
entity_header_options.
|
1049
|
+
reject { |header| header == entity_header.keys.first&.downcase }
|
1050
|
+
destination_headers.delete_if { |key, _| entity_header_options_to_exclude.include?(key.to_s.downcase) }
|
1051
|
+
end
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
|
1023
1055
|
def describe_call(object = nil, log_errors = true)
|
1024
1056
|
tries ||= 2
|
1025
1057
|
|
1026
1058
|
base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
|
1027
1059
|
url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
|
1028
|
-
headers =
|
1029
|
-
|
1060
|
+
headers = { "Content-Type" => "text/xml; charset=utf-8" }.merge(self.entity_header)
|
1061
|
+
|
1062
|
+
response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic), "User-Agent" => USER_AGENT}.merge(headers), :timeout => 130)
|
1030
1063
|
|
1031
1064
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
|
1032
1065
|
|
@@ -1112,12 +1145,11 @@ module ZuoraAPI
|
|
1112
1145
|
authentication_headers = {}
|
1113
1146
|
if z_session
|
1114
1147
|
authentication_headers = {"Authorization" => self.get_session(prefix: true, auth_type: session_type, zuora_track_id: zuora_track_id) }
|
1115
|
-
|
1116
|
-
|
1117
|
-
authentication_headers.delete_if { |key, value| ["entityId", "entityName"].include?(key.to_s) }
|
1118
|
-
end
|
1148
|
+
|
1149
|
+
self.insert_entity_header(authentication_headers, lookup_headers: headers)
|
1119
1150
|
end
|
1120
1151
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1152
|
+
headers['User-Agent'] = USER_AGENT
|
1121
1153
|
|
1122
1154
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
1123
1155
|
|
@@ -1279,10 +1311,12 @@ module ZuoraAPI
|
|
1279
1311
|
http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
|
1280
1312
|
if z_session
|
1281
1313
|
headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
|
1282
|
-
|
1314
|
+
|
1315
|
+
self.insert_entity_header(headers)
|
1283
1316
|
end
|
1284
1317
|
|
1285
1318
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1319
|
+
headers["User-Agent"] = USER_AGENT
|
1286
1320
|
|
1287
1321
|
response_save = nil
|
1288
1322
|
http.request_get(uri.request_uri, headers) do |response|
|
@@ -32,7 +32,7 @@ module ZuoraAPI
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def get_z_session(debug: false, zuora_track_id: nil)
|
35
|
-
headers = self.
|
35
|
+
headers = self.entity_header
|
36
36
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
37
37
|
output_json, response = self.rest_call(:url => self.rest_endpoint("connections"), :session_type => :bearer, :headers => headers)
|
38
38
|
begin
|
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.
|
4
|
+
version: 1.10.0
|
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: 2021-
|
11
|
+
date: 2021-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
- !ruby/object:Gem::Version
|
220
220
|
version: '0'
|
221
221
|
requirements: []
|
222
|
-
rubygems_version: 3.2.
|
222
|
+
rubygems_version: 3.2.22
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: Gem that provides easy integration to Zuora
|