zuora_api 1.9.08 → 1.10.2

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: a012abdd5eacb3b9743866d78557e5bb97f52067de92a9aec0e46d45252e190c
4
- data.tar.gz: 005d7186d019c95060f7ec531f0b548382dc6e274e80522d97a79500ee645938
3
+ metadata.gz: 8cf78cb3b1e25a9394f07c8557a23b8822d4f5cf48839bfad5e6f8e2ab3ad1e7
4
+ data.tar.gz: 76d6cd10a87cbae7dc3a5898192c9cc1c8683c374ae0008b116bef46ecc79cda
5
5
  SHA512:
6
- metadata.gz: 81d8472647c0b37ceee7fadf82610b28deb9b52b35f84740840de68b65f07ded753114e5e86ab6f936740eedf730a9a42f57bdf0e08b91c8a63b711300fb8c5b
7
- data.tar.gz: 2aef7becdbfa2b9b4bdf5d598bd5be23f528f1a09181178df233d8ef218f1c801978d1d1c60d20808b07b7e83981d2bb4dbe1c786a5616977713c064f8fade62
6
+ metadata.gz: 4e53ec1c8acb9ba3d7ce1247f5516162d85095567421082b025fd04117a4cdc463854ec136dc09f3283b09af493a1d68b17cda7c29f0d18d48faabfef949dea5
7
+ data.tar.gz: 0be11b3df708385da409848b1c953be59cd3efe4c8b658d55dd06e781a9c347df58cd809f32edb88063be4ea6ea11fada13396177ddb08233534afffd3458463
@@ -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': '107.0', 'Sandbox': '107.0', 'Production': '107.0', 'Performance': '107.0', 'Services': '96.0', 'Unknown': '96.0', 'Staging': '107.0'}.freeze
10
+ MIN_Endpoints = {'Test': '114.0', 'Sandbox': '114.0', 'Production': '114.0', 'Performance': '114.0', 'Services': '96.0', 'Unknown': '96.0', 'Staging': '114.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,
@@ -46,9 +47,9 @@ module ZuoraAPI
46
47
  ZuoraAPI::Exceptions::ZuoraUnexpectedError
47
48
  ].freeze
48
49
 
49
- 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
50
+ 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
50
51
 
51
- def initialize(url: nil, entity_id: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
52
+ def initialize(url: nil, entity_id: nil, entity_identifier: nil, session: nil, status: nil, bearer_token: nil, oauth_session_expires_at: nil, **keyword_args)
52
53
  raise "URL is nil or empty, but URL is required" if url.nil? || url.empty?
53
54
  # raise "URL is improper. URL must contain zuora.com, zuora.eu, or zuora.na" if /zuora.com|zuora.eu|zuora.na/ === url
54
55
  self.hostname = /(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url)[0] if !/(?<=https:\/\/|http:\/\/)(.*?)(?=\/|$)/.match(url).nil?
@@ -62,6 +63,8 @@ module ZuoraAPI
62
63
  self.url = url
63
64
  end
64
65
  self.entity_id = get_entity_id(entity_id: entity_id)
66
+ self.entity_identifier = entity_identifier
67
+ self.entity_header_type = :entity_id
65
68
  self.errors = Hash.new
66
69
  self.current_session = session
67
70
  self.bearer_token = bearer_token
@@ -77,7 +80,7 @@ module ZuoraAPI
77
80
  zsession = cookies["ZSession"]
78
81
  begin
79
82
  if !zsession.blank?
80
- response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
83
+ response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
81
84
  output_json = JSON.parse(response.body)
82
85
  else
83
86
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
@@ -93,7 +96,7 @@ module ZuoraAPI
93
96
  zsession = cookies["ZSession"]
94
97
  begin
95
98
  if zsession.present?
96
- response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
99
+ response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
97
100
  output_json = JSON.parse(response.body)
98
101
  else
99
102
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
@@ -109,7 +112,7 @@ module ZuoraAPI
109
112
  zsession = cookies["ZSession"]
110
113
  begin
111
114
  if !zsession.blank?
112
- response = HTTParty.put("https://#{self.hostname}/apps/v1/preference/navigation", :body => state.to_json, :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
115
+ 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})
113
116
  output_json = JSON.parse(response.body)
