active_zuora 1.3.0 → 1.4.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.
- data/README.rdoc +22 -1
- data/Rakefile +0 -9
- data/VERSION +1 -1
- data/active_zuora.gemspec +43 -13
- data/lib/active_zuora.rb +5 -10
- data/lib/active_zuora/account.rb +27 -0
- data/lib/active_zuora/amendment.rb +7 -0
- data/lib/active_zuora/bill_run.rb +4 -0
- data/lib/active_zuora/contact.rb +7 -0
- data/lib/active_zuora/invoice.rb +46 -0
- data/lib/active_zuora/invoice_item.rb +26 -0
- data/lib/active_zuora/invoice_item_adjustment.rb +4 -0
- data/lib/active_zuora/invoice_payment.rb +11 -0
- data/lib/active_zuora/payment.rb +18 -0
- data/lib/active_zuora/payment_method.rb +10 -0
- data/lib/active_zuora/product.rb +4 -0
- data/lib/active_zuora/product_rate_plan.rb +9 -0
- data/lib/active_zuora/product_rate_plan_charge.rb +11 -0
- data/lib/active_zuora/product_rate_plan_charge_tier.rb +7 -0
- data/lib/active_zuora/product_rate_plan_charge_tier_data.rb +4 -0
- data/lib/active_zuora/rate_plan.rb +16 -0
- data/lib/active_zuora/rate_plan_charge.rb +44 -0
- data/lib/active_zuora/rate_plan_charge_data.rb +4 -0
- data/lib/active_zuora/rate_plan_charge_tier.rb +4 -0
- data/lib/{zuora → active_zuora}/rate_plan_data.rb +0 -0
- data/lib/active_zuora/refund.rb +4 -0
- data/lib/{zuora → active_zuora}/subscribe_options.rb +0 -0
- data/lib/active_zuora/subscribe_request.rb +13 -0
- data/lib/{zuora → active_zuora}/subscribe_with_existing_account_request.rb +0 -0
- data/lib/active_zuora/subscription.rb +17 -0
- data/lib/{zuora → active_zuora}/subscription_data.rb +0 -0
- data/lib/active_zuora/usage.rb +4 -0
- data/lib/active_zuora/zobject.rb +156 -0
- data/lib/zuora/ZUORA.rb +180 -27
- data/lib/zuora/ZUORADriver.rb +17 -0
- data/lib/zuora/ZUORAMappingRegistry.rb +236 -23
- data/lib/zuora_client.rb +28 -24
- data/lib/zuora_interface.rb +21 -5
- metadata +112 -17
- data/lib/zuora/account.rb +0 -4
- data/lib/zuora/contact.rb +0 -4
- data/lib/zuora/rate_plan.rb +0 -4
- data/lib/zuora/subscribe_request.rb +0 -4
- data/lib/zuora/subscription.rb +0 -4
- data/lib/zuora/zobject.rb +0 -52
data/lib/zuora_client.rb
CHANGED
@@ -44,12 +44,17 @@ end
|
|
44
44
|
|
45
45
|
module Zuora
|
46
46
|
class Client
|
47
|
-
|
48
|
-
|
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
|
49
54
|
|
50
55
|
def self.config
|
51
56
|
return @config_hash if @config_hash
|
52
|
-
@config_hash =
|
57
|
+
@config_hash = Zuora::CONFIG if defined?(Zuora::CONFIG)
|
53
58
|
@config_hash ||= {}
|
54
59
|
end
|
55
60
|
|
@@ -71,10 +76,10 @@ module Zuora
|
|
71
76
|
@custom_fields = YAML.load_file(File.dirname(__FILE__) + '/../custom_fields.yml')
|
72
77
|
end
|
73
78
|
|
74
|
-
def initialize(url=
|
79
|
+
def initialize(url=nil)
|
75
80
|
$ZUORA_USER = self.class.config["username"]
|
76
81
|
$ZUORA_PASSWORD = self.class.config["password"]
|
77
|
-
$ZUORA_ENDPOINT = url
|
82
|
+
$ZUORA_ENDPOINT = url || self.class.app_url
|
78
83
|
|
79
84
|
@client = ZuoraInterface.new
|
80
85
|
|
@@ -84,34 +89,29 @@ module Zuora
|
|
84
89
|
end
|
85
90
|
|
86
91
|
def query(query_string)
|
92
|
+
# This will keep calling queryMore until all the results are retreived.
|
87
93
|
|
88
94
|
query_string =~ /select\s+(.+)\s+from/i
|
89
95
|
fields = ($1.split /,\s+/).map do |f|
|
90
96
|
f.gsub!(/\b\w/) { $&.downcase }
|
91
97
|
end
|
92
98
|
|
99
|
+
responses = []
|
93
100
|
begin
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
result = []
|
100
|
-
if response && response.result && response.result.size > 0
|
101
|
-
response.result.records.each do |record|
|
102
|
-
row = {}
|
103
|
-
fields.each do |f|
|
104
|
-
row[f] = record.send(f)
|
105
|
-
end
|
106
|
-
result << row
|
101
|
+
responses << @client.api_call(:query, query_string)
|
102
|
+
until responses.last.result.done
|
103
|
+
responses << @client.api_call(:query_more, responses.last.result.queryLocator)
|
107
104
|
end
|
105
|
+
rescue Exception => e
|
106
|
+
$stderr.puts e.message
|
108
107
|
end
|
109
|
-
|
108
|
+
# Capture all the records into one single array.
|
109
|
+
responses.map{ |response| response.result.size > 0 ? response.result.records : [] }.flatten
|
110
110
|
end
|
111
111
|
|
112
112
|
def subscribe(obj)
|
113
113
|
begin
|
114
|
-
response = @client.subscribe
|
114
|
+
response = @client.api_call(:subscribe, obj)
|
115
115
|
return response
|
116
116
|
rescue Exception => e
|
117
117
|
puts e.message
|
@@ -120,7 +120,7 @@ module Zuora
|
|
120
120
|
|
121
121
|
def create(obj)
|
122
122
|
begin
|
123
|
-
response = @client.create
|
123
|
+
response = @client.api_call(:create,obj)
|
124
124
|
result = save_results_to_hash(response)
|
125
125
|
rescue Exception => e
|
126
126
|
puts e.message
|
@@ -130,7 +130,7 @@ module Zuora
|
|
130
130
|
|
131
131
|
def generate(obj)
|
132
132
|
begin
|
133
|
-
response = @client.generate
|
133
|
+
response = @client.api_call(:generate,obj)
|
134
134
|
result = save_results_to_hash(response)
|
135
135
|
rescue Exception => e
|
136
136
|
puts e.message
|
@@ -140,7 +140,7 @@ module Zuora
|
|
140
140
|
|
141
141
|
def update(obj)
|
142
142
|
begin
|
143
|
-
response = @client.update
|
143
|
+
response = @client.api_call(:update, obj)
|
144
144
|
result = save_results_to_hash(response)
|
145
145
|
rescue Exception => e
|
146
146
|
puts e.message
|
@@ -150,7 +150,7 @@ module Zuora
|
|
150
150
|
|
151
151
|
def delete(type, ids)
|
152
152
|
begin
|
153
|
-
response = @client.delete
|
153
|
+
response = @client.api_call(:delete, type, ids)
|
154
154
|
result = save_results_to_hash(response)
|
155
155
|
rescue Exception => e
|
156
156
|
puts e.message
|
@@ -158,6 +158,10 @@ module Zuora
|
|
158
158
|
result || []
|
159
159
|
end
|
160
160
|
|
161
|
+
def amend(obj)
|
162
|
+
@client.api_call(:amend, obj)
|
163
|
+
end
|
164
|
+
|
161
165
|
private
|
162
166
|
|
163
167
|
def save_results_to_hash(save_results)
|
data/lib/zuora_interface.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'zuora/api'
|
2
2
|
|
3
3
|
class ZuoraInterface
|
4
|
+
begin
|
5
|
+
require 'system_timer'
|
6
|
+
SysTimer = SystemTimer
|
7
|
+
rescue LoadError
|
8
|
+
require 'timeout'
|
9
|
+
SysTimer = Timeout
|
10
|
+
end
|
4
11
|
|
5
12
|
def make_account(accountName)
|
6
13
|
acc = ZUORA::Account.new
|
@@ -93,11 +100,16 @@ class ZuoraInterface
|
|
93
100
|
return val
|
94
101
|
end
|
95
102
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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))
|
101
113
|
end
|
102
114
|
|
103
115
|
def create(objs)
|
@@ -123,6 +135,10 @@ class ZuoraInterface
|
|
123
135
|
return @z.subscribe(sub)
|
124
136
|
end
|
125
137
|
|
138
|
+
def amend(amend)
|
139
|
+
return @z.amend(amend)
|
140
|
+
end
|
141
|
+
|
126
142
|
def get_object(query)
|
127
143
|
object = lookup(query)
|
128
144
|
unless object.result.size == 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_zuora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,75 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: soap4r
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json_pure
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.4'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: soap4r
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
17
81
|
none: false
|
18
82
|
requirements:
|
19
83
|
- - ! '>='
|
@@ -21,10 +85,15 @@ dependencies:
|
|
21
85
|
version: 1.5.8
|
22
86
|
type: :runtime
|
23
87
|
prerelease: false
|
24
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.5.8
|
25
94
|
- !ruby/object:Gem::Dependency
|
26
95
|
name: json_pure
|
27
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
28
97
|
none: false
|
29
98
|
requirements:
|
30
99
|
- - ! '>='
|
@@ -32,7 +101,12 @@ dependencies:
|
|
32
101
|
version: 1.4.6
|
33
102
|
type: :runtime
|
34
103
|
prerelease: false
|
35
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.4.6
|
36
110
|
description: A client for Zuora API
|
37
111
|
email: anfleene@gmail.com
|
38
112
|
executables: []
|
@@ -46,21 +120,39 @@ files:
|
|
46
120
|
- active_zuora.gemspec
|
47
121
|
- custom_fields.yml
|
48
122
|
- lib/active_zuora.rb
|
123
|
+
- lib/active_zuora/account.rb
|
124
|
+
- lib/active_zuora/amendment.rb
|
125
|
+
- lib/active_zuora/bill_run.rb
|
126
|
+
- lib/active_zuora/contact.rb
|
127
|
+
- lib/active_zuora/invoice.rb
|
128
|
+
- lib/active_zuora/invoice_item.rb
|
129
|
+
- lib/active_zuora/invoice_item_adjustment.rb
|
130
|
+
- lib/active_zuora/invoice_payment.rb
|
131
|
+
- lib/active_zuora/payment.rb
|
132
|
+
- lib/active_zuora/payment_method.rb
|
133
|
+
- lib/active_zuora/product.rb
|
134
|
+
- lib/active_zuora/product_rate_plan.rb
|
135
|
+
- lib/active_zuora/product_rate_plan_charge.rb
|
136
|
+
- lib/active_zuora/product_rate_plan_charge_tier.rb
|
137
|
+
- lib/active_zuora/product_rate_plan_charge_tier_data.rb
|
138
|
+
- lib/active_zuora/rate_plan.rb
|
139
|
+
- lib/active_zuora/rate_plan_charge.rb
|
140
|
+
- lib/active_zuora/rate_plan_charge_data.rb
|
141
|
+
- lib/active_zuora/rate_plan_charge_tier.rb
|
142
|
+
- lib/active_zuora/rate_plan_data.rb
|
143
|
+
- lib/active_zuora/refund.rb
|
144
|
+
- lib/active_zuora/subscribe_options.rb
|
145
|
+
- lib/active_zuora/subscribe_request.rb
|
146
|
+
- lib/active_zuora/subscribe_with_existing_account_request.rb
|
147
|
+
- lib/active_zuora/subscription.rb
|
148
|
+
- lib/active_zuora/subscription_data.rb
|
149
|
+
- lib/active_zuora/usage.rb
|
150
|
+
- lib/active_zuora/zobject.rb
|
49
151
|
- lib/zuora/ZUORA.rb
|
50
152
|
- lib/zuora/ZUORADriver.rb
|
51
153
|
- lib/zuora/ZUORAMappingRegistry.rb
|
52
154
|
- lib/zuora/ZuoraServiceClient.rb
|
53
|
-
- lib/zuora/account.rb
|
54
155
|
- lib/zuora/api.rb
|
55
|
-
- lib/zuora/contact.rb
|
56
|
-
- lib/zuora/rate_plan.rb
|
57
|
-
- lib/zuora/rate_plan_data.rb
|
58
|
-
- lib/zuora/subscribe_options.rb
|
59
|
-
- lib/zuora/subscribe_request.rb
|
60
|
-
- lib/zuora/subscribe_with_existing_account_request.rb
|
61
|
-
- lib/zuora/subscription.rb
|
62
|
-
- lib/zuora/subscription_data.rb
|
63
|
-
- lib/zuora/zobject.rb
|
64
156
|
- lib/zuora_client.rb
|
65
157
|
- lib/zuora_interface.rb
|
66
158
|
- LICENSE
|
@@ -77,6 +169,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
169
|
- - ! '>='
|
78
170
|
- !ruby/object:Gem::Version
|
79
171
|
version: '0'
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
hash: -4160532751421098619
|
80
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
176
|
none: false
|
82
177
|
requirements:
|
@@ -86,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
181
|
requirements:
|
87
182
|
- none
|
88
183
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
184
|
+
rubygems_version: 1.8.24
|
90
185
|
signing_key:
|
91
186
|
specification_version: 3
|
92
187
|
summary: Active Zuora
|
data/lib/zuora/account.rb
DELETED
data/lib/zuora/contact.rb
DELETED
data/lib/zuora/rate_plan.rb
DELETED
data/lib/zuora/subscription.rb
DELETED
data/lib/zuora/zobject.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
module Zuora
|
2
|
-
class ZObject < SimpleDelegator
|
3
|
-
def initialize(attributes={})
|
4
|
-
super(self.class.zobject_class.new).tap do |zobject|
|
5
|
-
attributes.each do |attr, value|
|
6
|
-
zobject.send("#{attr}=", value)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_zobject
|
12
|
-
__getobj__
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.zobject_class
|
16
|
-
return @zobject_class if @zobject_class
|
17
|
-
klass_name = name.match(/(\w+)::(\w+)/)
|
18
|
-
@zobject_class = "#{klass_name[1].upcase}::#{klass_name[2]}".constantize
|
19
|
-
end
|
20
|
-
|
21
|
-
#TODO: This sucks attributes need to be clearly defined
|
22
|
-
def self.attribute_names
|
23
|
-
@attribute_names ||= zobject_class.instance_variable_get("@attributes").reject{|name| name == :fieldsToNull }
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.where(conditions={})
|
27
|
-
zobjects = self.client.query("select #{self.attribute_names.join(", ")} from #{self.name.gsub(/Zuora::/,"")} where #{build_filter_statments(conditions)}")
|
28
|
-
zobjects.map{|zobject| self.new zobject }
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.build_filter_statments(filter_statments)
|
32
|
-
filter_statments.map{|key, value|
|
33
|
-
value = "'#{value}'" if value.kind_of?(String)
|
34
|
-
"#{key} = #{value}"
|
35
|
-
}.join(" and ")
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.find(id)
|
39
|
-
zobject = client.query("select #{attribute_names.join(", ")} from #{self.name.gsub(/Zuora::/,"")} where Id = '#{id}'").first
|
40
|
-
self.new zobject if zobject
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.all
|
44
|
-
zobjects = client.query("select #{attribute_names.join(", ")} from #{self.name.gsub(/Zuora::/,"")}")
|
45
|
-
zobjects.map{|zobject| self.new zobject }
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.client
|
49
|
-
@client ||= Zuora::Client.new
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|