zuora_api 1.9.08 → 1.9.09
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/exceptions.rb +0 -6
- data/lib/zuora_api/login.rb +24 -96
- 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: a6da8c9fbf54221b62336d0221ada0f53e9d22690b7a6a52cd83f214314b5ba5
|
4
|
+
data.tar.gz: be31b09eef19df8b8d1fcbd70b9a11980f125c4eb4d5f96c3259ed516ab88934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6382ae611e80b38e574357baa771b432c4e554662293e98e4a73ca446c9445264d902f0b604ee071fe9dac6cf6bee4fde8319f0f782975955fdd562cf921b6c
|
7
|
+
data.tar.gz: 1008b0e7e533e01b6636cc82e3e79b21c825d095d789d83c73c96142d9de78556c0caa38775aedb97a3b27e43a93f16281680f10a7d988fb005951084a36f75e
|
data/lib/zuora_api/exceptions.rb
CHANGED
@@ -125,12 +125,6 @@ module ZuoraAPI
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
class ZuoraAPIRequestConcurrentLimit < ZuoraAPIRequestLimit
|
129
|
-
end
|
130
|
-
|
131
|
-
class ZuoraAPIRequestRateLimit < ZuoraAPIRequestLimit
|
132
|
-
end
|
133
|
-
|
134
128
|
class ZuoraAPIUnkownError < Error
|
135
129
|
attr_reader :code, :response
|
136
130
|
attr_writer :default_message
|
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,
|
@@ -29,8 +30,6 @@ module ZuoraAPI
|
|
29
30
|
ZUORA_API_ERRORS = [
|
30
31
|
ZuoraAPI::Exceptions::ZuoraAPIError,
|
31
32
|
ZuoraAPI::Exceptions::ZuoraAPIRequestLimit,
|
32
|
-
ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit,
|
33
|
-
ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit,
|
34
33
|
ZuoraAPI::Exceptions::ZuoraAPILockCompetition,
|
35
34
|
ZuoraAPI::Exceptions::ZuoraAPITemporaryError,
|
36
35
|
ZuoraAPI::Exceptions::ZuoraDataIntegrity,
|
@@ -77,7 +76,7 @@ module ZuoraAPI
|
|
77
76
|
zsession = cookies["ZSession"]
|
78
77
|
begin
|
79
78
|
if !zsession.blank?
|
80
|
-
response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
79
|
+
response = HTTParty.get("https://#{self.hostname}/apps/v1/identity", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
81
80
|
output_json = JSON.parse(response.body)
|
82
81
|
else
|
83
82
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -93,7 +92,7 @@ module ZuoraAPI
|
|
93
92
|
zsession = cookies["ZSession"]
|
94
93
|
begin
|
95
94
|
if zsession.present?
|
96
|
-
response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
95
|
+
response = HTTParty.get("https://#{self.hostname}/apps/v1/navigation", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
97
96
|
output_json = JSON.parse(response.body)
|
98
97
|
else
|
99
98
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -109,7 +108,7 @@ module ZuoraAPI
|
|
109
108
|
zsession = cookies["ZSession"]
|
110
109
|
begin
|
111
110
|
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'})
|
111
|
+
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
112
|
output_json = JSON.parse(response.body)
|
114
113
|
else
|
115
114
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -125,7 +124,7 @@ module ZuoraAPI
|
|
125
124
|
zsession = cookies["ZSession"]
|
126
125
|
begin
|
127
126
|
if !zsession.blank?
|
128
|
-
response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json'})
|
127
|
+
response = HTTParty.post("https://#{self.hostname}/apps/v1/navigation/fetch", :headers => {'Cookie' => "ZSession=#{zsession}", 'Content-Type' => 'application/json', "User-Agent" => USER_AGENT})
|
129
128
|
output_json = JSON.parse(response.body)
|
130
129
|
else
|
131
130
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("No ZSession cookie present")
|
@@ -140,13 +139,14 @@ module ZuoraAPI
|
|
140
139
|
def reporting_url(path)
|
141
140
|
map = {"US" => {"Sandbox" => "https://zconnectsandbox.zuora.com/api/rest/v1/",
|
142
141
|
"Production" => "https://zconnect.zuora.com/api/rest/v1/",
|
143
|
-
"Test" => "https://
|
142
|
+
"Test" => "https://zconnect-services0001.test.zuora.com/api/rest/v1/",
|
144
143
|
"Staging" => "https://reporting-stg11.zan.svc.auw2.zuora.com/api/rest/v1/",
|
145
144
|
"Performance" => "https://zconnectpt1.zuora.com/api/rest/v1/",
|
146
145
|
"Services" => "https://reporting-svc08.svc.auw2.zuora.com/api/rest/v1/"},
|
147
146
|
"EU" => {"Sandbox" => "https://zconnect.sandbox.eu.zuora.com/api/rest/v1/",
|
148
147
|
"Production" => "https://zconnect.eu.zuora.com/api/rest/v1/",
|
149
|
-
"Services"=> "https://reporting-sbx0000.sbx.aec1.zuora.com/api/rest/v1/"
|
148
|
+
"Services"=> "https://reporting-sbx0000.sbx.aec1.zuora.com/api/rest/v1/",
|
149
|
+
"Test" => "https://zconnect-services0002.test.eu.zuora.com/api/rest/v1/"},
|
150
150
|
"NA" => {"Sandbox" => "https://zconnect.sandbox.na.zuora.com/api/rest/v1/",
|
151
151
|
"Production" => "https://zconnect.na.zuora.com/api/rest/v1/",
|
152
152
|
"Services"=> ""}
|
@@ -177,7 +177,7 @@ module ZuoraAPI
|
|
177
177
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Zuora User ID not provided")
|
178
178
|
end
|
179
179
|
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'})
|
180
|
+
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
181
|
bearer_hash = JSON.parse(bearer_response.body)
|
182
182
|
bearer_token = bearer_hash["access_token"]
|
183
183
|
authorization = "Bearer #{bearer_token}"
|
@@ -185,7 +185,7 @@ module ZuoraAPI
|
|
185
185
|
|
186
186
|
if !authorization.blank? && !user_id.blank? && !entity_ids.blank?
|
187
187
|
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)
|
188
|
+
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
189
|
output_json = JSON.parse(oauth_response.body)
|
190
190
|
if oauth_response.code == 201
|
191
191
|
output_json["clientSecret"] = new_client_secret if !use_api_generated_client_secret
|
@@ -434,12 +434,12 @@ module ZuoraAPI
|
|
434
434
|
end
|
435
435
|
if single_transaction
|
436
436
|
xml["#{ns1}"].CallOptions do
|
437
|
-
xml.useSingleTransaction single_transaction
|
437
|
+
xml["#{ns1}"].useSingleTransaction single_transaction
|
438
438
|
end
|
439
439
|
end
|
440
440
|
if batch_size
|
441
441
|
xml["#{ns1}"].QueryOptions do
|
442
|
-
xml.batchSize batch_size
|
442
|
+
xml["#{ns1}"].batchSize batch_size
|
443
443
|
end
|
444
444
|
end
|
445
445
|
end
|
@@ -454,6 +454,7 @@ module ZuoraAPI
|
|
454
454
|
|
455
455
|
headers.merge!({ 'Content-Type' => "text/xml; charset=utf-8", 'Accept' => 'text/xml'})
|
456
456
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
457
|
+
headers["User-Agent"] = USER_AGENT
|
457
458
|
|
458
459
|
request = HTTParty::Request.new(
|
459
460
|
Net::HTTP::Post,
|
@@ -613,7 +614,10 @@ module ZuoraAPI
|
|
613
614
|
case response.code
|
614
615
|
when 504
|
615
616
|
raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from 'https://#{rest_domain(endpoint: request_uri)}'", response)
|
616
|
-
when
|
617
|
+
when 429
|
618
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", response)
|
619
|
+
when 401
|
620
|
+
|
617
621
|
else
|
618
622
|
if body.class == Hash
|
619
623
|
case request_path
|
@@ -630,21 +634,6 @@ module ZuoraAPI
|
|
630
634
|
when :SOAP
|
631
635
|
error, success, message = get_soap_error_and_message(body)
|
632
636
|
|
633
|
-
if response.code == 429
|
634
|
-
if message.to_s.downcase.include?('concurrent')
|
635
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit.new(
|
636
|
-
"The total number of concurrent requests has exceeded the limit allowed by the system. " \
|
637
|
-
"Please resubmit your request later.",
|
638
|
-
response
|
639
|
-
)
|
640
|
-
else
|
641
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new(
|
642
|
-
"Rate limiting. Please resubmit your request later.",
|
643
|
-
response
|
644
|
-
)
|
645
|
-
end
|
646
|
-
end
|
647
|
-
|
648
637
|
if body.xpath('//fns:LoginFault', 'fns' =>'http://fault.api.zuora.com/').present?
|
649
638
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response)
|
650
639
|
end
|
@@ -737,12 +726,7 @@ module ZuoraAPI
|
|
737
726
|
codes_array = codes_array.push(body.dig("error", 'code')).compact
|
738
727
|
end
|
739
728
|
|
740
|
-
|
741
|
-
if body_message.include?('rate limit exceeded')
|
742
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new("The total number of requests has exceeded the rate limit allowed by the system. Please resubmit your request later.", response)
|
743
|
-
end
|
744
|
-
|
745
|
-
if body_message.include?('request exceeded limit')
|
729
|
+
if body['message'] == 'request exceeded limit'
|
746
730
|
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", response)
|
747
731
|
end
|
748
732
|
|
@@ -814,7 +798,7 @@ module ZuoraAPI
|
|
814
798
|
|
815
799
|
#Request exceeded limit
|
816
800
|
if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
|
817
|
-
raise ZuoraAPI::Exceptions::
|
801
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
|
818
802
|
end
|
819
803
|
|
820
804
|
#All Errors catch
|
@@ -822,10 +806,6 @@ module ZuoraAPI
|
|
822
806
|
raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{messages_array.join(', ')}", response)
|
823
807
|
end
|
824
808
|
|
825
|
-
if response.code == 429
|
826
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", response)
|
827
|
-
end
|
828
|
-
|
829
809
|
#Zuora REST Query Errors
|
830
810
|
if body["faultcode"].present?
|
831
811
|
raise_errors_helper(error: body["faultcode"], message: body["faultstring"], response: response)
|
@@ -961,11 +941,7 @@ module ZuoraAPI
|
|
961
941
|
when /.*INVALID_SESSION/
|
962
942
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response, errors, success)
|
963
943
|
when /.*REQUEST_EXCEEDED_LIMIT/
|
964
|
-
|
965
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestConcurrentLimit.new(message, response, errors, success)
|
966
|
-
else
|
967
|
-
raise ZuoraAPI::Exceptions::ZuoraAPIRequestRateLimit.new(message, response, errors, success)
|
968
|
-
end
|
944
|
+
raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new(message, response, errors, success)
|
969
945
|
when /.*LOCK_COMPETITION/
|
970
946
|
raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new(message, response, errors, success)
|
971
947
|
when /.*BATCH_FAIL_ERROR/
|
@@ -1052,7 +1028,7 @@ module ZuoraAPI
|
|
1052
1028
|
base = self.url.include?(".com") ? self.url.split(".com")[0].concat(".com") : self.url.split(".eu")[0].concat(".eu")
|
1053
1029
|
url = object ? "#{base}/apps/api/describe/#{object}" : "#{base}/apps/api/describe/"
|
1054
1030
|
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)
|
1031
|
+
response = HTTParty.get(url, headers: {"Authorization" => self.get_session(prefix: true, auth_type: :basic), "User-Agent" => USER_AGENT}.merge(headers), :timeout => 130)
|
1056
1032
|
|
1057
1033
|
raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error.present? ? self.current_error : 'Describe call 401', response) if response.code == 401
|
1058
1034
|
|
@@ -1144,6 +1120,7 @@ module ZuoraAPI
|
|
1144
1120
|
end
|
1145
1121
|
end
|
1146
1122
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1123
|
+
headers['User-Agent'] = USER_AGENT
|
1147
1124
|
|
1148
1125
|
modified_headers = {'Content-Type' => "application/json; charset=utf-8"}.merge(authentication_headers).merge(headers)
|
1149
1126
|
|
@@ -1309,6 +1286,7 @@ module ZuoraAPI
|
|
1309
1286
|
end
|
1310
1287
|
|
1311
1288
|
headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present?
|
1289
|
+
headers["User-Agent"] = USER_AGENT
|
1312
1290
|
|
1313
1291
|
response_save = nil
|
1314
1292
|
http.request_get(uri.request_uri, headers) do |response|
|
@@ -1423,56 +1401,6 @@ module ZuoraAPI
|
|
1423
1401
|
raise
|
1424
1402
|
end
|
1425
1403
|
|
1426
|
-
def create_data_source_export(query: "", encrypted: false, zip: true, z_track_id: "")
|
1427
|
-
begin
|
1428
|
-
output_xml, input_xml = self.soap_call(debug: false, timeout_retry: true, zuora_track_id: z_track_id) do |xml|
|
1429
|
-
xml['ns1'].create do
|
1430
|
-
xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
|
1431
|
-
xml['ns2'].Format 'csv'
|
1432
|
-
xml['ns2'].Zip zip
|
1433
|
-
xml['ns2'].Name 'googman'
|
1434
|
-
xml['ns2'].Query query
|
1435
|
-
xml['ns2'].Encrypted encrypted
|
1436
|
-
end
|
1437
|
-
end
|
1438
|
-
end
|
1439
|
-
|
1440
|
-
return output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
|
1441
|
-
rescue Exception => ex
|
1442
|
-
raise ex.class.new("#{z_track_id} #{ex.message}")
|
1443
|
-
end
|
1444
|
-
end
|
1445
|
-
|
1446
|
-
def check_export_status(export_id: "")
|
1447
|
-
begin
|
1448
|
-
response, full_response = self.rest_call(method: :get,url: self.rest_endpoint("object/export/#{export_id}"))
|
1449
|
-
|
1450
|
-
return full_response.parsed_response
|
1451
|
-
rescue Exception => ex
|
1452
|
-
raise ex
|
1453
|
-
end
|
1454
|
-
end
|
1455
|
-
|
1456
|
-
def get_export_file(file_id: "", extract: true, zip: true)
|
1457
|
-
begin
|
1458
|
-
export_file_path = self.get_file(:url => self.rest_endpoint("files/#{file_id}")).path
|
1459
|
-
|
1460
|
-
if extract && zip
|
1461
|
-
require "zip"
|
1462
|
-
new_path = export_file_path.partition('.zip').first
|
1463
|
-
zipped = Zip::File.open(export_file_path)
|
1464
|
-
file_handle = zipped.entries.first
|
1465
|
-
file_handle.extract(new_path)
|
1466
|
-
File.delete(export_file_path)
|
1467
|
-
return new_path
|
1468
|
-
else
|
1469
|
-
return export_file_path
|
1470
|
-
end
|
1471
|
-
rescue Exception => ex
|
1472
|
-
raise ex
|
1473
|
-
end
|
1474
|
-
end
|
1475
|
-
|
1476
1404
|
def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
|
1477
1405
|
tries ||= 3
|
1478
1406
|
|
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.9.
|
4
|
+
version: 1.9.09
|
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-08-04 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
|