zuora_api 0.2.4.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1233e68ad5b7dcee9bebc1f42de004fa937b54e
4
+ data.tar.gz: 7fd1dbbe7b2635c9a9f53dd69743da9e0e9d5b91
5
+ SHA512:
6
+ metadata.gz: 8e04f8ef2c13f150fa1844f3f909bc1a4ec22a686aa5006d6c45e3b2836288d2df77c40ce71abce7577ac7d56105c09eb545290708583e39a9a400e98f4cb163
7
+ data.tar.gz: bc0a5da7735d14dac5ee880e7c474bd729b7a639de9095f4334ebf81b34d0d8e49559339405a74eb62650e7a51b5b64372143346a2370c36ab9ea61572ed6c1f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zuora.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Zuora
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zuora`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'zuora'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zuora
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zuora.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "zuora"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/zuora.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ require "zuora/login"
4
+ module Zuora
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,441 @@
1
+ require "HTTParty"
2
+ require "Nokogiri"
3
+ module Zuora
4
+ class Login
5
+ ENVIRONMENTS = [SANDBOX = 'Sandbox', PRODUCTION = 'Production', PREFORMANCE = 'Preformance', SERVICES = 'Services', UNKNOWN = 'Unknown' ]
6
+
7
+ attr_accessor :username, :password, :url, :wsdl_number, :status, :current_session, :environment, :status, :errors, :current_error, :user_info, :tenant_id, :tenant_name
8
+
9
+ def initialize(username,password,url)
10
+ @username = username
11
+ @password = password
12
+ @errors = Hash.new
13
+ @user_info = Hash.new
14
+ @url = url
15
+ self.new_session
16
+ self.update_environment
17
+ end
18
+
19
+ def self.environments
20
+ %w(Sandbox Production Services Performance)
21
+ end
22
+
23
+ def self.endpoints
24
+ return {"Sandbox" => "https://apisandbox.zuora.com/apps/services/a/",
25
+ "Production" => "https://www.zuora.com/apps/services/a/",
26
+ "Performance" => "https://pt1.zuora.com/apps/services/a/",
27
+ "Services" => "https://services347.zuora.com/apps/services/a/"}
28
+ end
29
+
30
+ def update_environment
31
+ if !self.url.blank?
32
+ env_path = self.url.split('https://').last.split('.zuora.com').first
33
+ if env_path == 'apisandbox' || self.url.include?('tls10.apisandbox.zuora.com')
34
+ self.environment = 'Sandbox'
35
+ elsif env_path == 'www' || env_path == 'api' || self.url.include?('tls10.zuora.com')
36
+ self.environment = 'Production'
37
+ elsif env_path.include?('service')
38
+ self.environment = 'Services'
39
+ elsif env_path.include?('pt')
40
+ self.environment = 'Performance'
41
+ else
42
+ self.environment = 'Unknown'
43
+ end
44
+ end
45
+ end
46
+
47
+ def rest_endpoint(url="")
48
+ if self.environment == 'Sandbox'
49
+ return "https://apisandbox-api.zuora.com/rest/v1/".concat(url)
50
+ elsif self.environment == 'Production'
51
+ return "https://api.zuora.com/rest/v1/".concat(url)
52
+ elsif self.environment == 'Services'
53
+ return self.url.split('/')[0..2].join('/').concat('/apps/v1/').concat(url)
54
+ elsif self.environment == 'Performance'
55
+ return self.url.split('/')[0..2].join('/').concat('/apps/v1/').concat(url)
56
+ else self.environment == 'Unknown'
57
+ return url
58
+ end
59
+ end
60
+
61
+ def fileURL
62
+ return self.url.split(".com").first.concat(".com/apps/api/file/")
63
+ end
64
+
65
+ def dateFormat
66
+ return self.wsdl_number > 68 ? '%Y-%m-%d' : '%Y-%m-%dT%H:%M:%S'
67
+ end
68
+
69
+ def new_session
70
+ request = Nokogiri::XML::Builder.new do |xml|
71
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' =>"http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:api' => "http://api.zuora.com/" ) do
72
+ if (self.password.blank? && !self.current_session.blank?)
73
+ Rails.logger.debug("Method [Session]")
74
+ xml['SOAP-ENV'].Header do
75
+ xml['api'].SessionHeader do
76
+ xml['api'].session self.current_session
77
+ end
78
+ end
79
+ xml['SOAP-ENV'].Body do
80
+ xml['api'].getUserInfo
81
+ end
82
+ else
83
+ xml['SOAP-ENV'].Header
84
+ xml['SOAP-ENV'].Body do
85
+ xml['api'].login do
86
+ xml['api'].username self.username
87
+ xml['api'].password self.password
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ @response_query = HTTParty.post(self.url,:body => request.to_xml, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => 10)
94
+ @output_xml = Nokogiri::XML(@response_query.body)
95
+ if !@response_query.success?
96
+ self.current_session = nil
97
+ if @output_xml.namespaces.size > 0 && @output_xml.xpath('//soapenv:Fault').size > 0
98
+ self.current_error = @output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text
99
+ if self.current_error.include?('deactivated')
100
+ self.status = 'Deactivated'
101
+ self.current_error = 'Deactivated user login, please check with Zuora tenant administrator'
102
+ self.errors[:username] = self.current_error
103
+ elsif self.current_error.include?('inactive')
104
+ self.status = 'Inactive'
105
+ self.current_error = 'Inactive user login, please check with Zuora tenant administrator'
106
+ self.errors[:username] = self.current_error
107
+ elsif self.current_error.include?("invalid username or password") || self.current_error.include?("Invalid login. User name and password do not match.")
108
+ self.status = 'Invalid Login'
109
+ self.current_error = 'Invalid login, please check username and password or URL endpoint'
110
+ self.errors[:username] = self.current_error
111
+ self.errors[:password] = self.current_error
112
+ elsif self.current_error.include?('unsupported version')
113
+ self.status = 'Unsupported API Version'
114
+ self.current_error = 'Unsupported API version, please verify URL endpoint'
115
+ self.errors[:url] = self.current_error
116
+ elsif self.current_error.include?('invalid api version')
117
+ self.status = 'Invalid API Version'
118
+ self.current_error = 'Invalid API version, please verify URL endpoint'
119
+ self.errors[:url] = self.current_error
120
+ elsif self.current_error.include?('invalid session')
121
+ self.status = 'Invalid Session'
122
+ self.current_error = 'Session invalid, please update session and verify URL endpoint'
123
+ self.errors[:session] = self.current_error
124
+ elsif self.current_error.include?('Your IP address')
125
+ self.status = 'Restricted IP'
126
+ self.current_error = 'IP restricted, contact Zuora tenant administrator and remove IP restriction'
127
+ self.errors[:base] = self.current_error
128
+ elsif self.current_error.include?('This account has been locked')
129
+ self.status = 'Locked'
130
+ self.current_error = 'Locked user login, please wait or navigate to Zuora to unlock user'
131
+ self.errors[:username] = self.current_error
132
+ else
133
+ self.status = 'Unknown'
134
+ self.current_error = @output_xml.xpath('//faultstring').text if self.current_error.blank?
135
+ self.errors[:base] = self.current_error
136
+ end
137
+ else
138
+ if @response_query.timed_out?
139
+ self.current_error = "Request timed out. Try again"
140
+ self.status = 'Timeout'
141
+ else
142
+ self.current_error = " Code = #{@response_query.code} Message = #{@response_query.return_code}"
143
+ self.status = 'No Service'
144
+ end
145
+ end
146
+ else
147
+ self.current_session = (self.password.blank? && !self.current_session.blank?) ? self.current_session : @output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text
148
+ self.username = @output_xml.xpath('//ns1:Username', 'ns1' =>'http://api.zuora.com/').text if self.username.blank?
149
+ self.current_error = nil
150
+ self.status = 'Active'
151
+ end
152
+ return self.status
153
+ end
154
+
155
+ def get_session
156
+ Rails.logger.debug("Create new session") if self.current_session.blank?
157
+ self.new_session if self.current_session.blank?
158
+ raise self.current_error if self.status != 'Active'
159
+ return self.current_session
160
+ end
161
+
162
+ def soap_call(ns1: 'ns1', ns2: 'ns2', batch_size: nil, single_transaction: false, **keyword_args)
163
+ tries ||= 2
164
+ xml = Nokogiri::XML::Builder.new do |xml|
165
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/",
166
+ "xmlns:#{ns2}" => "http://object.api.zuora.com/",
167
+ 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
168
+ 'xmlns:api' => "http://api.zuora.com/",
169
+ "xmlns:#{ns1}" => "http://api.zuora.com/") do
170
+ xml['SOAP-ENV'].Header do
171
+ xml["#{ns1}"].SessionHeader do
172
+ xml["#{ns1}"].session self.get_session
173
+ end
174
+ if single_transaction
175
+ xml["#{ns1}"].CallOptions do
176
+ xml.useSingleTransaction single_transaction
177
+ end
178
+ end
179
+ if batch_size
180
+ xml["#{ns1}"].QueryOptions do
181
+ xml.batchSize batch_size
182
+ end
183
+ end
184
+ end
185
+ xml['SOAP-ENV'].Body do
186
+ yield xml, keyword_args
187
+ end
188
+ end
189
+ end
190
+
191
+ input_xml = Nokogiri::XML(xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip)
192
+ input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove
193
+ Rails.logger.debug('Connect') {"Request SOAP XML: #{input_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip}"}
194
+ response = HTTParty.post(self.url,:body => xml.doc.to_xml, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, :timeout => 10)
195
+ output_xml = Nokogiri::XML(response.body)
196
+ Rails.logger.debug('Connect') {"Response SOAP XML: #{output_xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip}"}
197
+
198
+ raise "#{output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text}::#{output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text}" if !output_xml.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text.blank?
199
+ raise "#{output_xml.xpath('//faultcode').text}::#{output_xml.xpath('//faultstring').text}" if !output_xml.xpath('//faultcode').text.blank?
200
+ rescue => ex
201
+ if !(tries -= 1).zero?
202
+ case ex.to_s.split("::")[0]
203
+ when "INVALID_SESSION"
204
+ Rails.logger.debug {"Session Invalid"}
205
+ self.new_session
206
+ retry
207
+ else
208
+ raise ex
209
+ end
210
+ else
211
+ raise ex
212
+ end
213
+ else
214
+ return [output_xml, input_xml]
215
+ end
216
+
217
+ def describe_call(object = nil)
218
+ url = object ? "https://apisandbox.zuora.com/apps/api/describe/#{object}" : "https://apisandbox.zuora.com/apps/api/describe/"
219
+ response = HTTParty.get(url, :headers => {'Content-Type' => "text/xml; charset=utf-8"}, basic_auth: {:username => self.username, :password => self.password})
220
+ output_xml = Nokogiri::XML(response.body)
221
+ des_hash = Hash.new
222
+ if object == nil
223
+ output_xml.xpath("//object").each do |object|
224
+ temp = {:label => object.xpath(".//label").text, :url => object.attributes["href"].value }
225
+ des_hash[object.xpath(".//name").text] = temp
226
+ end
227
+ else
228
+ output_xml.xpath("//field").each do |object|
229
+ temp = {:label => object.xpath(".//label").text,:selectable => object.xpath(".//selectable").text,
230
+ :createable => object.xpath(".//label").text == "ID" ? "false" : object.xpath(".//createable").text,
231
+ :filterable => object.xpath(".//filterable").text,
232
+ :updateable => object.xpath(".//label").text == "ID" ? "false" : object.xpath(".//updateable").text,
233
+ :custom => object.xpath(".//custom").text,:maxlength => object.xpath(".//maxlength").text,
234
+ :required => object.xpath(".//required").text,
235
+ :type => object.xpath(".//type").text,
236
+ :context => object.xpath(".//context").collect{ |x| x.text } }
237
+ temp[:options] = object.xpath(".//option").collect{ |x| x.text } if object.xpath(".//option").size > 0
238
+ des_hash[object.xpath(".//name").text.to_sym] = temp
239
+ end
240
+ des_hash[:related_objects] = output_xml.xpath(".//related-objects").xpath(".//object").map{ |x| [x.xpath(".//name").text.to_sym, [ [:url, x.attributes["href"].value], [:label, x.xpath(".//name").text ] ].to_h] }.to_h
241
+ end
242
+ return des_hash
243
+ end
244
+
245
+ def rest_call(method: :get, body: {}, url: rest_endpoint("catalog/products?pageSize=4") , **keyword_args)
246
+ tries ||= 2
247
+ response = HTTParty.get(self.url, body: body, headers: {'Content-Type' => "application/json; charset=utf-8", "Authorization" => "ZSession #{self.get_session}"}) if method.to_s.downcase == "get"
248
+ response = HTTParty.post(self.url, body: body, headers: {'Content-Type' => "application/json; charset=utf-8", "Authorization" => "ZSession #{self.get_session}"}) if method.to_s.downcase == "post"
249
+ raise "#{response.code}::#{response.return_code}" if !response.success?
250
+ output_json = JSON.parse(response.body)
251
+ Rails.logger.debug('Connect') {"Response JSON: #{output_json}"}
252
+ raise "#{output_json["reasons"][0]["code"]}::#{output_json["reasons"][0]["message"]}" if !output_json["success"].to_bool
253
+ rescue => ex
254
+ if !(tries -= 1).zero?
255
+ case ex.to_s.split("::")[0]
256
+ when "90000011"
257
+ Rails.logger.debug {"Session Invalid"}
258
+ self.new_session
259
+ retry
260
+ else
261
+ raise ex
262
+ end
263
+ else
264
+ raise ex
265
+ end
266
+ else
267
+ return output_json
268
+ end
269
+
270
+ def update_create_tenant
271
+ Rails.logger.debug("Update and/or Create Tenant")
272
+ output_xml, input_xml = soap_call() do |xml|
273
+ xml['api'].getUserInfo
274
+ end
275
+ user_info = output_xml.xpath('//ns1:getUserInfoResponse', 'ns1' =>'http://api.zuora.com/')
276
+ output_hash = Hash[user_info.children.map {|x| [x.name.to_sym, x.text] }]
277
+ self.user_info = output_hash
278
+ self.user_info['entities'] = self.rest_call(:url => self.rest_endpoint("user-access/user-profile/#{self.user_info['UserId']}/accessible-entities"))['entities']
279
+ self.tenant_name = output_hash[:TenantName]
280
+ self.tenant_id = output_hash[:TenantId]
281
+ return self
282
+ end
283
+
284
+ def getDataSourceExport(query)
285
+ Rails.logger.info('Export') {"Build export"}
286
+ Rails.logger.info('Export query') {"#{query}"}
287
+ request = Nokogiri::XML::Builder.new do |xml|
288
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
289
+ xml['SOAP-ENV'].Header do
290
+ xml['ns1'].SessionHeader do
291
+ xml['ns1'].session self.current_session
292
+ end
293
+ end
294
+ xml['SOAP-ENV'].Body do
295
+ xml['ns1'].create do
296
+ xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
297
+ xml['ns2'].Format 'csv'
298
+ xml['ns2'].Zip 'true'
299
+ xml['ns2'].Name 'googman'
300
+ xml['ns2'].Query query
301
+ end
302
+ end
303
+ end
304
+ end
305
+ end
306
+ response_query = HTTParty.post(self.url, body: request.to_xml, headers: {'Content-Type' => "application/json; charset=utf-8"})
307
+ output_xml = Nokogiri::XML(response_query.body)
308
+
309
+ return 'Export Creation Unsuccessful : ' + output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
310
+ id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
311
+
312
+ confirmRequest = Nokogiri::XML::Builder.new do |xml|
313
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
314
+ xml['SOAP-ENV'].Header do
315
+ xml['ns1'].SessionHeader do
316
+ xml['ns1'].session self.current_session
317
+ end
318
+ end
319
+ xml['SOAP-ENV'].Body do
320
+ xml['ns1'].query do
321
+ xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where id='" + id + "'"
322
+ end
323
+ end
324
+ end
325
+ end
326
+ result = 'Waiting'
327
+ while result != "Completed"
328
+ sleep 3
329
+ response_query = HTTParty.post(self.url, body: confirmRequest.to_xml, headers: {'Content-Type' => "application/json; charset=utf-8"})
330
+ output_xml = Nokogiri::XML(response_query.body)
331
+ result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
332
+ return 'Export Creation Unsuccessful : ' + output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text if result == "Failed"
333
+ end
334
+ file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
335
+ response_query = HTTParty.get(self.fileURL + file_id, body: request.to_xml, headers: {"Authorization" => "ZSession " + self.current_session}, query: {"file-id" => file_id})
336
+ Rails.logger.info('Export') {'=====> Export finished'}
337
+ list = Array.new
338
+ headers = Array.new
339
+ i=0
340
+ Zip::Archive.open_buffer(response_query.body) do |ar|
341
+ ar.fopen(0) do |zf|
342
+ open(zf.name, 'wb') do |f|
343
+ CSV.parse(zf.read) do |row|
344
+ j=0
345
+ values = Hash.new
346
+ storename = ''
347
+ row.each do |col|
348
+ if i == 0
349
+ headers[j] = col
350
+ else
351
+ #Is this needed - can just store all dates as string
352
+ if headers[j].include? 'CreatedDate'
353
+ values[headers[j]] = Date.strptime(row[j], self.dateFormat)
354
+ elsif row[j].nil?
355
+ values[headers[j]] = ''
356
+ else
357
+ values[headers[j]] = row[j]
358
+ end
359
+ end
360
+ j += 1
361
+ end
362
+ if i!=0
363
+ list[i-1] = values
364
+ end
365
+ i += 1
366
+ end
367
+ end
368
+ end
369
+ end
370
+ return list
371
+ end
372
+
373
+ def query(query)
374
+ Rails.logger.info('query') {"Querying Zuora for #{query}"}
375
+ confirmRequest = Nokogiri::XML::Builder.new do |xml|
376
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
377
+ xml['SOAP-ENV'].Header do
378
+ xml['ns1'].SessionHeader do
379
+ xml['ns1'].session self.current_session
380
+ end
381
+ end
382
+ xml['SOAP-ENV'].Body do
383
+ xml['ns1'].query do
384
+ xml['ns1'].queryString query
385
+ end
386
+ end
387
+ end
388
+ end
389
+ response_query = HTTParty.post(self.url, body: confirmRequest.to_xml, :headers => {'Content-Type' => "text/xml; charset=utf-8"})
390
+ output_xml = Nokogiri::XML(response_query.body)
391
+ Rails.logger.info('query') {"#{output_xml}"}
392
+ return output_xml
393
+ end
394
+
395
+ def createJournalRun(call)
396
+ url = rest_endpoint("/journal-runs")
397
+ uri = URI(url)
398
+ req = Net::HTTP::Post.new(uri,initheader = {'Content-Type' =>'application/json'})
399
+ req.basic_auth self.username, self.password
400
+ req.body = call
401
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
402
+ http.request req
403
+ end
404
+ Rails.logger.info('Journal Run') {"Response #{response.code} #{response.message}:
405
+ #{response.body}"}
406
+
407
+ result = JSON.parse(response.body)
408
+ if result["success"]
409
+ jrNumber = result["journalRunNumber"]
410
+ return jrNumber
411
+ else
412
+ message = result["reasons"][0]["message"]
413
+ Rails.logger.info('Journal Run') {"Journal Run failed with message #{message}"}
414
+ return false
415
+ end
416
+ end
417
+
418
+ def checkJRStatus(jrNumber)
419
+ Rails.logger.info('Journal Run') {"Check for completion"}
420
+ url = rest_endpoint("/journal-runs/#{jrNumber}")
421
+ uri = URI(url)
422
+ req = Net::HTTP::Get.new(uri,initheader = {'Content-Type' =>'application/json'})
423
+ req.basic_auth self.username, self.password
424
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
425
+ http.request req
426
+ end
427
+ result = JSON.parse(response.body)
428
+
429
+ if result["success"]
430
+ if !(result["status"].eql? "Completed")
431
+ sleep(20.seconds)
432
+ end
433
+ return result["status"]
434
+ else
435
+ message = result["reasons"][0]["message"]
436
+ Rails.logger.info('Journal Run') {"Checking status of journal run failed with message #{message}"}
437
+ end
438
+ return "failure"
439
+ end
440
+ end
441
+ end
@@ -0,0 +1,3 @@
1
+ module Zuora
2
+ VERSION = "0.2.4.5"
3
+ end
data/zuora.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zuora/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zuora_api"
8
+ spec.version = Zuora::VERSION
9
+ spec.authors = ["Zuora Strategic Solutions Group"]
10
+ spec.email = ["connect@zuora.com"]
11
+
12
+ spec.summary = %q{Gem that provides easy integration to Zuora}
13
+ spec.description = %q{Gem that provides easy integration to Zuora}
14
+ spec.homepage = "https://connect.zuora.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_dependency("nokogiri", "~>1.6.8")
25
+ spec.add_dependency("httparty")
26
+ spec.add_dependency("railties", ">= 4.1.0", "< 5.1")
27
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zuora_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4.5
5
+ platform: ruby
6
+ authors:
7
+ - Zuora Strategic Solutions Group
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.8
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.8
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: railties
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 4.1.0
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '5.1'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 4.1.0
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '5.1'
103
+ description: Gem that provides easy integration to Zuora
104
+ email:
105
+ - connect@zuora.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/setup
119
+ - lib/zuora.rb
120
+ - lib/zuora/login.rb
121
+ - lib/zuora/version.rb
122
+ - zuora.gemspec
123
+ homepage: https://connect.zuora.com
124
+ licenses: []
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Gem that provides easy integration to Zuora
146
+ test_files: []