streamsend 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +33 -0
- data/Rakefile +2 -14
- data/lib/streamsend/resource.rb +19 -0
- data/lib/streamsend/subscriber.rb +70 -0
- data/lib/streamsend/version.rb +3 -0
- data/lib/streamsend.rb +4 -83
- data/spec/lib/streamsend/resource_spec.rb +21 -0
- data/spec/lib/streamsend/subscriber_spec.rb +229 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/streamsend_spec.rb +6 -211
- data/streamsend.gemspec +17 -24
- metadata +73 -27
- data/Manifest +0 -5
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
streamsend (0.1.1)
|
5
|
+
httparty (= 0.7.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.2.7)
|
11
|
+
crack (0.1.8)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
httparty (0.7.4)
|
14
|
+
crack (= 0.1.8)
|
15
|
+
rspec (2.9.0)
|
16
|
+
rspec-core (~> 2.9.0)
|
17
|
+
rspec-expectations (~> 2.9.0)
|
18
|
+
rspec-mocks (~> 2.9.0)
|
19
|
+
rspec-core (2.9.0)
|
20
|
+
rspec-expectations (2.9.0)
|
21
|
+
diff-lcs (~> 1.1.3)
|
22
|
+
rspec-mocks (2.9.0)
|
23
|
+
webmock (1.8.4)
|
24
|
+
addressable (>= 2.2.7)
|
25
|
+
crack (>= 0.1.7)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
rspec (~> 2.5)
|
32
|
+
streamsend!
|
33
|
+
webmock (~> 1.6)
|
data/Rakefile
CHANGED
@@ -1,14 +1,2 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'echoe'
|
4
|
-
|
5
|
-
Echoe.new('streamsend', '0.1.0') do |p|
|
6
|
-
p.description = "Ruby wrapper for the StreamSend API."
|
7
|
-
p.url = "http://github.com/salbertson/streamsend-ruby"
|
8
|
-
p.author = "Scott Albertson"
|
9
|
-
p.email = "salbertson@streamsend.com"
|
10
|
-
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
p.development_dependencies = []
|
12
|
-
end
|
13
|
-
|
14
|
-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module StreamSend
|
2
|
+
class Resource
|
3
|
+
def initialize(data)
|
4
|
+
@data = data
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
if @data.include?(method.to_s)
|
9
|
+
@data[method.to_s]
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
@data["id"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module StreamSend
|
2
|
+
class Subscriber < Resource
|
3
|
+
def self.audience_id
|
4
|
+
@audience_id ||= StreamSend.get("/audiences.xml").parsed_response["audiences"].first["id"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
response = StreamSend.get("/audiences/#{audience_id}/people.xml")
|
9
|
+
|
10
|
+
case response.code
|
11
|
+
when 200
|
12
|
+
response["people"].collect { |data| new(data) }
|
13
|
+
else
|
14
|
+
raise "Could not find any subscribers. Make sure your audience ID is correct. (#{response.code})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(email_address)
|
19
|
+
response = StreamSend.get("/audiences/#{audience_id}/people.xml?email_address=#{email_address}")
|
20
|
+
|
21
|
+
case response.code
|
22
|
+
when 200
|
23
|
+
if subscriber = response["people"].first
|
24
|
+
new(subscriber)
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
else
|
29
|
+
raise "Could not find the subscriber. Make sure your audience ID is correct. (#{response.code})"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
response = StreamSend.get("/audiences/#{audience_id}/people/#{id}.xml")
|
35
|
+
|
36
|
+
case response.code
|
37
|
+
when 200
|
38
|
+
if subscriber = response["person"]
|
39
|
+
self.class.new(subscriber)
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
else
|
44
|
+
raise "Could not show the subscriber. (#{response.code})"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def activate
|
49
|
+
response = StreamSend.post("/audiences/#{audience_id}/people/#{id}/activate.xml")
|
50
|
+
|
51
|
+
case response.code
|
52
|
+
when 200
|
53
|
+
true
|
54
|
+
else
|
55
|
+
raise "Could not activate the subscriber. (#{response.code})"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def unsubscribe
|
60
|
+
response = StreamSend.post("/audiences/#{audience_id}/people/#{id}/unsubscribe.xml")
|
61
|
+
|
62
|
+
case response.code
|
63
|
+
when 200
|
64
|
+
true
|
65
|
+
else
|
66
|
+
raise "Could not subscribe the subscriber. (#{response.code})"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/streamsend.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'httparty'
|
3
3
|
|
4
|
+
require "streamsend/resource"
|
5
|
+
require "streamsend/subscriber"
|
6
|
+
require "streamsend/version"
|
7
|
+
|
4
8
|
module StreamSend
|
5
9
|
include HTTParty
|
6
10
|
format :xml
|
@@ -9,87 +13,4 @@ module StreamSend
|
|
9
13
|
base_uri host
|
10
14
|
basic_auth username, password
|
11
15
|
end
|
12
|
-
|
13
|
-
class Resource
|
14
|
-
def initialize(data)
|
15
|
-
@data = data
|
16
|
-
end
|
17
|
-
|
18
|
-
def method_missing(method, *args, &block)
|
19
|
-
if @data.include?(method.to_s)
|
20
|
-
@data[method.to_s]
|
21
|
-
else
|
22
|
-
super
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def id
|
27
|
-
@data["id"]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Subscriber < Resource
|
32
|
-
def self.all(audience_id)
|
33
|
-
response = StreamSend.get("/audiences/#{audience_id}/people.xml")
|
34
|
-
|
35
|
-
case response.code
|
36
|
-
when 200
|
37
|
-
response["people"].collect { |data| new(data) }
|
38
|
-
else
|
39
|
-
raise "Could not find any subscribers. Make sure your audience ID is correct. (#{response.code})"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.find(audience_id, email_address)
|
44
|
-
response = StreamSend.get("/audiences/#{audience_id}/people.xml?email_address=#{email_address}")
|
45
|
-
|
46
|
-
case response.code
|
47
|
-
when 200
|
48
|
-
if subscriber = response["people"].first
|
49
|
-
new(subscriber)
|
50
|
-
else
|
51
|
-
nil
|
52
|
-
end
|
53
|
-
else
|
54
|
-
raise "Could not find the subscriber. Make sure your audience ID is correct. (#{response.code})"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def show
|
59
|
-
response = StreamSend.get("/audiences/#{audience_id}/people/#{id}.xml")
|
60
|
-
|
61
|
-
case response.code
|
62
|
-
when 200
|
63
|
-
if subscriber = response["person"]
|
64
|
-
self.class.new(subscriber)
|
65
|
-
else
|
66
|
-
nil
|
67
|
-
end
|
68
|
-
else
|
69
|
-
raise "Could not show the subscriber. (#{response.code})"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def activate
|
74
|
-
response = StreamSend.post("/audiences/#{audience_id}/people/#{id}/activate.xml")
|
75
|
-
|
76
|
-
case response.code
|
77
|
-
when 200
|
78
|
-
true
|
79
|
-
else
|
80
|
-
raise "Could not activate the subscriber. (#{response.code})"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def unsubscribe
|
85
|
-
response = StreamSend.post("/audiences/#{audience_id}/people/#{id}/unsubscribe.xml")
|
86
|
-
|
87
|
-
case response.code
|
88
|
-
when 200
|
89
|
-
true
|
90
|
-
else
|
91
|
-
raise "Could not subscribe the subscriber. (#{response.code})"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
16
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../../spec_helper")
|
2
|
+
|
3
|
+
module StreamSend
|
4
|
+
describe "Resource" do
|
5
|
+
describe "with missing method" do
|
6
|
+
before(:each) do
|
7
|
+
@resource = StreamSend::Resource.new({"name" => "scott"})
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return value" do
|
11
|
+
@resource.name.should == "scott"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#id" do
|
16
|
+
it "should return id" do
|
17
|
+
StreamSend::Resource.new({"id" => 99}).id.should == 99
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../../spec_helper")
|
2
|
+
|
3
|
+
module StreamSend
|
4
|
+
describe "Subscriber" do
|
5
|
+
before(:each) do
|
6
|
+
stub_http_request(:any, //).to_return(:body => "Page not found.", :status => 404)
|
7
|
+
|
8
|
+
@username = "scott"
|
9
|
+
@password = "topsecret"
|
10
|
+
@host = "test.host"
|
11
|
+
|
12
|
+
xml = <<-XML
|
13
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
14
|
+
<audiences type="array">
|
15
|
+
<audience>
|
16
|
+
<id type="integer">2</id>
|
17
|
+
</audience>
|
18
|
+
</audiences>
|
19
|
+
XML
|
20
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences.xml").to_return(:body => xml)
|
21
|
+
|
22
|
+
StreamSend.configure(@username, @password, @host)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".audience_id" do
|
26
|
+
it "should return the id of the first audience" do
|
27
|
+
StreamSend::Subscriber.audience_id.should == 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".all" do
|
32
|
+
describe "with subscribers" do
|
33
|
+
before(:each) do
|
34
|
+
xml = <<-XML
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<people type="array">
|
37
|
+
<person>
|
38
|
+
<id type="integer">2</id>
|
39
|
+
<email-address>scott@gmail.com</email-address>
|
40
|
+
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
41
|
+
</person>
|
42
|
+
</people>
|
43
|
+
XML
|
44
|
+
|
45
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml").to_return(:body => xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return array of one subscriber object" do
|
49
|
+
subscribers = StreamSend::Subscriber.all
|
50
|
+
subscribers.size.should == 1
|
51
|
+
|
52
|
+
subscribers.first.should be_instance_of(StreamSend::Subscriber)
|
53
|
+
subscribers.first.id.should == 2
|
54
|
+
subscribers.first.email_address.should == "scott@gmail.com"
|
55
|
+
subscribers.first.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with no subscribers" do
|
60
|
+
before(:each) do
|
61
|
+
xml = <<-XML
|
62
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
63
|
+
<people type="array"/>
|
64
|
+
XML
|
65
|
+
|
66
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml").to_return(:body => xml)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return an empty array" do
|
70
|
+
StreamSend::Subscriber.all.should == []
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "with invalid audience" do
|
75
|
+
before(:each) do
|
76
|
+
xml = <<-XML
|
77
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
78
|
+
<people type="array"/>
|
79
|
+
XML
|
80
|
+
|
81
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/99/people.xml").to_return(:body => xml)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise an exception" do
|
85
|
+
lambda { StreamSend::Subscriber.all }.should raise_error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".find" do
|
91
|
+
describe "with matching subscriber" do
|
92
|
+
before(:each) do
|
93
|
+
xml = <<-XML
|
94
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
95
|
+
<people type="array">
|
96
|
+
<person>
|
97
|
+
<id type="integer">2</id>
|
98
|
+
<email-address>scott@gmail.com</email-address>
|
99
|
+
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
100
|
+
</person>
|
101
|
+
</people>
|
102
|
+
XML
|
103
|
+
|
104
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml?email_address=scott@gmail.com").to_return(:body => xml)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return subscriber" do
|
108
|
+
subscriber = StreamSend::Subscriber.find("scott@gmail.com")
|
109
|
+
|
110
|
+
subscriber.should be_instance_of(StreamSend::Subscriber)
|
111
|
+
subscriber.id.should == 2
|
112
|
+
subscriber.email_address.should == "scott@gmail.com"
|
113
|
+
subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "with no matching subscriber" do
|
118
|
+
before(:each) do
|
119
|
+
xml = <<-XML
|
120
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
121
|
+
<people type="array"\>
|
122
|
+
XML
|
123
|
+
|
124
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/2/people.xml?email_address=bad.email@gmail.com").to_return(:body => xml)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return nil" do
|
128
|
+
StreamSend::Subscriber.find("bad.email@gmail.com").should == nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "with invalid audience" do
|
133
|
+
before(:each) do
|
134
|
+
xml = <<-XML
|
135
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
136
|
+
<people type="array"\>
|
137
|
+
XML
|
138
|
+
|
139
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/99/people.xml?email_address=bad.email@gmail.com").to_return(:body => xml)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should raise an exception" do
|
143
|
+
lambda { StreamSend::Subscriber.find("scott@gmail.com") }.should raise_error
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#show" do
|
149
|
+
describe "with valid subscriber instance" do
|
150
|
+
before(:each) do
|
151
|
+
xml = <<-XML
|
152
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
153
|
+
<person>
|
154
|
+
<id type="integer">2</id>
|
155
|
+
<email-address>scott@gmail.com</email-address>
|
156
|
+
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
157
|
+
<first-name>Scott</first-name>
|
158
|
+
<last-name>Albertson</last-name>
|
159
|
+
</person>
|
160
|
+
XML
|
161
|
+
|
162
|
+
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2.xml").to_return(:body => xml)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should return subscriber" do
|
166
|
+
subscriber = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).show
|
167
|
+
|
168
|
+
subscriber.should be_instance_of(StreamSend::Subscriber)
|
169
|
+
subscriber.id.should == 2
|
170
|
+
subscriber.email_address.should == "scott@gmail.com"
|
171
|
+
subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
172
|
+
subscriber.first_name.should == "Scott"
|
173
|
+
subscriber.last_name.should == "Albertson"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "with invalid subscriber instance" do
|
178
|
+
it "should raise exception" do
|
179
|
+
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).show }.should raise_error
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "with invalid audience" do
|
184
|
+
it "should raise exception" do
|
185
|
+
lambda { StreamSend::Subscriber.new({"id" => 2}).show }.should raise_error
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#activate" do
|
191
|
+
before(:each) do
|
192
|
+
stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/activate.xml").to_return(:body => nil)
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "with valid subscriber" do
|
196
|
+
it "should be successful" do
|
197
|
+
response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).activate
|
198
|
+
response.should be_true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "with invalid subscriber" do
|
203
|
+
it "should raise exception" do
|
204
|
+
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).activate }.should raise_error
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#unsubscribe" do
|
210
|
+
before(:each) do
|
211
|
+
stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/unsubscribe.xml").to_return(:body => nil)
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "with valid subscriber" do
|
215
|
+
it "should be successful" do
|
216
|
+
response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).unsubscribe
|
217
|
+
response.should be_true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "with invalid subscriber" do
|
222
|
+
it "should raise exception" do
|
223
|
+
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).unsubscribe }.should raise_error
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
data/spec/spec_helper.rb
ADDED
data/spec/streamsend_spec.rb
CHANGED
@@ -1,214 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require 'webmock/rspec'
|
3
|
-
require 'streamsend'
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
4
2
|
|
5
|
-
describe
|
6
|
-
describe "
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return value" do
|
13
|
-
@resource.name.should == "scott"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#id" do
|
18
|
-
it "should return id" do
|
19
|
-
StreamSend::Resource.new({"id" => 99}).id.should == 99
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "Subscriber" do
|
25
|
-
before(:each) do
|
26
|
-
stub_http_request(:any, //).to_return(:body => "Page not found.", :status => 404)
|
27
|
-
|
28
|
-
@username = "scott"
|
29
|
-
@password = "topsecret"
|
30
|
-
@host = "test.host"
|
31
|
-
|
32
|
-
StreamSend.configure(@username, @password, @host)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".all" do
|
36
|
-
describe "with subscribers" do
|
37
|
-
before(:each) do
|
38
|
-
xml = <<-XML
|
39
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
40
|
-
<people type="array">
|
41
|
-
<person>
|
42
|
-
<id type="integer">2</id>
|
43
|
-
<email-address>scott@gmail.com</email-address>
|
44
|
-
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
45
|
-
</person>
|
46
|
-
</people>
|
47
|
-
XML
|
48
|
-
|
49
|
-
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people.xml").to_return(:body => xml)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return array of one subscriber object" do
|
53
|
-
subscribers = StreamSend::Subscriber.all(1)
|
54
|
-
subscribers.size.should == 1
|
55
|
-
|
56
|
-
subscribers.first.should be_instance_of(StreamSend::Subscriber)
|
57
|
-
subscribers.first.id.should == 2
|
58
|
-
subscribers.first.email_address.should == "scott@gmail.com"
|
59
|
-
subscribers.first.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "with no subscribers" do
|
64
|
-
before(:each) do
|
65
|
-
xml = <<-XML
|
66
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
67
|
-
<people type="array"/>
|
68
|
-
XML
|
69
|
-
|
70
|
-
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people.xml").to_return(:body => xml)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should return an empty array" do
|
74
|
-
StreamSend::Subscriber.all(1).should == []
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "with invalid audience" do
|
79
|
-
it "should raise an exception" do
|
80
|
-
lambda { StreamSend::Subscriber.all(99) }.should raise_error
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe ".find" do
|
86
|
-
describe "with matching subscriber" do
|
87
|
-
before(:each) do
|
88
|
-
xml = <<-XML
|
89
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
90
|
-
<people type="array">
|
91
|
-
<person>
|
92
|
-
<id type="integer">2</id>
|
93
|
-
<email-address>scott@gmail.com</email-address>
|
94
|
-
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
95
|
-
</person>
|
96
|
-
</people>
|
97
|
-
XML
|
98
|
-
|
99
|
-
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people.xml?email_address=scott@gmail.com").to_return(:body => xml)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return subscriber" do
|
103
|
-
subscriber = StreamSend::Subscriber.find(1, "scott@gmail.com")
|
104
|
-
|
105
|
-
subscriber.should be_instance_of(StreamSend::Subscriber)
|
106
|
-
subscriber.id.should == 2
|
107
|
-
subscriber.email_address.should == "scott@gmail.com"
|
108
|
-
subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "with no matching subscriber" do
|
113
|
-
before(:each) do
|
114
|
-
xml = <<-XML
|
115
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
116
|
-
<people type="array"\>
|
117
|
-
XML
|
118
|
-
|
119
|
-
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people.xml?email_address=bad.email@gmail.com").to_return(:body => xml)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should return nil" do
|
123
|
-
StreamSend::Subscriber.find(1, "bad.email@gmail.com").should == nil
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "with invalid audience" do
|
128
|
-
it "should raise an exception" do
|
129
|
-
lambda { StreamSend::Subscriber.find(99, "scott@gmail.com") }.should raise_error
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "#show" do
|
135
|
-
describe "with valid subscriber instance" do
|
136
|
-
before(:each) do
|
137
|
-
xml = <<-XML
|
138
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
139
|
-
<person>
|
140
|
-
<id type="integer">2</id>
|
141
|
-
<email-address>scott@gmail.com</email-address>
|
142
|
-
<created-at type="datetime">2009-09-18T01:27:05Z</created-at>
|
143
|
-
<first-name>Scott</first-name>
|
144
|
-
<last-name>Albertson</last-name>
|
145
|
-
</person>
|
146
|
-
XML
|
147
|
-
|
148
|
-
stub_http_request(:get, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2.xml").to_return(:body => xml)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should return subscriber" do
|
152
|
-
subscriber = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).show
|
153
|
-
|
154
|
-
subscriber.should be_instance_of(StreamSend::Subscriber)
|
155
|
-
subscriber.id.should == 2
|
156
|
-
subscriber.email_address.should == "scott@gmail.com"
|
157
|
-
subscriber.created_at.should == Time.parse("2009-09-18T01:27:05Z")
|
158
|
-
subscriber.first_name.should == "Scott"
|
159
|
-
subscriber.last_name.should == "Albertson"
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "with invalid subscriber instance" do
|
164
|
-
it "should raise exception" do
|
165
|
-
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).show }.should raise_error
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "with invalid audience" do
|
170
|
-
it "should raise exception" do
|
171
|
-
lambda { StreamSend::Subscriber.new({"id" => 2}).show }.should raise_error
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#activate" do
|
177
|
-
before(:each) do
|
178
|
-
stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/activate.xml").to_return(:body => nil)
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "with valid subscriber" do
|
182
|
-
it "should be successful" do
|
183
|
-
response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).activate
|
184
|
-
response.should be_true
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "with invalid subscriber" do
|
189
|
-
it "should raise exception" do
|
190
|
-
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).activate }.should raise_error
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "#unsubscribe" do
|
196
|
-
before(:each) do
|
197
|
-
stub_http_request(:post, "http://#{@username}:#{@password}@#{@host}/audiences/1/people/2/unsubscribe.xml").to_return(:body => nil)
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "with valid subscriber" do
|
201
|
-
it "should be successful" do
|
202
|
-
response = StreamSend::Subscriber.new({"id" => 2, "audience_id" => 1}).unsubscribe
|
203
|
-
response.should be_true
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "with invalid subscriber" do
|
208
|
-
it "should raise exception" do
|
209
|
-
lambda { StreamSend::Subscriber.new({"id" => 99, "audience_id" => 1}).unsubscribe }.should raise_error
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
3
|
+
describe StreamSend do
|
4
|
+
describe ".configure" do
|
5
|
+
it "should set username"
|
6
|
+
it "should set password"
|
7
|
+
it "should set host"
|
213
8
|
end
|
214
9
|
end
|
data/streamsend.gemspec
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/streamsend/version', __FILE__)
|
2
3
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Scott Albertson"]
|
6
|
+
gem.email = %q{salbertson@streamsend.com}
|
7
|
+
gem.summary = %q{Ruby wrapper for the StreamSend API.}
|
8
|
+
gem.description = %q{Ruby wrapper for the StreamSend API.}
|
9
|
+
gem.homepage = %q{http://github.com/salbertson/streamsend-ruby}
|
10
|
+
gem.date = %q{2012-03-27}
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
s.description = %q{Ruby wrapper for the StreamSend API.}
|
11
|
-
s.email = %q{salbertson@streamsend.com}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/streamsend.rb"]
|
13
|
-
s.files = ["README.rdoc", "Rakefile", "lib/streamsend.rb", "spec/streamsend_spec.rb", "Manifest", "streamsend.gemspec"]
|
14
|
-
s.homepage = %q{http://github.com/salbertson/streamsend-ruby}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Streamsend", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{streamsend}
|
18
|
-
s.rubygems_version = %q{1.5.2}
|
19
|
-
s.summary = %q{Ruby wrapper for the StreamSend API.}
|
12
|
+
gem.add_dependency "httparty", "0.7.4"
|
13
|
+
gem.add_development_dependency "rspec", "~> 2.5"
|
14
|
+
gem.add_development_dependency "webmock", "~> 1.6"
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
end
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.name = "streamsend"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = Streamsend::VERSION
|
29
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamsend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Albertson
|
@@ -15,38 +15,82 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
date: 2012-03-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 7
|
32
|
+
- 4
|
33
|
+
version: 0.7.4
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 9
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 5
|
48
|
+
version: "2.5"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: webmock
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 6
|
63
|
+
version: "1.6"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
22
66
|
description: Ruby wrapper for the StreamSend API.
|
23
67
|
email: salbertson@streamsend.com
|
24
68
|
executables: []
|
25
69
|
|
26
70
|
extensions: []
|
27
71
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
30
|
-
- lib/streamsend.rb
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
31
74
|
files:
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
32
77
|
- README.rdoc
|
33
78
|
- Rakefile
|
34
79
|
- lib/streamsend.rb
|
80
|
+
- lib/streamsend/resource.rb
|
81
|
+
- lib/streamsend/subscriber.rb
|
82
|
+
- lib/streamsend/version.rb
|
83
|
+
- spec/lib/streamsend/resource_spec.rb
|
84
|
+
- spec/lib/streamsend/subscriber_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
35
86
|
- spec/streamsend_spec.rb
|
36
|
-
- Manifest
|
37
87
|
- streamsend.gemspec
|
38
|
-
has_rdoc: true
|
39
88
|
homepage: http://github.com/salbertson/streamsend-ruby
|
40
89
|
licenses: []
|
41
90
|
|
42
91
|
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
|
45
|
-
- --inline-source
|
46
|
-
- --title
|
47
|
-
- Streamsend
|
48
|
-
- --main
|
49
|
-
- README.rdoc
|
92
|
+
rdoc_options: []
|
93
|
+
|
50
94
|
require_paths:
|
51
95
|
- lib
|
52
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -63,17 +107,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
107
|
requirements:
|
64
108
|
- - ">="
|
65
109
|
- !ruby/object:Gem::Version
|
66
|
-
hash:
|
110
|
+
hash: 3
|
67
111
|
segments:
|
68
|
-
-
|
69
|
-
|
70
|
-
version: "1.2"
|
112
|
+
- 0
|
113
|
+
version: "0"
|
71
114
|
requirements: []
|
72
115
|
|
73
|
-
rubyforge_project:
|
74
|
-
rubygems_version: 1.
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.7.1
|
75
118
|
signing_key:
|
76
119
|
specification_version: 3
|
77
120
|
summary: Ruby wrapper for the StreamSend API.
|
78
|
-
test_files:
|
79
|
-
|
121
|
+
test_files:
|
122
|
+
- spec/lib/streamsend/resource_spec.rb
|
123
|
+
- spec/lib/streamsend/subscriber_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/streamsend_spec.rb
|