114
117
  else
115
118
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
@@ -125,7 +128,7 @@ module ZuoraAPI
125
128
  zsession = cookies["ZSession"]
126
129
  begin
127
130
  if !zsession.blank?
128
- response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
131
+ response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
129
132
  output_json = JSON.parse(response.body)
130
133
  else
131
134
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
@@ -140,13 +143,14 @@ module ZuoraAPI
140
143
  def reporting_url(path)
141
144
  map = {"US" => {"Sandbox" => "https://zconnectsandbox.zuora.com/api/rest/v1/",
142
145
  "Production" => "https://zconnect.zuora.com/api/rest/v1/",
143
- "Test" => "https://reporting-sbx.zan.0001.sbx.auw2.zuora.com/api/rest/v1/",
146
+ "Test" => "https://zconnect-services0001.test.zuora.com/api/rest/v1/",
144
147
  "Staging" => "https://reporting-stg11.zan.svc.auw2.zuora.com/api/rest/v1/",
145
148
  "Performance" => "https://zconnectpt1.zuora.com/api/rest/v1/",
146
149
  "Services" => "https://reporting-svc08.svc.auw2.zuora.com/api/rest/v1/"},
147
150
  "EU" => {"Sandbox" => "https://zconnect.sandbox.eu.zuora.com/api/rest/v1/",
148
151
  "Production" => "https://zconnect.eu.zuora.com/api/rest/v1/",
149
- "Services"=> "https://reporting-sbx0000.sbx.aec1.zuora.com/api/rest/v1/"},
152
+ "Services"=> "https://reporting-sbx0000.sbx.aec1.zuora.com/api/rest/v1/",
153
+ "Test" => "https://zconnect-services0002.test.eu.zuora.com/api/rest/v1/"},
150
154
  "NA" => {"Sandbox" => "https://zconnect.sandbox.na.zuora.com/api/rest/v1/",
151
155
  "Production" => "https://zconnect.na.zuora.com/api/rest/v1/",
152
156
  "Services"=> ""}
@@ -177,7 +181,7 @@ module ZuoraAPI
177
181
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Zuora User ID not provided")
178
182
  end
179
183
  elsif !client_id.nil? && !client_secret.nil?
180
- 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'})
184
+ 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'})
181
185
  bearer_hash = JSON.parse(bearer_response.body)
182
186
  bearer_token = bearer_hash["access_token"]
183
187
  authorization = "Bearer #{bearer_token}"
@@ -185,7 +189,7 @@ module ZuoraAPI
185
189
 
186
190
  if !authorization.blank? && !user_id.blank? && !entity_ids.blank?
187
191
  endpoint = chomp_v1_from_genesis_endpoint ? self.rest_endpoint.chomp("v1/").concat("genesis/clients") : self.rest_endpoint("genesis/clients")
188
- 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)
192
+ 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)
189
193
  output_json = JSON.parse(oauth_response.body)
190
194
  if oauth_response.code == 201
191
195
  output_json["clientSecret"] = new_client_secret if !use_api_generated_client_secret
@@ -434,12 +438,12 @@ module ZuoraAPI
434
438
  end
435
439
  if single_transaction
436
440
  xml["#{ns1}"].CallOptions do
437
- xml.useSingleTransaction single_transaction
441
+ xml["#{ns1}"].useSingleTransaction single_transaction
438
442
  end
439
443
  end
440
444
  if batch_size
441
445
  xml["#{ns1}"].QueryOptions do
442
- xml.batchSize batch_size
446
+ xml["#{ns1}"].batchSize batch_size
443
447
  end
444
448
  end
445
449
  end
@@ -454,6 +458,9 @@ module ZuoraAPI
454
458
 
