zuora_api 1.3.9993 → 1.3.9994

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
  SHA1:
3
- metadata.gz: f0202e43f863f6c4e5956313337ed743e5857fa3
4
- data.tar.gz: 0b57363605fb505c7ebab46ebcb2c638e59dddfb
3
+ metadata.gz: bb771efe44918a884178a46340720e08717a0e35
4
+ data.tar.gz: 0d22b870b2ed2543d57fed05f0ac56cc16636b98
5
5
  SHA512:
6
- metadata.gz: 342e6a5e2f71092949e01a1a2c139e4f7ae86a7d57d2fe5b45671d279e0a021342c58e12192b4fb1cb44289ec272db2cadc154ac3500cce4f3c83b9cb66a31be
7
- data.tar.gz: dcd429dca5c927f183766dc4c6df92cc0332f41b952a32c6161c22116d7624f187f5ee70c0e5ea0e040fe51a315a93225505e609182ad21e55a5b3422434a91a
6
+ metadata.gz: 65e01572cf4210b43f4718aecd47d62952204b33e5a8772d1a2764913129326e1097cadbdb30fd1e004ecea52873f9596860cae091459114a596e42d5a32b771
7
+ data.tar.gz: acef40f0eaac21596127aea716f321bf7b99d17f61a13cd81340e4fc68f8d8e612dfbb20f9416fb94d071af71d171c3cfcd71de4157d7335192c0ab12116f665
@@ -29,9 +29,8 @@ security-testing:
29
29
 
30
30
  rspec-testing:
31
31
  stage: test
32
- allow_failure: true
33
32
  script:
34
- - gem install rspec
33
+ - bundle install --path /cache
35
34
  - rspec
36
35
 
37
36
  rubygems-deploy:
@@ -5,7 +5,7 @@ module ZuoraAPI
5
5
  class Login
6
6
  ENVIRONMENTS = [SANDBOX = 'Sandbox', PRODUCTION = 'Production', PREFORMANCE = 'Preformance', SERVICES = 'Services', UNKNOWN = 'Unknown' ]
7
7
  REGIONS = [EU = 'EU', US = 'US' ]
8
- attr_accessor :username, :password, :region,:url, :wsdl_number, :status, :current_session, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id
8
+ attr_accessor :username, :password, :region,:url, :wsdl_number, :current_session, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name, :entity_id
9
9
 
10
10
  def initialize(username: nil, password: nil, url: nil, entity_id: nil, session: nil, **keyword_args)
11
11
  @username = username
@@ -115,6 +115,7 @@ module ZuoraAPI
115
115
  end
116
116
  @response_query = HTTParty.post(self.url,:body => request.to_xml, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => 10)
117
117
  @output_xml = Nokogiri::XML(@response_query.body)
118
+
118
119
  if !@response_query.success?
119
120
  self.current_session = nil
120
121
  if @output_xml.namespaces.size > 0 && @output_xml.xpath('//soapenv:Fault').size > 0
@@ -162,8 +163,18 @@ module ZuoraAPI
162
163
  self.status = 'No Service'
163
164
  end
164
165
  else
165
- self.current_session = (self.password.blank? && !self.current_session.blank?) ? self.current_session : @output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text
166
- self.username = @output_xml.xpath('//ns1:Username', 'ns1' =>'http://api.zuora.com/').text if self.username.blank?
166
+ #If Session only is used for Gem TODO Depercate
167
+ if (self.password.blank? && self.current_session.present?)
168
+ self.current_session = self.current_session
169
+ self.username = @output_xml.xpath('//ns1:Username', 'ns1' =>'http://api.zuora.com/').text if self.username.blank?
170
+
171
+ #Username & password combo
172
+ elsif (self.password.present? && self.username.present?)
173
+ retrieved_session = @output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text
174
+ raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("No session found for api call.") if retrieved_session.blank?
175
+ self.current_session = retrieved_session
176
+ end
177
+
167
178
  self.current_error = nil
168
179
  self.status = 'Active'
169
180
  end
@@ -252,35 +263,69 @@ module ZuoraAPI
252
263
  def raise_errors(type: :SOAP, body: nil, response: nil)
253
264
  case type
254
265
  when :SOAP
255
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "INVALID_SESSION")
256
-
257
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "REQUEST_EXCEEDED_LIMIT")
258
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}") if (!body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text.blank? && body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text == "REQUEST_EXCEEDED_LIMIT")
259
266
 
260
- raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if (!body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank? && body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text == "LOCK_COMPETITION")
261
- raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text}::#{body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}") if (!body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text.blank? && body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text == "LOCK_COMPETITION")
267
+ error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
268
+ message = body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text
262
269
 
