spreedly 1.3.6 → 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.
- checksums.yaml +8 -8
- data/HISTORY.md +5 -0
- data/lib/spreedly.rb +16 -2
- data/lib/spreedly/mock.rb +70 -30
- data/lib/spreedly/test_hacks.rb +6 -3
- data/lib/spreedly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWQ5NjM1NzgyZTBkYWJjY2I1MDM0ZDExMzJiMjIyNTExNjg2ODQ5MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmMyNjUyZTIxNDNiYzAwZjVjNzgwZDRkYzk0MjRkMWNiODkzNmZjOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmExNTYxMDhlYjdlZGZjZDYxOGE2Y2Q4MTcwNjlmN2M3NWYxYzE2N2FiMGI3
|
10
|
+
YWQ4NjY0OTRhYmViN2IxNWJhNmU4M2ZkYjJlM2I2ODRhMmZlYzM0ZGRhMzU2
|
11
|
+
NzhiMzc4NzUzOGI4MzNhYmIyNmZiYTFkYzgzOTk4YTdjYTcyYTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzZmMDVlYjNhOWQ4NTg3ZTAzNjJjMTE3ZTgzNzViZTYwYTVmYmUzMTZmMzFi
|
14
|
+
NWZlZWY0NjJmYjllZDI5YTJhMzMyMmYzMjdlYTNkZjYxNTk5YTIxM2U5ODkw
|
15
|
+
NmVjMmI3YzU3OGE4NDkwOWRhNzAxYWNjMzhiZjQ2ODc3OTQyMjA=
|
data/HISTORY.md
CHANGED
data/lib/spreedly.rb
CHANGED
@@ -83,7 +83,6 @@ module Spreedly
|
|
83
83
|
end
|
84
84
|
|
85
85
|
class Subscriber < Resource
|
86
|
-
|
87
86
|
# This will DELETE all the subscribers from the site.
|
88
87
|
#
|
89
88
|
# Only works for test sites (enforced on the Spreedly side).
|
@@ -219,7 +218,7 @@ module Spreedly
|
|
219
218
|
end
|
220
219
|
end
|
221
220
|
|
222
|
-
#
|
221
|
+
# Allow Another Free Trial
|
223
222
|
# usage: @subscriber.allow_free_trial
|
224
223
|
def allow_free_trial
|
225
224
|
result = Spreedly.post("/subscribers/#{id}/allow_free_trial.xml")
|
@@ -246,6 +245,21 @@ module Spreedly
|
|
246
245
|
raise "Could not add fee to subscriber: result code #{result.code}."
|
247
246
|
end
|
248
247
|
end
|
248
|
+
|
249
|
+
# Get the invoices for the subscriber
|
250
|
+
def invoices
|
251
|
+
@invoices ||= @data["invoices"].collect{|i| Invoice.new(i)}
|
252
|
+
end
|
253
|
+
|
254
|
+
# Get the last successful invoice
|
255
|
+
def last_successful_invoice
|
256
|
+
invoices.detect do |invoice|
|
257
|
+
invoice.closed?
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
class Invoice < Resource
|
249
263
|
end
|
250
264
|
|
251
265
|
class SubscriptionPlan < Resource
|
data/lib/spreedly/mock.rb
CHANGED
@@ -4,15 +4,15 @@ raise "Real Spreedly already required!" if defined?(Spreedly::REAL)
|
|
4
4
|
|
5
5
|
module Spreedly
|
6
6
|
MOCK = "mock"
|
7
|
-
|
7
|
+
|
8
8
|
def self.configure(name, token)
|
9
9
|
@site_name = name
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def self.site_name
|
13
13
|
@site_name
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
class Resource
|
17
17
|
def self.attributes
|
18
18
|
@attributes ||= {}
|
@@ -21,12 +21,13 @@ module Spreedly
|
|
21
21
|
def self.attributes=(value)
|
22
22
|
@attributes = value
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
attr_reader :attributes
|
25
26
|
def initialize(params={})
|
26
27
|
@attributes = self.class.attributes.inject({}){|a,(k,v)| a[k.to_sym] = v.call; a}
|
27
28
|
params.each {|k,v| @attributes[k.to_sym] = v }
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
def id
|
31
32
|
@attributes[:id]
|
32
33
|
end
|
@@ -41,7 +42,7 @@ module Spreedly
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
class Subscriber < Resource
|
46
47
|
self.attributes = {
|
47
48
|
:created_at => proc{Time.now},
|
@@ -58,7 +59,7 @@ module Spreedly
|
|
58
59
|
def self.wipe! # :nodoc: all
|
59
60
|
@subscribers = nil
|
60
61
|
end
|
61
|
-
|
62
|
+
|
62
63
|
def self.create!(id, *args) # :nodoc: all
|
63
64
|
optional_attrs = args.last.is_a?(::Hash) ? args.pop : {}
|
64
65
|
email, screen_name = args
|
@@ -71,34 +72,35 @@ module Spreedly
|
|
71
72
|
subscribers[sub.id] = sub
|
72
73
|
sub
|
73
74
|
end
|
74
|
-
|
75
|
+
|
75
76
|
def self.delete!(id)
|
76
77
|
subscribers.delete(id)
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
def self.find(id)
|
80
81
|
subscribers[id]
|
81
82
|
end
|
82
|
-
|
83
|
+
|
83
84
|
def self.subscribers
|
84
85
|
@subscribers ||= {}
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
def self.all
|
88
89
|
@subscribers.values
|
89
90
|
end
|
90
|
-
|
91
|
+
|
91
92
|
def initialize(params={})
|
92
93
|
super
|
93
94
|
if !id || id == ''
|
94
95
|
raise "Could not create subscriber: Customer ID can't be blank."
|
95
96
|
end
|
97
|
+
@invoices ||= []
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
def id
|
99
101
|
@attributes[:customer_id]
|
100
102
|
end
|
101
|
-
|
103
|
+
|
102
104
|
def update(args)
|
103
105
|
args.each_pair do |key, value|
|
104
106
|
if @attributes.has_key?(key)
|
@@ -106,7 +108,7 @@ module Spreedly
|
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end
|
109
|
-
|
111
|
+
|
110
112
|
def comp(quantity, units, feature_level=nil)
|
111
113
|
raise "Could not comp subscriber: no longer exists." unless self.class.find(id)
|
112
114
|
raise "Could not comp subscriber: validation failed." unless units && quantity
|
@@ -129,53 +131,91 @@ module Spreedly
|
|
129
131
|
plan = SubscriptionPlan.find(plan_id)
|
130
132
|
comp(plan.duration_quantity, plan.duration_units, plan.feature_level)
|
131
133
|
end
|
132
|
-
|
134
|
+
|
133
135
|
def allow_free_trial
|
134
|
-
@attributes[:eligible_for_free_trial] = true
|
136
|
+
@attributes[:eligible_for_free_trial] = true
|
135
137
|
end
|
136
138
|
|
137
139
|
def stop_auto_renew
|
138
140
|
raise "Could not stop auto renew for subscriber: subscriber does not exist." unless self.class.find(id)
|
139
141
|
@attributes[:recurring] = false
|
140
142
|
end
|
141
|
-
|
142
|
-
def subscribe(plan_id)
|
143
|
-
@attributes[:recurring] = true
|
143
|
+
|
144
|
+
def subscribe(plan_id, card_number="4222222222222")
|
144
145
|
plan = SubscriptionPlan.find(plan_id)
|
146
|
+
@invoices.unshift(Invoice.new(
|
147
|
+
amount: (@invoices.select{|invoice| invoice.closed?}.size > 0 ? 0 : plan.amount),
|
148
|
+
closed: false
|
149
|
+
))
|
150
|
+
|
151
|
+
return unless card_number == "4222222222222"
|
152
|
+
|
153
|
+
@invoices.first.attributes[:closed] = true
|
154
|
+
@attributes[:recurring] = true
|
145
155
|
comp(plan.duration_quantity, plan.duration_units, plan.feature_level)
|
146
156
|
end
|
147
|
-
|
157
|
+
|
148
158
|
def add_fee(args)
|
149
159
|
raise "Unprocessable Entity" unless (args.keys & [:amount, :group, :name]).size == 3
|
150
160
|
raise "Unprocessable Entity" unless active?
|
151
161
|
nil
|
152
162
|
end
|
163
|
+
|
164
|
+
def invoices
|
165
|
+
@invoices
|
166
|
+
end
|
167
|
+
|
168
|
+
def last_successful_invoice
|
169
|
+
@invoices.detect{|invoice| invoice.closed?}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class Invoice < Resource
|
153
174
|
end
|
154
|
-
|
175
|
+
|
155
176
|
class SubscriptionPlan < Resource
|
156
177
|
self.attributes = {
|
157
178
|
:plan_type => proc{'regular'},
|
158
179
|
:feature_level => proc{''}
|
159
180
|
}
|
160
|
-
|
181
|
+
|
161
182
|
def self.all
|
162
183
|
plans.values
|
163
184
|
end
|
164
|
-
|
185
|
+
|
165
186
|
def self.find(id)
|
166
187
|
plans[id.to_i]
|
167
188
|
end
|
168
|
-
|
189
|
+
|
169
190
|
def self.plans
|
170
191
|
@plans ||= {
|
171
|
-
1 => new(
|
172
|
-
|
173
|
-
|
192
|
+
1 => new(
|
193
|
+
:id => 1,
|
194
|
+
:name => 'Default mock plan',
|
195
|
+
:duration_quantity => 1,
|
196
|
+
:duration_units => 'days',
|
197
|
+
:amount => 6
|
198
|
+
),
|
199
|
+
2 => new(
|
200
|
+
:id => 2,
|
201
|
+
:name => 'Test Free Trial Plan',
|
202
|
+
:plan_type => 'free_trial',
|
203
|
+
:duration_quantity => 1,
|
204
|
+
:duration_units => 'days',
|
205
|
+
:amount => 11
|
206
|
+
),
|
207
|
+
3 => new(
|
208
|
+
:id => 3,
|
209
|
+
:name => 'Test Regular Plan',
|
210
|
+
:duration_quantity => 1,
|
211
|
+
:duration_units => 'days',
|
212
|
+
:amount => 17
|
213
|
+
)
|
174
214
|
}
|
175
215
|
end
|
176
|
-
|
216
|
+
|
177
217
|
def trial?
|
178
218
|
(plan_type == "free_trial")
|
179
219
|
end
|
180
220
|
end
|
181
|
-
end
|
221
|
+
end
|
data/lib/spreedly/test_hacks.rb
CHANGED
@@ -4,7 +4,7 @@ module Spreedly
|
|
4
4
|
class Subscriber
|
5
5
|
# This method is *strictly* for use when testing, and will
|
6
6
|
# probably only work against a test Spreedly site anyhow.
|
7
|
-
def subscribe(plan_id)
|
7
|
+
def subscribe(plan_id, card_number="4222222222222")
|
8
8
|
agent = Mechanize.new
|
9
9
|
page = agent.get(Spreedly.subscribe_url(id, plan_id))
|
10
10
|
page = page.forms.first.submit
|
@@ -12,13 +12,16 @@ module Spreedly
|
|
12
12
|
form['credit_card[first_name]'] = 'Joe'
|
13
13
|
form['credit_card[last_name]'] = 'Bob'
|
14
14
|
form['subscriber[email]'] = 'joe@example.com'
|
15
|
-
form['credit_card[number]'] =
|
15
|
+
form['credit_card[number]'] = card_number
|
16
16
|
form['credit_card[card_type]'] = 'visa'
|
17
17
|
form['credit_card[verification_value]'] = '234'
|
18
18
|
form['credit_card[month]'] = '1'
|
19
19
|
form['credit_card[year]'] = '2024'
|
20
20
|
page = form.click_button
|
21
|
-
|
21
|
+
|
22
|
+
if card_number == "4222222222222"
|
23
|
+
raise "Subscription didn't go through" unless page.title == "Thank you!"
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/spreedly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreedly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spreedly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
prerelease: false
|