455
459
  headers.merge!({ 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'})
456
460
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
461
+ headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
462
+
463
+ headers["User-Agent"] = USER_AGENT
457
464
 
458
465
  request = HTTParty::Request.new(
459
466
  Net::HTTP::Post,
@@ -1046,13 +1053,42 @@ module ZuoraAPI
1046
1053
  return self.get_file(url: self.aqua_endpoint("file/#{fileId}"))
1047
1054
  end
1048
1055
 
1056
+ def entity_header
1057
+ if self.entity_header_type == :entity_name && self.entity_identifier.present?
1058
+ { "entityName" => self.entity_identifier }
1059
+ elsif self.entity_id.present?
1060
+ { "Zuora-Entity-Ids" => self.entity_id }
1061
+ else
1062
+ {}
1063
+ end
1064
+ end
1065
+
1066
+ def insert_entity_header(destination_headers, lookup_headers: nil)
1067
+ # The entity header may be added to a place other than where we look for it
1068
+ lookup_headers = destination_headers if lookup_headers.nil?
1069
+
1070
+ entity_header_options = %w(zuora-entity-ids entityid entityname)
1071
+ # If the customer doesn't supply an entity header, fill it in
1072
+ if (entity_header_options & lookup_headers.keys.map(&:downcase)).blank?
1073
+ entity_header = self.entity_header
1074
+ if entity_header.present?
1075
+ destination_headers.merge!(entity_header)
1076
+ entity_header_options_to_exclude =
1077
+ entity_header_options.
1078
+ reject { |header| header == entity_header.keys.first&.downcase }
1079
+ destination_headers.delete_if { |key, _| entity_header_options_to_exclude.include?(key.to_s.downcase) }
1080
+ end
1081
+ end
1082
+ end
1083
+
1049
1084
  def describe_call(object = nil, log_errors = true)
1050
1085
  tries ||= 2
1051
1086
 
1052
1087
  base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
1053
1088
  url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
1054
- headers = self.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id, 'Content-Type' => "text/xml; charset=utf-8"} : {'Content-Type' => "text/xml; charset=utf-8"}
1055
- response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic)}.merge(headers), :timeout => 130)
1089
+ headers = { "Content-Type" => "text/xml; charset=utf-8" }.merge(self.entity_header)
1090
+
1091
+ response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic), "User-Agent" => USER_AGENT}.merge(headers), :timeout => 130)
1056
1092
 
1057
1093
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
1058
1094
 
@@ -1138,12 +1174,13 @@ module ZuoraAPI
1138
1174
  authentication_headers = {}
1139
1175
  if z_session
1140
1176
  authentication_headers = {"Authorization" => self.get_session(prefix: true, auth_type: session_type, zuora_track_id: zuora_track_id) }
1141
- if self.entity_id.present?
1142
- authentication_headers["Zuora-Entity-Ids"] = self.entity_id if headers.dig("Zuora-Entity-Ids").nil?
1143
- authentication_headers.delete_if { |key, value| ["entityId", "entityName"].include?(key.to_s) }
1144
- end
1177
+
1178
+ self.insert_entity_header(authentication_headers, lookup_headers: headers)
1145
1179
  end
1146
1180
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
1181
+ headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
1182
+
1183
+ headers['User-Agent'] = USER_AGENT
1147
1184
 
1148
1185
  modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
1149
1186
 
@@ -1305,10 +1342,14 @@ module ZuoraAPI
1305
1342
  http.use_ssl = true if !uri.scheme.nil? && uri.scheme.downcase == 'https'
1306
1343
  if z_session
1307
1344
  headers = headers.merge({"Authorization" => self.get_session(prefix: true)})
1308
- headers = headers.merge({"Zuora-Entity-Ids" => self.entity_id}) if !self.entity_id.blank?
1345
+
1346
+ self.insert_entity_header(headers)
1309
1347
  end
1310
1348
 
1311
1349
  headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
1350
+ headers['X-Amzn-Trace-Id'] = zuora_track_id if zuora_track_id.present?
1351
+
1352
+ headers["User-Agent"] = USER_AGENT
1312
1353
 
1313
1354
  response_save = nil
1314
1355
  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.entity_id.present? ? {"Zuora-Entity-Ids" => self.entity_id } : {}
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"),
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.9.08"
2
+ VERSION = "1.10.2"
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.9.08
4
+ version: 1.10.2
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-05-26 00:00:00.000000000 Z
11
+ date: 2022-01-14 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.15
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