active_zuora 1.5.2 → 2.0.0

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.
Files changed (78) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +57 -0
  3. data/README.md +155 -0
  4. data/Rakefile +6 -22
  5. data/TODO.md +2 -0
  6. data/active_zuora.gemspec +25 -68
  7. data/lib/active_zuora.rb +37 -6
  8. data/lib/active_zuora/amend.rb +43 -0
  9. data/lib/active_zuora/base.rb +73 -0
  10. data/lib/active_zuora/belongs_to_associations.rb +56 -0
  11. data/lib/active_zuora/connection.rb +41 -0
  12. data/lib/active_zuora/fields.rb +122 -0
  13. data/lib/active_zuora/fields/array_field_decorator.rb +28 -0
  14. data/lib/active_zuora/fields/boolean_field.rb +12 -0
  15. data/lib/active_zuora/fields/date_time_field.rb +19 -0
  16. data/lib/active_zuora/fields/decimal_field.rb +12 -0
  17. data/lib/active_zuora/fields/field.rb +76 -0
  18. data/lib/active_zuora/fields/integer_field.rb +11 -0
  19. data/lib/active_zuora/fields/object_field.rb +31 -0
  20. data/lib/active_zuora/fields/string_field.rb +11 -0
  21. data/lib/active_zuora/generate.rb +43 -0
  22. data/lib/active_zuora/generator.rb +220 -0
  23. data/lib/active_zuora/has_many_associations.rb +37 -0
  24. data/lib/active_zuora/has_many_proxy.rb +50 -0
  25. data/lib/active_zuora/persistence.rb +176 -0
  26. data/lib/active_zuora/relation.rb +253 -0
  27. data/lib/active_zuora/scoping.rb +50 -0
  28. data/lib/active_zuora/subscribe.rb +42 -0
  29. data/lib/active_zuora/version.rb +3 -0
  30. data/lib/active_zuora/z_object.rb +21 -0
  31. data/spec/belongs_to_associations_spec.rb +35 -0
  32. data/spec/has_many_integration_spec.rb +53 -0
  33. data/spec/spec_helper.rb +21 -0
  34. data/spec/subscribe_integration_spec.rb +218 -0
  35. data/spec/zobject_integration_spec.rb +104 -0
  36. data/wsdl/zuora.wsdl +1548 -0
  37. metadata +128 -72
  38. checksums.yaml +0 -7
  39. data/LICENSE +0 -202
  40. data/README.rdoc +0 -36
  41. data/VERSION +0 -1
  42. data/custom_fields.yml +0 -17
  43. data/lib/active_zuora/account.rb +0 -31
  44. data/lib/active_zuora/amendment.rb +0 -7
  45. data/lib/active_zuora/bill_run.rb +0 -4
  46. data/lib/active_zuora/contact.rb +0 -7
  47. data/lib/active_zuora/invoice.rb +0 -46
  48. data/lib/active_zuora/invoice_item.rb +0 -26
  49. data/lib/active_zuora/invoice_item_adjustment.rb +0 -4
  50. data/lib/active_zuora/invoice_payment.rb +0 -11
  51. data/lib/active_zuora/payment.rb +0 -18
  52. data/lib/active_zuora/payment_method.rb +0 -10
  53. data/lib/active_zuora/product.rb +0 -4
  54. data/lib/active_zuora/product_rate_plan.rb +0 -9
  55. data/lib/active_zuora/product_rate_plan_charge.rb +0 -11
  56. data/lib/active_zuora/product_rate_plan_charge_tier.rb +0 -7
  57. data/lib/active_zuora/product_rate_plan_charge_tier_data.rb +0 -4
  58. data/lib/active_zuora/rate_plan.rb +0 -16
  59. data/lib/active_zuora/rate_plan_charge.rb +0 -71
  60. data/lib/active_zuora/rate_plan_charge_data.rb +0 -4
  61. data/lib/active_zuora/rate_plan_charge_tier.rb +0 -4
  62. data/lib/active_zuora/rate_plan_data.rb +0 -4
  63. data/lib/active_zuora/refund.rb +0 -4
  64. data/lib/active_zuora/subscribe_options.rb +0 -4
  65. data/lib/active_zuora/subscribe_request.rb +0 -13
  66. data/lib/active_zuora/subscribe_with_existing_account_request.rb +0 -4
  67. data/lib/active_zuora/subscription.rb +0 -17
  68. data/lib/active_zuora/subscription_data.rb +0 -4
  69. data/lib/active_zuora/usage.rb +0 -4
  70. data/lib/active_zuora/zobject.rb +0 -154
  71. data/lib/soap/property +0 -1
  72. data/lib/zuora/ZUORA.rb +0 -1560
  73. data/lib/zuora/ZUORADriver.rb +0 -145
  74. data/lib/zuora/ZUORAMappingRegistry.rb +0 -1709
  75. data/lib/zuora/ZuoraServiceClient.rb +0 -124
  76. data/lib/zuora/api.rb +0 -18
  77. data/lib/zuora_client.rb +0 -191
  78. data/lib/zuora_interface.rb +0 -215
