zuora_api 1.9.07 → 1.10.1
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 +54 -17
- data/lib/zuora_api/logins/oauth.rb +3 -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: c3b3400576f3df87efec934f2e76fc13b6e427c20cb36dff8e4c81dc95abfc1d
|
4
|
+
data.tar.gz: 9250a4ef4c4b1dc7de382e2325533536e646d3f36ada93afeb59a0aa90a87166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1ad5caf8f7689f9522e5b880cf742d9bd3a20f52b662dfb59f091c17c986ae972b66f97adc2752a16aee77fcd019934e338276ae61ba802918e65543df1ccbf
|
7
|
+
data.tar.gz: 2ec1e093f0bfb3d7815434addb8372e5cf6ddee2b06957add664c86b411e2c026e8e018ad0c7a9508c12a660d4bf1373f8099e10ca191a462c338d9a6ac99a58
|
data/lib/zuora_api/login.rb
CHANGED
@@ -9,6 +9,7 @@ module ZuoraAPI
|
|
9
9
|
REGIONS = [EU = 'EU', US = 'US', NA = 'NA' ]
|
10
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,8 @@ 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['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
|
460
|
+
headers["User-Agent"] = USER_AGENT
|
456
461
|
|
457
462
|
request = HTTParty::Request.new(
|
458
463
|
Net::HTTP::Post,
|
@@ -1020,13 +1025,42 @@ module ZuoraAPI
|
|
1020
1025
|
return self.get_file(url: self.aqua_endpoint("file/#{fileId}"))
|
1021
1026
|
end
|
1022
1027
|
|
1028
|
+
def entity_header
|
1029
|
+
if self.entity_header_type == :entity_name && self.entity_identifier.present?
|
1030
|
+
{ "entityName" => self.entity_identifier }
|
1031
|
+
elsif self.entity_id.present?
|
1032
|
+
{ "Zuora-Entity-Ids" => self.entity_id }
|
1033
|
+
else
|
1034
|
+
{}
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def insert_entity_header(destination_headers, lookup_headers: nil)
|
1039
|
+
# The entity header may be added to a place other than where we look for it
|
1040
|
+
lookup_headers = destination_headers if lookup_headers.nil?
|
1041
|
+
|
1042
|
+
entity_header_options = %w(zuora-entity-ids entityid entityname)
|
1043
|
+
# If the customer doesn't supply an entity header, fill it in
|
1044
|
+
if (entity_header_options & lookup_headers.keys.map(&:downcase)).blank?
|
1045
|
+
entity_header = self.entity_header
|
1046
|
+
if entity_header.present?
|
1047
|
+
destination_headers.merge!(entity_header)
|
1048
|
+
entity_header_options_to_exclude =
|
1049
|
+
entity_header_options.
|
1050
|
+
reject { |header| header == entity_header.keys.first&.downcase }
|
1051
|
+
destination_headers.delete_if { |key, _| entity_header_options_to_exclude.include?(key.to_s.downcase) }
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
|
1023
1056
|
def describe_call(object = nil, log_errors = true)
|
1024
1057
|
tries ||= 2
|
1025
1058
|
|
1026
1059
|
base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
|
1027
1060
|
url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
|
1028
|
-
headers =
|
1029
|
-
|
1061
|
+
headers = { "Content-Type" => "text/xml; charset=utf-8" }.merge(self.entity_header)
|
1062
|
+
|
1063
|
+
response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic), "User-Agent" => USER_AGENT}.merge(headers), :timeout => 130)
|
1030
1064
|
|
1031
1065
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
|
1032
1066
|
|
@@ -1112,12 +1146,12 @@ module ZuoraAPI
|
|
1112
1146
|
authentication_headers = {}
|
1113
1147
|
if z_session
|
1114
1148
|
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
|
1149
|
+
|
1150
|
+
self.insert_entity_header(authentication_headers, lookup_headers: headers)
|
1119
1151
|
end
|
1120
1152
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1153
|
+
headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
|
1154
|
+
headers['User-Agent'] = USER_AGENT
|
1121
1155
|
|
1122
1156
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
1123
1157
|
|
@@ -1279,10 +1313,13 @@ module ZuoraAPI
|
|
1279
1313
|
http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
|
1280
1314
|
if z_session
|
1281
1315
|
headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
|
1282
|
-
|
1316
|
+
|
1317
|
+
self.insert_entity_header(headers)
|
1283
1318
|
end
|
1284
1319
|
|
1285
1320
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1321
|
+
headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
|
1322
|
+
headers["User-Agent"] = USER_AGENT
|
1286
1323
|
|
1287
1324
|
response_save = nil
|
1288
1325
|
http.request_get(uri.request_uri, headers) do |response|
|
@@ -32,8 +32,9 @@ 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
|
+
headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
|
37
38
|
output_json, response = self.rest_call(:url => self.rest_endpoint("connections"), :session_type => :bearer, :headers => headers)
|
38
39
|
begin
|
39
40
|
self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
|
@@ -54,6 +55,7 @@ module ZuoraAPI
|
|
54
55
|
|
55
56
|
headers = { "content-type" => "application/x-www-form-urlencoded" }
|
56
57
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
58
|
+
headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
|
57
59
|
|
58
60
|
output_json, response = self.rest_call(:method => :post,
|
59
61
|
url: self.rest_endpoint.chomp('v1/').concat("oauth/token"),
|
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.1
|
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-12-06 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.32
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: Gem that provides easy integration to Zuora
|