newslettre 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/list.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:27:06 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '[]'
24
+ http_version: '1.1'
@@ -0,0 +1,118 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/identity/add.json?address=Oranienstra%C3%9Fe%206&api_key=<<PASSWORD>>&api_user=<<USERNAME>>&city=Berlin&country=DE&email=<<USERNAME>>&identity=test-identity&name=Mathias%20Fiedler&state=B&zip=10997
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:27:07 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '{"message": "success"}'
24
+ http_version: '1.1'
25
+ - !ruby/struct:VCR::HTTPInteraction
26
+ request: !ruby/struct:VCR::Request
27
+ method: :post
28
+ uri: https://sendgrid.com:443/api/newsletter/add.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&html=%3Chtml%3E%3Cbody%3E%3Ch1%3EA%20rendered%20Headline%3C/h1%3E%3C/body%3E%3C/html%3E&identity=test-identity&name=test&subject=A%20letter%20to%20the%20world!&text=An%20unrendered%20Headline
29
+ body: !!null
30
+ headers: !!null
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: OK
35
+ headers:
36
+ server:
37
+ - nginx/0.7.65
38
+ date:
39
+ - Tue, 20 Sep 2011 14:27:08 GMT
40
+ content-type:
41
+ - text/html
42
+ transfer-encoding:
43
+ - chunked
44
+ connection:
45
+ - keep-alive
46
+ body: ! '{"message": "success"}'
47
+ http_version: '1.1'
48
+ - !ruby/struct:VCR::HTTPInteraction
49
+ request: !ruby/struct:VCR::Request
50
+ method: :post
51
+ uri: https://sendgrid.com:443/api/newsletter/get.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&name=test
52
+ body: !!null
53
+ headers: !!null
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ server:
60
+ - nginx/0.7.65
61
+ date:
62
+ - Tue, 20 Sep 2011 14:27:09 GMT
63
+ content-type:
64
+ - text/html
65
+ transfer-encoding:
66
+ - chunked
67
+ connection:
68
+ - keep-alive
69
+ body: ! '{"name": "test", "text": "An unrendered Headline", "html": "<html><body><h1>A
70
+ rendered Headline</h1></body></html>", "identity": "test-identity", "subject":
71
+ "A letter to the world!"}'
72
+ http_version: '1.1'
73
+ - !ruby/struct:VCR::HTTPInteraction
74
+ request: !ruby/struct:VCR::Request
75
+ method: :post
76
+ uri: https://sendgrid.com:443/api/newsletter/identity/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&identity=test-identity
77
+ body: !!null
78
+ headers: !!null
79
+ response: !ruby/struct:VCR::Response
80
+ status: !ruby/struct:VCR::ResponseStatus
81
+ code: 200
82
+ message: OK
83
+ headers:
84
+ server:
85
+ - nginx/0.7.65
86
+ date:
87
+ - Tue, 20 Sep 2011 14:27:10 GMT
88
+ content-type:
89
+ - text/html
90
+ transfer-encoding:
91
+ - chunked
92
+ connection:
93
+ - keep-alive
94
+ body: ! '{"message": "success"}'
95
+ http_version: '1.1'
96
+ - !ruby/struct:VCR::HTTPInteraction
97
+ request: !ruby/struct:VCR::Request
98
+ method: :post
99
+ uri: https://sendgrid.com:443/api/newsletter/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&name=test
100
+ body: !!null
101
+ headers: !!null
102
+ response: !ruby/struct:VCR::Response
103
+ status: !ruby/struct:VCR::ResponseStatus
104
+ code: 200
105
+ message: OK
106
+ headers:
107
+ server:
108
+ - nginx/0.7.65
109
+ date:
110
+ - Tue, 20 Sep 2011 14:27:11 GMT
111
+ content-type:
112
+ - text/html
113
+ transfer-encoding:
114
+ - chunked
115
+ connection:
116
+ - keep-alive
117
+ body: ! '{"message": "success"}'
118
+ http_version: '1.1'
@@ -0,0 +1,24 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/lists/get.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:26:58 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '[{"list": "testuser"}]'
24
+ http_version: '1.1'
@@ -0,0 +1,70 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/lists/add.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:26:59 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '{"message": "success"}'
24
+ http_version: '1.1'
25
+ - !ruby/struct:VCR::HTTPInteraction
26
+ request: !ruby/struct:VCR::Request
27
+ method: :post
28
+ uri: https://sendgrid.com:443/api/newsletter/lists/get.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
29
+ body: !!null
30
+ headers: !!null
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: OK
35
+ headers:
36
+ server:
37
+ - nginx/0.7.65
38
+ date:
39
+ - Tue, 20 Sep 2011 14:27:00 GMT
40
+ content-type:
41
+ - text/html
42
+ transfer-encoding:
43
+ - chunked
44
+ connection:
45
+ - keep-alive
46
+ body: ! '[{"list": "test-list"}]'
47
+ http_version: '1.1'
48
+ - !ruby/struct:VCR::HTTPInteraction
49
+ request: !ruby/struct:VCR::Request
50
+ method: :post
51
+ uri: https://sendgrid.com:443/api/newsletter/lists/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
52
+ body: !!null
53
+ headers: !!null
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ server:
60
+ - nginx/0.7.65
61
+ date:
62
+ - Tue, 20 Sep 2011 14:27:01 GMT
63
+ content-type:
64
+ - text/html
65
+ transfer-encoding:
66
+ - chunked
67
+ connection:
68
+ - keep-alive
69
+ body: ! '{"message": "success"}'
70
+ http_version: '1.1'
@@ -0,0 +1,117 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/lists/add.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:27:02 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '{"message": "success"}'
24
+ http_version: '1.1'
25
+ - !ruby/struct:VCR::HTTPInteraction
26
+ request: !ruby/struct:VCR::Request
27
+ method: :post
28
+ uri: https://sendgrid.com:443/api/newsletter/lists/email/add.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list&data%5B0%5D=%7B%22email%22:%22me@lmaa.name%22,%22name%22:%22Lennart%20Melzer%22%7D&data%5B1%5D=%7B%22email%22:%22<<USERNAME>>%22,%22name%22:%22Mathias%20Fiedler%22%7D
29
+ body: !!null
30
+ headers: !!null
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: OK
35
+ headers:
36
+ server:
37
+ - nginx/0.7.65
38
+ date:
39
+ - Tue, 20 Sep 2011 14:27:03 GMT
40
+ content-type:
41
+ - text/html
42
+ transfer-encoding:
43
+ - chunked
44
+ connection:
45
+ - keep-alive
46
+ body: ! '{"inserted": 2}'
47
+ http_version: '1.1'
48
+ - !ruby/struct:VCR::HTTPInteraction
49
+ request: !ruby/struct:VCR::Request
50
+ method: :post
51
+ uri: https://sendgrid.com:443/api/newsletter/lists/email/get.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
52
+ body: !!null
53
+ headers: !!null
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ server:
60
+ - nginx/0.7.65
61
+ date:
62
+ - Tue, 20 Sep 2011 14:27:04 GMT
63
+ content-type:
64
+ - text/html
65
+ transfer-encoding:
66
+ - chunked
67
+ connection:
68
+ - keep-alive
69
+ body: ! '[{"email": "<<USERNAME>>", "name": "Mathias Fiedler"},{"email": "me@lmaa.name",
70
+ "name": "Lennart Melzer"}]'
71
+ http_version: '1.1'
72
+ - !ruby/struct:VCR::HTTPInteraction
73
+ request: !ruby/struct:VCR::Request
74
+ method: :post
75
+ uri: https://sendgrid.com:443/api/newsletter/lists/email/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list&email%5B0%5D=me@lmaa.name&email%5B1%5D=<<USERNAME>>
76
+ body: !!null
77
+ headers: !!null
78
+ response: !ruby/struct:VCR::Response
79
+ status: !ruby/struct:VCR::ResponseStatus
80
+ code: 200
81
+ message: OK
82
+ headers:
83
+ server:
84
+ - nginx/0.7.65
85
+ date:
86
+ - Tue, 20 Sep 2011 14:27:05 GMT
87
+ content-type:
88
+ - text/html
89
+ transfer-encoding:
90
+ - chunked
91
+ connection:
92
+ - keep-alive
93
+ body: ! '{"removed": 2}'
94
+ http_version: '1.1'
95
+ - !ruby/struct:VCR::HTTPInteraction
96
+ request: !ruby/struct:VCR::Request
97
+ method: :post
98
+ uri: https://sendgrid.com:443/api/newsletter/lists/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&list=test-list
99
+ body: !!null
100
+ headers: !!null
101
+ response: !ruby/struct:VCR::Response
102
+ status: !ruby/struct:VCR::ResponseStatus
103
+ code: 200
104
+ message: OK
105
+ headers:
106
+ server:
107
+ - nginx/0.7.65
108
+ date:
109
+ - Tue, 20 Sep 2011 14:27:06 GMT
110
+ content-type:
111
+ - text/html
112
+ transfer-encoding:
113
+ - chunked
114
+ connection:
115
+ - keep-alive
116
+ body: ! '{"message": "success"}'
117
+ http_version: '1.1'
@@ -0,0 +1,24 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/list.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:22:17 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '[]'
24
+ http_version: '1.1'
@@ -0,0 +1,25 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: https://sendgrid.com:443/api/newsletter/delete.json?api_key=<<PASSWORD>>&api_user=<<USERNAME>>&name=A%20Newsletter%20that%20will%20_hopefully_%20never,%20ever%20exist!
6
+ body: !!null
7
+ headers: !!null
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 401
11
+ message: Unauthorized
12
+ headers:
13
+ server:
14
+ - nginx/0.7.65
15
+ date:
16
+ - Tue, 20 Sep 2011 14:29:48 GMT
17
+ content-type:
18
+ - text/html
19
+ transfer-encoding:
20
+ - chunked
21
+ connection:
22
+ - keep-alive
23
+ body: ! '{"error": "A Newsletter that will _hopefully_ never, ever exist! does
24
+ not exist"}'
25
+ http_version: '1.1'
@@ -0,0 +1,174 @@
1
+ describe Newslettre do
2
+ before :each do
3
+ @client = Newslettre::Client.new :email => NEWSLETTRE_CONFIG['sendgrid']['username'],
4
+ :password => NEWSLETTRE_CONFIG['sendgrid']['password']
5
+ end
6
+
7
+ describe "#initialize" do
8
+ it "should accept an email and password" do
9
+ @client.should be_kind_of(Newslettre::Client)
10
+ end
11
+
12
+ it "should set email" do
13
+ @client.email.should == NEWSLETTRE_CONFIG['sendgrid']['username']
14
+ end
15
+
16
+ it "should set password" do
17
+ @client.password.should == NEWSLETTRE_CONFIG['sendgrid']['password']
18
+ end
19
+
20
+ it "should target `https://sendgrid.com/api/newsletter/`" do
21
+ @client.url.should == "https://sendgrid.com/api/newsletter"
22
+ end
23
+ end
24
+
25
+ describe "http actions" do
26
+ use_vcr_cassette
27
+
28
+ it "should auth requests" do
29
+ @client.list
30
+ end
31
+
32
+ it "should raise NotFound on missing resource" do
33
+ lambda {
34
+ VCR.use_cassette('upon raising errors') do
35
+ @client.delete :name => "A Newsletter that will _hopefully_ never, ever exist!"
36
+ end
37
+ }.should raise_error(Newslettre::Client::ClientFailure)
38
+ end
39
+ end
40
+
41
+ describe "#newsletters" do
42
+ it "should be a list" do
43
+ pending {
44
+ @client.newsletters.should be_respond_to(:<<)
45
+ }
46
+ end
47
+ end
48
+
49
+ describe Newslettre::Identity do
50
+ use_vcr_cassette
51
+
52
+ before :each do
53
+ @identity = Newslettre::Identity.new @client
54
+ end
55
+
56
+ it "should list zero identities" do
57
+ @identity.list.each do |i|
58
+ i["identity"].should_not == "test-identity"
59
+ end
60
+ end
61
+
62
+ context "with a new identity" do
63
+ use_vcr_cassette
64
+ before :each do
65
+ @identity.add "test-identity", NEWSLETTRE_CONFIG['identity']
66
+ end
67
+
68
+ after :each do
69
+ @identity.delete "test-identity"
70
+ end
71
+
72
+ it "should create a test-identity" do
73
+ id = @identity.get "test-identity"
74
+ id.should == NEWSLETTRE_CONFIG['identity'].merge("identity" => "test-identity")
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ describe Newslettre::Lists do
81
+ use_vcr_cassette
82
+
83
+ before :each do
84
+ @lists = Newslettre::Lists.new @client
85
+ end
86
+
87
+ it "should list zero test lists" do
88
+ @lists.list.each do |l|
89
+ l["list"].should_not == "test-list"
90
+ end
91
+ end
92
+
93
+ context "with a new list" do
94
+ use_vcr_cassette
95
+
96
+ before(:each) { @lists.add('test-list') }
97
+
98
+ after(:each) { @lists.delete('test-list') }
99
+
100
+ it "should create a new list for recipients" do
101
+ list = @lists.get "test-list"
102
+
103
+ list.should == {"list" => "test-list"}
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ describe Newslettre::Lists::Email do
110
+ use_vcr_cassette
111
+
112
+ before :each do
113
+ @lists = Newslettre::Lists.new @client
114
+ @lists.add('test-list')
115
+
116
+ @emails = Newslettre::Lists::Email.new 'test-list', @client
117
+
118
+ @emails.add *NEWSLETTRE_CONFIG['emails']
119
+ end
120
+
121
+ after :each do
122
+ @emails.delete *(NEWSLETTRE_CONFIG['emails'].map{|r| r['email'] })
123
+ @lists.delete 'test-list'
124
+ end
125
+
126
+ it "should add two emails to list" do
127
+ emails = @emails.get
128
+ emails.should =~ NEWSLETTRE_CONFIG['emails']
129
+ end
130
+
131
+ end
132
+
133
+ describe Newslettre::Letter do
134
+ use_vcr_cassette
135
+
136
+ before :each do
137
+ @newsletter = Newslettre::Letter.new @client
138
+ end
139
+
140
+ it "should have a client" do
141
+ @newsletter.client.should == @client
142
+ end
143
+
144
+ it "should list zero test letters" do
145
+ @newsletter.list.each do |l|
146
+ l["name"].should_not == "test"
147
+ end
148
+ end
149
+
150
+ context "with a new letter" do
151
+ use_vcr_cassette
152
+
153
+ before :each do
154
+ @identity = Newslettre::Identity.new @client
155
+ @identity.add "test-identity", NEWSLETTRE_CONFIG['identity']
156
+
157
+ @newsletter.add 'test', NEWSLETTRE_CONFIG['letter']
158
+ end
159
+
160
+ after :each do
161
+ @identity.delete "test-identity"
162
+ @newsletter.delete "test"
163
+ end
164
+
165
+ it "should create a newsletter" do
166
+ news = @newsletter.get "test"
167
+
168
+ news.should == NEWSLETTRE_CONFIG['letter'].merge("name" => 'test')
169
+ end
170
+ end
171
+
172
+ end
173
+
174
+ end