@@ -1,124 +0,0 @@
1
- module ZUORA
2
-
3
- endpoint_url = ARGV.shift
4
- obj = Soap.new(endpoint_url)
5
-
6
- # run ruby with -d to see SOAP wiredumps.
7
- obj.wiredump_dev = STDERR if $DEBUG
8
-
9
- # SYNOPSIS
10
- # login(parameters)
11
- #
12
- # ARGS
13
- # parameters Login - {http://api.zuora.com/}login
14
- #
15
- # RETURNS
16
- # parameters LoginResponse - {http://api.zuora.com/}loginResponse
17
- #
18
- # RAISES
19
- # fault LoginFault - {http://fault.api.zuora.com/}LoginFault
20
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
21
- #
22
- parameters = nil
23
- puts obj.login(parameters)
24
-
25
- # SYNOPSIS
26
- # subscribe(parameters)
27
- #
28
- # ARGS
29
- # parameters Subscribe - {http://api.zuora.com/}subscribe
30
- #
31
- # RETURNS
32
- # parameters SubscribeResponse - {http://api.zuora.com/}subscribeResponse
33
- #
34
- # RAISES
35
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
36
- #
37
- parameters = nil
38
- puts obj.subscribe(parameters)
39
-
40
- # SYNOPSIS
41
- # subscribeWithExistingAccount(parameters)
42
- #
43
- # ARGS
44
- # parameters SubscribeWithExistingAccount - {http://api.zuora.com/}subscribeWithExistingAccount
45
- #
46
- # RETURNS
47
- # parameters SubscribeResponse - {http://api.zuora.com/}subscribeResponse
48
- #
49
- # RAISES
50
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
51
- #
52
- parameters = nil
53
- puts obj.subscribeWithExistingAccount(parameters)
54
-
55
- # SYNOPSIS
56
- # create(parameters)
57
- #
58
- # ARGS
59
- # parameters Create - {http://api.zuora.com/}create
60
- #
61
- # RETURNS
62
- # parameters CreateResponse - {http://api.zuora.com/}createResponse
63
- #
64
- # RAISES
65
- # fault InvalidTypeFault - {http://fault.api.zuora.com/}InvalidTypeFault
66
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
67
- #
68
- parameters = nil
69
- puts obj.create(parameters)
70
-
71
- # SYNOPSIS
72
- # update(parameters)
73
- #
74
- # ARGS
75
- # parameters Update - {http://api.zuora.com/}update
76
- #
77
- # RETURNS
78
- # parameters UpdateResponse - {http://api.zuora.com/}updateResponse
79
- #
80
- # RAISES
81
- # fault InvalidTypeFault - {http://fault.api.zuora.com/}InvalidTypeFault
82
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
83
- #
84
- parameters = nil
85
- puts obj.update(parameters)
86
-
87
- # SYNOPSIS
88
- # delete(parameters)
89
- #
90
- # ARGS
91
- # parameters Delete - {http://api.zuora.com/}delete
92
- #
93
- # RETURNS
94
- # parameters DeleteResponse - {http://api.zuora.com/}deleteResponse
95
- #
96
- # RAISES
97
- # fault InvalidTypeFault - {http://fault.api.zuora.com/}InvalidTypeFault
98
- # fault InvalidValueFault - {http://fault.api.zuora.com/}InvalidValueFault
99
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
100
- #
101
- parameters = nil
102
- puts obj.delete(parameters)
103
-
104
- # SYNOPSIS
105
- # query(parameters)
106
- #
107
- # ARGS
108
- # parameters Query - {http://api.zuora.com/}query
109
- #
110
- # RETURNS
111
- # parameters QueryResponse - {http://api.zuora.com/}queryResponse
112
- #
113
- # RAISES
114
- # fault MalformedQueryFault - {http://fault.api.zuora.com/}MalformedQueryFault
115
- # fault InvalidQueryLocatorFault - {http://fault.api.zuora.com/}InvalidQueryLocatorFault
116
- # fault UnexpectedErrorFault - {http://fault.api.zuora.com/}UnexpectedErrorFault
117
- #
118
- parameters = nil
119
- puts obj.query(parameters)
120
-
121
-
122
-
123
-
124
- end
@@ -1,18 +0,0 @@
1
- require 'singleton'
2
-
3
- require 'zuora/ZUORA'
4
- require 'zuora/ZUORADriver'
5
- require 'zuora/ZUORAMappingRegistry'
6
-
7
- module Zuora
8
- module Billing
9
- class Api
10
- include Singleton
11
- def initialize
12
- @driver = ZUORA::Soap.new
13
- end
14
-
15
- attr_reader :driver
16
- end
17
- end
18
- end
@@ -1,191 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Copyright 2010 Ning
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
-
18
- # if you get this error:
19
- #
20
- # 'uninitialized constant SOAP::Mapping::EncodedRegistry (NameError)'
21
- #
22
- # you need to follow the bellow steps to work around it
23
- #
24
- # gem uninstall soap4r
25
- # curl -O http://dev.ctor.org/download/soap4r-1.5.8.tar.gz
26
- # tar zxvf soap4r-1.5.8.tar.gz
27
- # cd soap4r-1.5.8
28
- # sudo ruby install.rb
29
-
30
- require 'zuora_interface'
31
- require 'zuora/api'
32
- require 'yaml'
33
-
34
- class SOAP::Header::HandlerSet
35
- def reset
36
- @store = XSD::NamedElements.new
37
- end
38
-
39
- def set(header)
40
- reset
41
- add header
42
- end
43
- end
44
-
45
- module Zuora
46
- class Client
47
- API_VERSION = "37.0"
48
- PROD_URL = "https://www.zuora.com/apps/services/a/#{API_VERSION}"
49
- SANDBOX_URL = "https://apisandbox.zuora.com/apps/services/a/#{API_VERSION}"
50
-
51
- def self.app_url
52
- SANDBOX_URL
53
- end
54
-
55
- def self.config
56
- return @config_hash if @config_hash
57
- @config_hash = Zuora::CONFIG if defined?(Zuora::CONFIG)
58
- @config_hash ||= {}
59
- end
60
-
61
- def self.parse_custom_fields
62
- if self.custom_fields
63
- self.custom_fields.each do |zobject, field_names|
64
- fields = field_names.map { |e| "#{e.strip}__c" }
65
- type_class = Object.const_get('ZUORA').const_get(zobject)
66
- fields.each do |field|
67
- custom_field = field.gsub(/^\w/) { |i| i.downcase }
68
- type_class.send :attr_accessor, custom_field
69
- end
70
- end
71
- end
72
- custom_fields
73
- end
74
-
75
- def self.custom_fields
76
- @custom_fields = YAML.load_file(File.dirname(__FILE__) + '/../custom_fields.yml')
77
- end
78
-
79
- def self.valid_session?
80
- #session is valid if it has been running for less than 8 hours
81
- @session_start_time + 28800 > Time.now
82
- end
83
-
84
- def self.client(*args)
85
- return @client if @client && self.valid_session?
86
- @session_start_time = Time.now
87
- @client = new(*args)
88
- end
89
-
90
- def initialize(url=nil)
91
- $ZUORA_USER = self.class.config["username"]
92
- $ZUORA_PASSWORD = self.class.config["password"]
93
- $ZUORA_ENDPOINT = url || self.class.app_url
94
-
95
- @client = ZuoraInterface.new
96
-
97
- # add custom fields, if any
98
- custom_fields = self.class.parse_custom_fields
99
- @client.session_start(custom_fields)
100
- end
101
-
102
- def query(query_string)
103
- # This will keep calling queryMore until all the results are retreived.
104
-
105
- query_string =~ /select\s+(.+)\s+from/i
106
- fields = ($1.split /,\s+/).map do |f|
107
- f.gsub!(/\b\w/) { $&.downcase }
108
- end
109
-
110
- responses = []
111
- begin
112
- responses << @client.api_call(:query, query_string)
113
- until responses.last.result.done
114
- responses << @client.api_call(:query_more, responses.last.result.queryLocator)
115
- end
116
- rescue Exception => e
117
- $stderr.puts e.message
118
- end
119
- # Capture all the records into one single array.
120
- responses.map{ |response| response.result.size > 0 ? response.result.records : [] }.flatten
121
- end
122
-
123
- def subscribe(obj)
124
- begin
125
- @client.api_call(:subscribe, obj)
126
- rescue Exception => e
127
- puts e.message
128
- end
129
- end
130
-
131
- def create(obj)
132
- begin
133
- response = @client.api_call(:create,obj)
134
- save_results_to_hash(response)
135
- rescue Exception => e
136
- [errors: [{message: e.message, code: nil}], object: obj]
137
- end
138
- end
139
-
140
- def generate(obj)
141
- begin
142
- response = @client.api_call(:generate,obj)
143
- save_results_to_hash(response)
144
- rescue Exception => e
145
- [errors: [{message: e.message, code: nil}], object: obj]
146
- end
147
- end
148
-
149
- def update(obj)
150
- begin
151
- response = @client.api_call(:update, obj)
152
- save_results_to_hash(response)
153
- rescue Exception => e
154
- [errors: [{message: e.message, code: nil}], object: obj]
155
- end
156
- end
157
-
158
- def delete(type, ids)
159
- begin
160
- response = @client.api_call(:delete, type, ids)
161
- save_results_to_hash(response)
162
- rescue Exception => e
163
- [errors: [{message: e.message, code: nil}], object: obj]
164
- end
165
- end
166
-
167
- def amend(obj)
168
- @client.api_call(:amend, obj)
169
- end
170
-
171
- private
172
-
173
- def save_results_to_hash(save_results)
174
- result = []
175
- save_results.each do |record|
176
- row = {:success => record.success}
177
- if record.success
178
- row[:id] = record.id
179
- else
180
- row[:errors] = []
181
- record.errors.each do |error|
182
- row[:errors] << {:message => error.message, :code => error.code}
183
- end
184
- end
185
- result << row
186
- end
187
- result
188
- end
189
- end
190
-
191
- end
@@ -1,215 +0,0 @@
1
- require 'zuora/api'
2
-
3
- class ZuoraInterface
4
- begin
5
- require 'system_timer'
6
- SysTimer = SystemTimer
7
- rescue LoadError
8
- require 'timeout'
9
- SysTimer = Timeout
10
- end
11
-
12
- def make_account(accountName)
13
- acc = ZUORA::Account.new
14
- acc.allowInvoiceEdit = 0
15
- acc.name = accountName
16
- acc.currency = "USD"
17
- acc.autoPay = 0
18
- acc.status = "Draft"
19
- acc.paymentTerm = "Due Upon Receipt"
20
- acc.batch = "Batch1"
21
- acc.billCycleDay = "01"
22
- return acc
23
- end
24
-
25
- def make_contact(accountId)
26
- con = ZUORA::Contact.new
27
- con.accountId = accountId
28
- con.address1 = '4901 Morena Blvd';
29
- con.city = 'San Diego';
30
- con.country = 'United States';
31
- con.firstName = 'Robert';
32
- con.lastName = 'Smith';
33
- con.postalCode = '92117';
34
- con.state = 'Virginia';
35
- con.workEmail = 'robert@smith.com';
36
- return con
37
- end
38
-
39
- def make_payment_method(accountId)
40
- pmt = ZUORA::PaymentMethod.new
41
- pmt.accountId = accountId
42
- pmt.creditCardAddress1 = '52 Vexford Lane';
43
- pmt.creditCardCity = 'Anaheim';
44
- pmt.creditCardCountry = 'United States';
45
- pmt.creditCardExpirationMonth = '12';
46
- pmt.creditCardExpirationYear = '2010';
47
- pmt.creditCardHolderName = 'Firstly Lastly';
48
- pmt.creditCardNumber = '4111111111111111';
49
- pmt.creditCardPostalCode = '22042';
50
- pmt.creditCardState = 'California';
51
- pmt.creditCardType = 'Visa';
52
- pmt.type = 'CreditCard';
53
- return pmt
54
- end
55
-
56
- def create_active_account(name)
57
-
58
- val = false
59
- session_start
60
- account = make_account(name)
61
- result = create([account])
62
- # puts result.first.inspect
63
-
64
- if result.first.success
65
-
66
- accountId = result.first.id
67
- payment = make_payment_method(accountId)
68
- result = create([payment])
69
-
70
- if result.first.success
71
-
72
- paymentId = result.first.id
73
- con = make_contact(accountId)
74
- result = create([con])
75
-
76
- if result.first.success
77
- conId = result.first.id
78
-
79
- account.id = accountId
80
- account.status = 'Active'
81
- account.billToId = conId
82
- account.soldToId = conId
83
- result = update([account])
84
-
85
- if result.first.success
86
- val = account
87
- else
88
- add_errors(result)
89
- end
90
-
91
- else
92
- add_errors(result)
93
- end
94
- else
95
- add_errors(result)
96
- end
97
- else
98
- add_errors(result)
99
- end
100
- return val
101
- end
102
-
103
- def api_call(call, *args)
104
- SysTimer.timeout(120) { self.send(call, *args) }
105
- end
106
-
107
- def query(query_string)
108
- @z.query(ZUORA::Query.new(query_string))
109
- end
110
-
111
- def query_more(query_locator)
112
- @z.queryMore(ZUORA::QueryMore.new(query_locator))
113
- end
114
-
115
- def create(objs)
116
- return @z.create(objs)
117
- end
118
-
119
- def generate(objs)
120
- return @z.generate(objs)
121
- end
122
-
123
- def update(objs)
124
- return @z.update(objs)
125
- end
126
-
127
- def delete(type, ids)
128
- d = ZUORA::Delete.new
129
- d.type = type
130
- d.ids = ids
131
- return @z.delete(d)
132
- end
133
-
134
- def subscribe(sub)
135
- return @z.subscribe(sub)
136
- end
137
-
138
- def amend(amend)
139
- return @z.amend(amend)
140
- end
141
-
142
- def get_object(query)
143
- object = lookup(query)
144
- unless object.result.size == 0
145
- return object.result.records.first
146
- else
147
- return nil
148
- end
149
- end
150
-
151
- def get_object_array(query)
152
- object = lookup(query)
153
- unless object.result.size == 0
154
- return object.result.records
155
- else
156
- return []
157
- end
158
- end
159
-
160
- def get_driver
161
- @z ||= Zuora::Billing::Api.instance.driver
162
- end
163
-
164
- def driver
165
- get_driver
166
- end
167
-
168
- def login
169
- loginargs = ZUORA::Login.new
170
- loginargs.username = $ZUORA_USER
171
- loginargs.password = $ZUORA_PASSWORD
172
- @session = ZUORA::SessionHeader.new
173
- @session.session = @z.login(loginargs).result.session
174
- end
175
-
176
- def session_start(custom_fields={})
177
- get_driver
178
- @z.do_init(custom_fields)
179
- session_cleanup
180
- login
181
- @z.headerhandler.set @session
182
- @z.wiredump_dev = STDERR if $ZUORA_VERBOSE
183
- end
184
-
185
- def session_cleanup
186
- @z.headerhandler.delete(@session) if @session
187
- end
188
- end
189
-
190
- public
191
-
192
- def run_tests
193
-
194
- t = ZuoraInterface.new
195
- t.session_start
196
-
197
- # create active account
198
- e = t.create_active_account("name" + String(Time.now.to_f))
199
- puts "Created Account: " + e.id
200
-
201
- # query it
202
- r = t.query("SELECT Id, Name FROM Account WHERE Name = '#{e.name}' and status = 'Active'")
203
- e = r.result.records[0]
204
- puts "Queried Account: " + e.to_s
205
-
206
- # delete it
207
- r = t.delete("Account", [e.id])
208
- puts "Deleted Account? " + r[0].success.to_s
209
-
210
- t.session_cleanup
211
-
212
- end
213
-
214
- if __FILE__ == $0
215
- end