spreedly 1.3.0 → 1.3.1
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/History.txt +7 -0
- data/Manifest.txt +1 -0
- data/README.txt +1 -1
- data/Rakefile +6 -8
- data/lib/spreedly.rb +19 -8
- data/lib/spreedly/common.rb +1 -1
- data/lib/spreedly/mock.rb +19 -10
- data/lib/spreedly/test_hacks.rb +24 -0
- data/lib/spreedly/version.rb +1 -1
- data/test/spreedly_gem_test.rb +23 -6
- metadata +12 -7
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 1.3.1
|
2
|
+
|
3
|
+
* Handle new error reporting when creating a subscriber.
|
4
|
+
* Use a more sane way of setting attributes in the mock, and make plans have a
|
5
|
+
plan type [seancribbs].
|
6
|
+
* Allow optional arguments to be passed when creating subscribers [jaknowlden].
|
7
|
+
|
1
8
|
=== 1.3.0 / 2009-06-04
|
2
9
|
|
3
10
|
* Properly handle invalid Subscriber lookup [karnowski].
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -3,14 +3,12 @@ require './lib/spreedly/version.rb'
|
|
3
3
|
|
4
4
|
ENV["COPYFILE_DISABLE"] = "true" # Lose all the fugly ._ files when tar'ing
|
5
5
|
|
6
|
-
hoe =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
project.extra_deps = ["mechanize"]
|
13
|
-
project.extra_dev_deps = ["thoughtbot-shoulda"]
|
6
|
+
hoe = Hoe.spec('spreedly') do
|
7
|
+
developer('Nathaniel Talbott', 'nathaniel@terralien.com')
|
8
|
+
self.rubyforge_name = 'terralien'
|
9
|
+
self.test_globs = ["test/**/*_test.rb"]
|
10
|
+
self.extra_deps << ["mechanize"]
|
11
|
+
self.extra_dev_deps << ["thoughtbot-shoulda"]
|
14
12
|
end
|
15
13
|
|
16
14
|
def remove_task(*task_names)
|
data/lib/spreedly.rb
CHANGED
@@ -101,14 +101,25 @@ module Spreedly
|
|
101
101
|
# Creates a new subscriber on Spreedly. The subscriber will NOT
|
102
102
|
# be active - they have to pay or you have to comp them for that
|
103
103
|
# to happen.
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
#
|
105
|
+
# Usage:
|
106
|
+
# Spreedly.Subscriber.create!(id, email)
|
107
|
+
# Spreedly.Subscriber.create!(id, email, screen_name)
|
108
|
+
# Spreedly.Subscriber.create!(id, :email => email, :screen_name => screen_name)
|
109
|
+
# Spreedly.Subscriber.create!(id, email, screen_name, :billing_first_name => first_name)
|
110
|
+
def self.create!(id, *args)
|
111
|
+
optional_attrs = args.last.is_a?(::Hash) ? args.pop : {}
|
112
|
+
email, screen_name = args
|
113
|
+
subscriber = {:customer_id => id, :email => email, :screen_name => screen_name}.merge(optional_attrs)
|
114
|
+
result = Spreedly.post('/subscribers.xml', :body => Spreedly.to_xml_params(:subscriber => subscriber))
|
107
115
|
case result.code.to_s
|
108
116
|
when /2../
|
109
117
|
new(result['subscriber'])
|
110
118
|
when '403'
|
111
|
-
raise "Could not create subscriber:
|
119
|
+
raise "Could not create subscriber: already exists."
|
120
|
+
when '422'
|
121
|
+
errors = [*result['errors']].collect{|e| e.last}
|
122
|
+
raise "Could not create subscriber: #{errors.join(', ')}"
|
112
123
|
else
|
113
124
|
raise "Could not create subscriber: result code #{result.code}."
|
114
125
|
end
|
@@ -117,7 +128,7 @@ module Spreedly
|
|
117
128
|
# Looks a subscriber up by id.
|
118
129
|
def self.find(id)
|
119
130
|
xml = Spreedly.get("/subscribers/#{id}.xml")
|
120
|
-
(xml.nil? ? nil : new(xml['subscriber']))
|
131
|
+
(xml.nil? || xml.empty? ? nil : new(xml['subscriber']))
|
121
132
|
end
|
122
133
|
|
123
134
|
# Returns all the subscribers in your site.
|
@@ -161,7 +172,7 @@ module Spreedly
|
|
161
172
|
def activate_free_trial(plan_id)
|
162
173
|
result = Spreedly.post("/subscribers/#{id}/subscribe_to_free_trial.xml", :body =>
|
163
174
|
Spreedly.to_xml_params(:subscription_plan => {:id => plan_id}))
|
164
|
-
case result.code
|
175
|
+
case result.code.to_s
|
165
176
|
when /2../
|
166
177
|
when '404'
|
167
178
|
raise "Could not active free trial for subscriber: subscriber or subscription plan no longer exists."
|
@@ -178,7 +189,7 @@ module Spreedly
|
|
178
189
|
# usage: @subscriber.stop_auto_renew
|
179
190
|
def stop_auto_renew
|
180
191
|
result = Spreedly.post("/subscribers/#{id}/stop_auto_renew.xml")
|
181
|
-
case result.code
|
192
|
+
case result.code.to_s
|
182
193
|
when /2../
|
183
194
|
when '404'
|
184
195
|
raise "Could not stop auto renew for subscriber: subscriber does not exist."
|
@@ -205,4 +216,4 @@ module Spreedly
|
|
205
216
|
(plan_type == 'free_trial')
|
206
217
|
end
|
207
218
|
end
|
208
|
-
end
|
219
|
+
end
|
data/lib/spreedly/common.rb
CHANGED
data/lib/spreedly/mock.rb
CHANGED
@@ -23,8 +23,8 @@ module Spreedly
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def initialize(params={})
|
26
|
-
@attributes =
|
27
|
-
|
26
|
+
@attributes = self.class.attributes.inject({}){|a,(k,v)| a[k.to_sym] = v.call; a}
|
27
|
+
params.each {|k,v| @attributes[k.to_sym] = v }
|
28
28
|
end
|
29
29
|
|
30
30
|
def id
|
@@ -58,8 +58,10 @@ module Spreedly
|
|
58
58
|
@subscribers = nil
|
59
59
|
end
|
60
60
|
|
61
|
-
def self.create!(id,
|
62
|
-
|
61
|
+
def self.create!(id, *args) # :nodoc: all
|
62
|
+
optional_attrs = args.last.is_a?(::Hash) ? args.pop : {}
|
63
|
+
email, screen_name = args
|
64
|
+
sub = new({:customer_id => id, :email => email, :screen_name => screen_name}.merge(optional_attrs))
|
63
65
|
|
64
66
|
if subscribers[sub.id]
|
65
67
|
raise "Could not create subscriber: already exists."
|
@@ -88,7 +90,7 @@ module Spreedly
|
|
88
90
|
def initialize(params={})
|
89
91
|
super
|
90
92
|
if !id || id == ''
|
91
|
-
raise "Could not create subscriber:
|
93
|
+
raise "Could not create subscriber: Customer ID can't be blank."
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
@@ -114,8 +116,9 @@ module Spreedly
|
|
114
116
|
raise "Could not activate free trial for subscriber: validation failed. missing subscription plan id" unless plan_id
|
115
117
|
raise "Could not active free trial for subscriber: subscriber or subscription plan no longer exists." unless self.class.find(id) && SubscriptionPlan.find(plan_id)
|
116
118
|
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." if on_trial?
|
117
|
-
@attributes[:active] = true
|
118
119
|
@attributes[:on_trial] = true
|
120
|
+
plan = SubscriptionPlan.find(plan_id)
|
121
|
+
comp(plan.duration_quantity, plan.duration_units, plan.feature_level)
|
119
122
|
end
|
120
123
|
|
121
124
|
def stop_auto_renew
|
@@ -124,12 +127,18 @@ module Spreedly
|
|
124
127
|
end
|
125
128
|
|
126
129
|
def subscribe(plan_id)
|
127
|
-
@attributes[:active] = true
|
128
130
|
@attributes[:recurring] = true
|
131
|
+
plan = SubscriptionPlan.find(plan_id)
|
132
|
+
comp(plan.duration_quantity, plan.duration_units, plan.feature_level)
|
129
133
|
end
|
130
134
|
end
|
131
135
|
|
132
136
|
class SubscriptionPlan < Resource
|
137
|
+
self.attributes = {
|
138
|
+
:plan_type => proc{'regular'},
|
139
|
+
:feature_level => proc{''}
|
140
|
+
}
|
141
|
+
|
133
142
|
def self.all
|
134
143
|
plans.values
|
135
144
|
end
|
@@ -140,9 +149,9 @@ module Spreedly
|
|
140
149
|
|
141
150
|
def self.plans
|
142
151
|
@plans ||= {
|
143
|
-
1 => new(:id => 1, :name => 'Default mock plan'),
|
144
|
-
2 => new(:id => 2, :name => 'Test Free Trial Plan', :plan_type => 'free_trial'),
|
145
|
-
3 => new(:id => 3, :name => 'Test Regular Plan'),
|
152
|
+
1 => new(:id => 1, :name => 'Default mock plan', :duration_quantity => 1, :duration_units => 'days'),
|
153
|
+
2 => new(:id => 2, :name => 'Test Free Trial Plan', :plan_type => 'free_trial', :duration_quantity => 1, :duration_units => 'days'),
|
154
|
+
3 => new(:id => 3, :name => 'Test Regular Plan', :duration_quantity => 1, :duration_units => 'days'),
|
146
155
|
}
|
147
156
|
end
|
148
157
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
module Spreedly
|
4
|
+
class Subscriber
|
5
|
+
# This method is *strictly* for use when testing, and will
|
6
|
+
# probably only work against a test Spreedly site anyhow.
|
7
|
+
def subscribe(plan_id)
|
8
|
+
agent = WWW::Mechanize.new
|
9
|
+
page = agent.get(Spreedly.subscribe_url(id, plan_id))
|
10
|
+
page = page.forms.first.submit
|
11
|
+
form = page.forms.first
|
12
|
+
form['credit_card[first_name]'] = 'Joe'
|
13
|
+
form['credit_card[last_name]'] = 'Bob'
|
14
|
+
form['subscriber[email]'] = 'joe@example.com'
|
15
|
+
form['credit_card[number]'] = '4222222222222'
|
16
|
+
form['credit_card[card_type]'] = 'visa'
|
17
|
+
form['credit_card[verification_value]'] = '234'
|
18
|
+
form['credit_card[month]'] = '1'
|
19
|
+
form['credit_card[year]'] = '2024'
|
20
|
+
page = form.click_button
|
21
|
+
raise "Subscription didn't got through" unless page.title == "Thank you!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/spreedly/version.rb
CHANGED
data/test/spreedly_gem_test.rb
CHANGED
@@ -34,12 +34,29 @@ class SpreedlyGemTest < Test::Unit::TestCase
|
|
34
34
|
assert subscribers.size == 1
|
35
35
|
assert_equal two.id, subscribers.first.id
|
36
36
|
end
|
37
|
+
|
38
|
+
context "adding a subscriber" do
|
39
|
+
should "generate a token" do
|
40
|
+
subscriber = Spreedly::Subscriber.create!('joe')
|
41
|
+
assert_not_nil subscriber.token
|
42
|
+
assert_equal subscriber.token, Spreedly::Subscriber.find('joe').token
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
should "accept email address as an argument" do
|
46
|
+
subscriber = Spreedly::Subscriber.create!('joe', 'a@b.cd')
|
47
|
+
assert_equal 'a@b.cd', Spreedly::Subscriber.find('joe').email
|
48
|
+
end
|
49
|
+
|
50
|
+
should "accept screen name as an argument" do
|
51
|
+
subscriber = Spreedly::Subscriber.create!('joe', 'a@b.cd', 'tuna')
|
52
|
+
assert_equal 'tuna', Spreedly::Subscriber.find('joe').screen_name
|
53
|
+
end
|
54
|
+
|
55
|
+
should "accept optional arguments: like billing first name" do
|
56
|
+
subscriber = Spreedly::Subscriber.create!('joe', {:billing_first_name => 'Joe'})
|
57
|
+
assert_equal 'Joe', Spreedly::Subscriber.find('joe').billing_first_name
|
58
|
+
end
|
59
|
+
end # adding a subscriber
|
43
60
|
|
44
61
|
should "get a subscriber" do
|
45
62
|
id = create_subscriber.id
|
@@ -71,7 +88,7 @@ class SpreedlyGemTest < Test::Unit::TestCase
|
|
71
88
|
ex = assert_raise(RuntimeError) do
|
72
89
|
create_subscriber('')
|
73
90
|
end
|
74
|
-
assert_match(/
|
91
|
+
assert_match(/customer id can't be blank/i, ex.message)
|
75
92
|
end
|
76
93
|
|
77
94
|
should "create with additional params" do
|
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.3.
|
4
|
+
version: 1.3.1
|
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-09-11 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,9 +40,11 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 2.3.3
|
44
44
|
version:
|
45
|
-
description:
|
45
|
+
description: |-
|
46
|
+
The Spreedly gem provides a convenient Ruby wrapper for the goodness that is
|
47
|
+
the http://spreedly.com API. Created by Terralien[http://terralien.com].
|
46
48
|
email:
|
47
49
|
- nathaniel@terralien.com
|
48
50
|
executables: []
|
@@ -62,6 +64,7 @@ files:
|
|
62
64
|
- lib/spreedly.rb
|
63
65
|
- lib/spreedly/common.rb
|
64
66
|
- lib/spreedly/mock.rb
|
67
|
+
- lib/spreedly/test_hacks.rb
|
65
68
|
- lib/spreedly/version.rb
|
66
69
|
- test/spreedly_gem_test.rb
|
67
70
|
- test/test_site.yml
|
@@ -122,7 +125,9 @@ files:
|
|
122
125
|
- vendor/httparty/website/css/common.css
|
123
126
|
- vendor/httparty/website/index.html
|
124
127
|
has_rdoc: true
|
125
|
-
homepage:
|
128
|
+
homepage: http://terralien.com/static/projects/spreedly-gem/
|
129
|
+
licenses: []
|
130
|
+
|
126
131
|
post_install_message:
|
127
132
|
rdoc_options:
|
128
133
|
- --main
|
@@ -144,9 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
149
|
requirements: []
|
145
150
|
|
146
151
|
rubyforge_project: terralien
|
147
|
-
rubygems_version: 1.3.
|
152
|
+
rubygems_version: 1.3.5
|
148
153
|
signing_key:
|
149
|
-
specification_version:
|
154
|
+
specification_version: 3
|
150
155
|
summary: The Spreedly gem provides a convenient Ruby wrapper for the goodness that is the http://spreedly.com API
|
151
156
|
test_files:
|
152
157
|
- test/spreedly_gem_test.rb
|