263
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{body.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}") if !body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank?
264
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body.xpath('//faultcode').text}::#{body.xpath('//faultstring').text}") if !body.xpath('//faultcode').text.blank?
270
+ if error.blank? || message.blank?
271
+ error = body.xpath('//ns1:Code', 'ns1' =>'http://api.zuora.com/').text
272
+ message = body.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text
273
+ end
274
+ if error.blank? || message.blank?
275
+ error = body.xpath('//faultcode').text
276
+ message = body.xpath('//faultstring').text
277
+ end
278
+
279
+ if error.present?
280
+ if error == "INVALID_SESSION"
281
+ raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{error}::#{message}")
282
+ end
283
+ if error == "REQUEST_EXCEEDED_LIMIT"
284
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{error}::#{message}")
285
+ end
286
+ if error == "LOCK_COMPETITION"
287
+ raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{error}::#{message}")
288
+ end
289
+ if error.present?
290
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{error}::#{message}")
291
+ end
292
+ end
265
293
 
266
- when :JSON
267
- #Zuora Regular REST API Unauthorized
268
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{body["reasons"][0]["message"]}") if body.class != Array && (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 90000011 && response.code == 401)
269
- #Zuora AQuA Unauthorized
270
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("Unauthorized") if response.code == 401
271
-
272
- #Zuora REST API Limit Errors
273
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{body["reasons"][0]["message"]}") if body.class != Array && (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 50000070 && response.code == 429)
274
-
275
- raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{body["reasons"][0]["message"]}") if (!body["success"] && !body["reasons"].blank? && body["reasons"] == Array && body["reasons"][0]["code"] == 53200050)
294
+ when :JSON
295
+ if body.class == Hash && (!body["success"] || !body["Success"] || response.code != 200)
296
+ messages_array = (body["reasons"] || []).map {|error| error['message']}.compact
297
+ codes_array = (body["reasons"] || []).map {|error| error['code']}.compact
298
+
299
+ #Authentication failed
300
+ if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(11) || response.code == 401
301
+ raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("#{messages_array.join(', ')}")
302
+ end
276
303
 
277
- #Zuora REST Query Errors
278
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}") if body.class != Array && !body["faultcode"].blank?
279
- #Zuora REST actions error
280
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["Errors"][0]["Code"]}::#{body["Errors"][0]["Message"]}") if body.class != Array && !body["Success"] && body["Errors"]
281
- #Zuora All Other API Errors
282
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}") if response.code != 200
304
+ #Request exceeded limit
305
+ if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
306
+ raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}")
307
+ end
308
+
309
+ #Locking contention
310
+ if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
311
+ raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}")
312
+ end
313
+
314
+ #Zuora REST Query Errors
315
+ if body["faultcode"].present?
316
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body["faultcode"]}::#{body["faultstring"]}")
317
+ end
318
+ end
283
319
 
320
+ if body.class == Array && (!body[0]["Success"])
321
+ #Zuora REST Actions error (Create, Update, Delete)
322
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{body[0]["Errors"][0]["Code"]}::#{body[0]["Errors"][0]["Message"]}")
323
+ end
324
+
325
+ #All other errors
326
+ if response.code != 200
327
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new("#{response.message}")
328
+ end
284
329
  end
285
330
  end
286
331
 
@@ -365,9 +410,14 @@ module ZuoraAPI
365
410
  headers["entityId"] = self.entity_id if !self.entity_id.blank?
366
411
  raise "Method not supported, supported methods include: :get, :post, :put, :delete, :patch, :head, :options" if ![:get, :post, :put, :delete, :patch, :head, :options].include?(method)
367
412
  response = HTTParty::Request.new("Net::HTTP::#{method.to_s.capitalize}".constantize, url, body: body, headers: {'Content-Type' => "application/json; charset=utf-8"}.merge(z_session ? {"Authorization" => "ZSession #{self.get_session}"} : {}).merge(headers), timeout: 120).perform
368
- Rails.logger.debug('Connect') { response.code} if debug
369
- output_json = JSON.parse(response.body)
370
- Rails.logger.debug('Connect') {"Response JSON: #{output_json}"} if debug
413
+
414
+ Rails.logger.debug('Connect') {"Response Code: #{response.code}" } if debug
415
+ begin
416
+ output_json = JSON.parse(response.body)
417
+ rescue JSON::ParserError => ex
418
+ output_json = {}
419
+ end
420
+ Rails.logger.debug('Connect') {"Response JSON: #{output_json}"} if debug && output_json.present?
371
421
 
372
422
  raise_errors(type: :JSON, body: output_json, response: response)
373
423
 
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.3.9993"
2
+ VERSION = "1.3.9994"
3
3
  end
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.12"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency("webmock")
25
+ spec.add_development_dependency("simplecov")
24
26
  spec.add_dependency("nokogiri", "~>1.6.8")
25
27
  spec.add_dependency("httparty")
26
28
  spec.add_dependency("rubyzip")
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.3.9993
4
+ version: 1.3.9994
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: 2017-09-19 00:00:00.000000000 Z
11
+ date: 2017-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: nokogiri
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -121,7 +149,6 @@ executables: []
121
149
  extensions: []
122
150
  extra_rdoc_files: []
123
151
  files:
124
- - ".DS_Store"
125
152
  - ".gitignore"
126
153
  - ".gitlab-ci.yml"
127
154
  - ".rspec"
data/.DS_Store DELETED
Binary file