streamsend-ruby 0.0.1.pre1
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/.gitignore +6 -0
- data/Gemfile +5 -0
- data/lib/spec/version.rb +14 -0
- data/lib/streamsend.rb +73 -0
- data/spec/streamsend_spec.rb +176 -0
- data/streamsend-ruby.gemspec +24 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/lib/spec/version.rb
ADDED
data/lib/streamsend.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module StreamSend
|
5
|
+
include HTTParty
|
6
|
+
format :xml
|
7
|
+
|
8
|
+
def self.configure(username, password, host = "app.streamsend.com")
|
9
|
+
base_uri host
|
10
|
+
basic_auth username, password
|
11
|
+
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(audience_id)
|
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
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'streamsend'
|
4
|
+
|
5
|
+
describe "StreamSend" do
|
6
|
+
describe "Resource" do
|
7
|
+
describe "with missing method" do
|
8
|
+
before(:each) do
|
9
|
+
@resource = StreamSend::Resource.new({"name" => "scott"})
|
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}).show(1)
|
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 return nil" do
|
165
|
+
lambda { StreamSend::Subscriber.new({:id => 99}).show(1) }.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(99) }.should raise_error
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "spec/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "streamsend-ruby"
|
8
|
+
s.version = Spec::VERSION::STRING
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Gaslight Software", "salbertson"]
|
11
|
+
s.email = ["gems@gaslightsoftware.com", nil]
|
12
|
+
s.homepage = "http://github.com/gaslightsoftware/streamsend-ruby"
|
13
|
+
s.summary = Spec::VERSION::SUMMARY
|
14
|
+
s.description = "A Ruby wrapper for the Streamsend API"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency("rspec")
|
22
|
+
s.add_development_dependency("webmock")
|
23
|
+
s.add_development_dependency("httparty")
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: streamsend-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1923831971
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- pre
|
11
|
+
- 1
|
12
|
+
version: 0.0.1.pre1
|
13
|
+
platform: ruby
|
14
|
+
authors:
|
15
|
+
- Gaslight Software
|
16
|
+
- salbertson
|
17
|
+
autorequire:
|
18
|
+
bindir: bin
|
19
|
+
cert_chain: []
|
20
|
+
|
21
|
+
date: 2011-07-28 00:00:00 -04:00
|
22
|
+
default_executable:
|
23
|
+
dependencies:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rspec
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
hash: 3
|
33
|
+
segments:
|
34
|
+
- 0
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: webmock
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: httparty
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: A Ruby wrapper for the Streamsend API
|
67
|
+
email:
|
68
|
+
- gems@gaslightsoftware.com
|
69
|
+
-
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files: []
|
75
|
+
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- lib/spec/version.rb
|
80
|
+
- lib/streamsend.rb
|
81
|
+
- spec/streamsend_spec.rb
|
82
|
+
- streamsend-ruby.gemspec
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/gaslightsoftware/streamsend-ruby
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 25
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 3
|
110
|
+
- 1
|
111
|
+
version: 1.3.1
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.4.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: streamsend-ruby 0.0.1.pre1
|
119
|
+
test_files:
|
120
|
+
- spec/streamsend_spec.rb
|