spreedly 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/README.txt +1 -1
- data/Rakefile +6 -6
- data/TODO +1 -0
- data/lib/spreedly/mock.rb +4 -0
- data/lib/spreedly/version.rb +1 -1
- data/lib/spreedly.rb +30 -4
- data/test/spreedly_gem_test.rb +11 -0
- metadata +4 -3
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -47,26 +47,26 @@ end
|
|
47
47
|
|
48
48
|
desc "Run tests with and without mocking."
|
49
49
|
replace_task :test do
|
50
|
-
hoe.
|
50
|
+
ruby hoe.make_test_cmd
|
51
51
|
|
52
52
|
ENV["SPREEDLY_TEST"] = "REAL"
|
53
|
-
hoe.
|
53
|
+
ruby hoe.make_test_cmd
|
54
54
|
end
|
55
55
|
|
56
56
|
desc "Run only mock tests."
|
57
57
|
task :test_mock do
|
58
|
-
hoe.
|
58
|
+
ruby hoe.make_test_cmd
|
59
59
|
end
|
60
60
|
|
61
61
|
desc "Run only real tests."
|
62
62
|
task :test_real do
|
63
63
|
ENV["SPREEDLY_TEST"] = "REAL"
|
64
|
-
hoe.
|
64
|
+
ruby hoe.make_test_cmd
|
65
65
|
end
|
66
66
|
|
67
67
|
desc "Run both sets of tests under multiruby"
|
68
68
|
replace_task :multi do
|
69
|
-
hoe.
|
69
|
+
ruby hoe.make_test_cmd(:multi)
|
70
70
|
ENV["SPREEDLY_TEST"] = "REAL"
|
71
|
-
hoe.
|
71
|
+
ruby hoe.make_test_cmd(:multi)
|
72
72
|
end
|
data/TODO
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
- Create a test for Subscriber#activate_free_trial once there's an API to create subscription plans.
|
data/lib/spreedly/mock.rb
CHANGED
data/lib/spreedly/version.rb
CHANGED
data/lib/spreedly.rb
CHANGED
@@ -86,10 +86,17 @@ module Spreedly
|
|
86
86
|
|
87
87
|
# This will DELETE all the subscribers from the site.
|
88
88
|
#
|
89
|
-
# Only works for
|
89
|
+
# Only works for test sites (enforced on the Spreedly side).
|
90
90
|
def self.wipe!
|
91
91
|
Spreedly.delete('/subscribers.xml')
|
92
92
|
end
|
93
|
+
|
94
|
+
# This will DELETE individual subscribers from the site. Pass in the customer_id.
|
95
|
+
#
|
96
|
+
# Only works for test sites (enforced on the Spreedly side).
|
97
|
+
def self.delete!(id)
|
98
|
+
Spreedly.delete("/subscribers/#{id}.xml")
|
99
|
+
end
|
93
100
|
|
94
101
|
# Creates a new subscriber on Spreedly. The subscriber will NOT
|
95
102
|
# be active - they have to pay or you have to comp them for that
|
@@ -97,7 +104,7 @@ module Spreedly
|
|
97
104
|
def self.create!(id, email=nil, screen_name=nil)
|
98
105
|
result = Spreedly.post('/subscribers.xml', :body =>
|
99
106
|
Spreedly.to_xml_params(:subscriber => {:customer_id => id, :email => email, :screen_name => screen_name}))
|
100
|
-
case result.code
|
107
|
+
case result.code.to_s
|
101
108
|
when /2../
|
102
109
|
new(result['subscriber'])
|
103
110
|
when '403'
|
@@ -125,7 +132,7 @@ module Spreedly
|
|
125
132
|
|
126
133
|
# Allows you to give a complimentary subscription (if the
|
127
134
|
# subscriber is inactive) or a complimentary time extension (if
|
128
|
-
# the subscriber is
|
135
|
+
# the subscriber is active). Automatically figures out which
|
129
136
|
# to do.
|
130
137
|
#
|
131
138
|
# Note: units must be one of "days" or "months" (Spreedly
|
@@ -135,7 +142,7 @@ module Spreedly
|
|
135
142
|
params[:feature_level] = feature_level if feature_level
|
136
143
|
endpoint = (active? ? "complimentary_time_extensions" : "complimentary_subscriptions")
|
137
144
|
result = Spreedly.post("/subscribers/#{id}/#{endpoint}.xml", :body => Spreedly.to_xml_params(endpoint[0..-2] => params))
|
138
|
-
case result.code
|
145
|
+
case result.code.to_s
|
139
146
|
when /2../
|
140
147
|
when '404'
|
141
148
|
raise "Could not comp subscriber: no longer exists."
|
@@ -147,6 +154,25 @@ module Spreedly
|
|
147
154
|
raise "Could not comp subscriber: result code #{result.code}."
|
148
155
|
end
|
149
156
|
end
|
157
|
+
|
158
|
+
# Activates a free trial on the subscriber.
|
159
|
+
# Requires subscription_id of the free trial plan
|
160
|
+
def activate_free_trial(subscription_id)
|
161
|
+
result = Spreedly.post("/subscribers/#{id}/subscribe_to_free_trial.xml", :body =>
|
162
|
+
Spreedly.to_xml_params(:subscription_plan => {:id => subscription_id}))
|
163
|
+
case result.code
|
164
|
+
when /2../
|
165
|
+
when '404'
|
166
|
+
raise "Could not active free trial for subscriber: subscriber or subscription plan no longer exists."
|
167
|
+
when '422'
|
168
|
+
raise "Could not activate free trial for subscriber: validation failed. missing subscription plan id"
|
169
|
+
when '403'
|
170
|
+
raise "Could not activate free trial for subscriber: subscription plan either 1) isn't a free trial, 2) the subscriber is not eligible for a free trial, or 3) the subscription plan is not enabled."
|
171
|
+
else
|
172
|
+
raise "Could not activate free trial for subscriber: result code #{result.code}."
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
150
176
|
end
|
151
177
|
|
152
178
|
class SubscriptionPlan < Resource
|
data/test/spreedly_gem_test.rb
CHANGED
@@ -22,6 +22,17 @@ class SpreedlyGemTest < Test::Unit::TestCase
|
|
22
22
|
Spreedly::Subscriber.wipe!
|
23
23
|
end
|
24
24
|
|
25
|
+
should "delete a subscriber" do
|
26
|
+
one = create_subscriber
|
27
|
+
two = create_subscriber
|
28
|
+
subscribers = Spreedly::Subscriber.all
|
29
|
+
assert subscribers.size == 2
|
30
|
+
Spreedly::Subscriber.delete!(one.id)
|
31
|
+
subscribers = Spreedly::Subscriber.all
|
32
|
+
assert subscribers.size == 1
|
33
|
+
assert_equal two.id, subscribers.first.id
|
34
|
+
end
|
35
|
+
|
25
36
|
should "add a subscriber" do
|
26
37
|
subscriber = Spreedly::Subscriber.create!('joe')
|
27
38
|
assert_not_nil subscriber.token
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreedly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Talbott
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-24 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.12.2
|
34
34
|
version:
|
35
35
|
description: The Spreedly gem provides a convenient Ruby wrapper for the goodness that is the http://spreedly.com API. Created by Terralien[http://terralien.com].
|
36
36
|
email:
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- Manifest.txt
|
49
49
|
- README.txt
|
50
50
|
- Rakefile
|
51
|
+
- TODO
|
51
52
|
- lib/spreedly.rb
|
52
53
|
- lib/spreedly/common.rb
|
53
54
|
- lib/spreedly/mock.rb
|