pew_pew 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +22 -0
  6. data/README.md +84 -0
  7. data/Rakefile +3 -0
  8. data/lib/pew_pew.rb +32 -0
  9. data/lib/pew_pew/client.rb +90 -0
  10. data/lib/pew_pew/config.rb +15 -0
  11. data/lib/pew_pew/domain.rb +9 -0
  12. data/lib/pew_pew/resource.rb +52 -0
  13. data/lib/pew_pew/resources/bounces.rb +41 -0
  14. data/lib/pew_pew/resources/campaigns.rb +141 -0
  15. data/lib/pew_pew/resources/complaints.rb +40 -0
  16. data/lib/pew_pew/resources/lists.rb +121 -0
  17. data/lib/pew_pew/resources/logs.rb +12 -0
  18. data/lib/pew_pew/resources/mailboxes.rb +41 -0
  19. data/lib/pew_pew/resources/messages.rb +37 -0
  20. data/lib/pew_pew/resources/routes.rb +57 -0
  21. data/lib/pew_pew/resources/stats.rb +12 -0
  22. data/lib/pew_pew/resources/unsubscribes.rb +43 -0
  23. data/lib/pew_pew/response.rb +11 -0
  24. data/lib/pew_pew/version.rb +3 -0
  25. data/pew_pew.gemspec +20 -0
  26. data/spec/fixtures/bounces.yml +144 -0
  27. data/spec/fixtures/campaigns.yml +368 -0
  28. data/spec/fixtures/complaints.yml +142 -0
  29. data/spec/fixtures/image.png +0 -0
  30. data/spec/fixtures/lists.yml +403 -0
  31. data/spec/fixtures/logs.yml +133 -0
  32. data/spec/fixtures/mailboxes.yml +141 -0
  33. data/spec/fixtures/messages.yml +196 -0
  34. data/spec/fixtures/mime.eml +34 -0
  35. data/spec/fixtures/routes.yml +225 -0
  36. data/spec/fixtures/stats.yml +61 -0
  37. data/spec/fixtures/unsubscribes.yml +219 -0
  38. data/spec/pew_pew/client_spec.rb +51 -0
  39. data/spec/pew_pew/config_spec.rb +38 -0
  40. data/spec/pew_pew/resource_spec.rb +46 -0
  41. data/spec/pew_pew/resources/bounces_spec.rb +78 -0
  42. data/spec/pew_pew/resources/campaigns_spec.rb +228 -0
  43. data/spec/pew_pew/resources/complaints_spec.rb +69 -0
  44. data/spec/pew_pew/resources/lists_spec.rb +283 -0
  45. data/spec/pew_pew/resources/logs_spec.rb +28 -0
  46. data/spec/pew_pew/resources/mailboxes_spec.rb +59 -0
  47. data/spec/pew_pew/resources/messages_spec.rb +53 -0
  48. data/spec/pew_pew/resources/routes_spec.rb +135 -0
  49. data/spec/pew_pew/resources/stats_spec.rb +26 -0
  50. data/spec/pew_pew/resources/unsubscribes_spec.rb +99 -0
  51. data/spec/pew_pew/response_spec.rb +21 -0
  52. data/spec/pew_pew_spec.rb +13 -0
  53. data/spec/spec_helper.rb +17 -0
  54. data/spec/support/contexts/api_requests.rb +23 -0
  55. data/spec/support/contexts/domain_resource.rb +17 -0
  56. data/spec/support/vcr.rb +6 -0
  57. metadata +211 -0
@@ -0,0 +1,228 @@
1
+ require 'spec_helper'
2
+
3
+ describe PewPew::Resources::Campaigns, :resource, :domain do
4
+ let(:resource) { described_class.new(client) }
5
+
6
+ context '#all' do
7
+ let(:response) { resource.all }
8
+
9
+ subject { response }
10
+
11
+ specify { should be_success }
12
+
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 1 }
15
+
16
+ context 'item' do
17
+ subject { response.items.first }
18
+
19
+ its(:bounced_count) { should == 0 }
20
+ its(:clicked_count) { should == 0 }
21
+ its(:complained_count) { should == 0 }
22
+ its(:created_at) { should == 'Sun, 03 Jun 2012 07:36:36 GMT' }
23
+ its(:delivered_count) { should == 0 }
24
+ its(:dropped_count) { should == 0 }
25
+ its(:id) { should == '8ben' }
26
+ its(:name) { should == 'Test' }
27
+ its(:opened_count) { should == 0 }
28
+ its(:submitted_count) { should == 0 }
29
+ its(:unsubscribed_count) { should == 0 }
30
+ end
31
+ end
32
+
33
+ context '#find' do
34
+ let(:response) { resource.find('8ben') }
35
+
36
+ subject { response }
37
+
38
+ specify { should be_success }
39
+
40
+ its(:status) { should == 200 }
41
+
42
+ its(:bounced_count) { should == 0 }
43
+ its(:clicked_count) { should == 0 }
44
+ its(:complained_count) { should == 0 }
45
+ its(:created_at) { should == 'Sun, 03 Jun 2012 07:36:36 GMT' }
46
+ its(:delivered_count) { should == 0 }
47
+ its(:dropped_count) { should == 0 }
48
+ its(:id) { should == '8ben' }
49
+ its(:name) { should == 'Test' }
50
+ its(:opened_count) { should == 0 }
51
+ its(:submitted_count) { should == 0 }
52
+ its(:unsubscribed_count) { should == 0 }
53
+ end
54
+
55
+ context '#create' do
56
+ let(:response) { resource.create(params) }
57
+
58
+ context 'with an ID' do
59
+ let(:params) { { name: 'Test', id: 'test' } }
60
+
61
+ subject { response }
62
+
63
+ specify { should be_success }
64
+
65
+ its(:status) { should == 200 }
66
+ its(:message) { should == 'Campaign created' }
67
+
68
+ context 'campaign' do
69
+ subject { response.campaign }
70
+
71
+ its(:bounced_count) { should == 0 }
72
+ its(:clicked_count) { should == 0 }
73
+ its(:complained_count) { should == 0 }
74
+ its(:created_at) { should == 'Sun, 03 Jun 2012 07:28:25 GMT' }
75
+ its(:delivered_count) { should == 0 }
76
+ its(:dropped_count) { should == 0 }
77
+ its(:id) { should == 'test' }
78
+ its(:name) { should == 'Test' }
79
+ its(:opened_count) { should == 0 }
80
+ its(:submitted_count) { should == 0 }
81
+ its(:unsubscribed_count) { should == 0 }
82
+ end
83
+ end
84
+
85
+ context 'without an ID' do
86
+ let(:params) { { name: 'Test' } }
87
+
88
+ subject { response }
89
+
90
+ specify { should be_success }
91
+
92
+ its(:status) { should == 200 }
93
+ its(:message) { should == 'Campaign created' }
94
+
95
+ context 'campaign' do
96
+ subject { response.campaign }
97
+
98
+ its(:bounced_count) { should == 0 }
99
+ its(:clicked_count) { should == 0 }
100
+ its(:complained_count) { should == 0 }
101
+ its(:created_at) { should == 'Sun, 03 Jun 2012 07:36:36 GMT' }
102
+ its(:delivered_count) { should == 0 }
103
+ its(:dropped_count) { should == 0 }
104
+ its(:id) { should == '8ben' }
105
+ its(:name) { should == 'Test' }
106
+ its(:opened_count) { should == 0 }
107
+ its(:submitted_count) { should == 0 }
108
+ its(:unsubscribed_count) { should == 0 }
109
+ end
110
+ end
111
+ end
112
+
113
+ context '#remove' do
114
+ let(:response) { resource.remove('test') }
115
+
116
+ subject { response }
117
+
118
+ specify { should be_success }
119
+
120
+ its(:status) { should == 200 }
121
+ its(:message) { should == 'Campaign deleted' }
122
+
123
+ its(:id) { should == 'test' }
124
+ end
125
+
126
+ context '#events' do
127
+ let(:response) { resource.events('8ben') }
128
+
129
+ subject { response }
130
+
131
+ specify { should be_success }
132
+
133
+ its(:status) { should == 200 }
134
+ its(:total_count) { should == 0 }
135
+
136
+ its(:items) { should == [] }
137
+ end
138
+
139
+ context '#stats' do
140
+ let(:response) { resource.stats('8ben') }
141
+
142
+ subject { response }
143
+
144
+ specify { should be_success }
145
+
146
+ its(:status) { should == 200 }
147
+
148
+ context 'total' do
149
+ subject { response.total }
150
+
151
+ its(:bounced) { should == 0 }
152
+ its(:clicked) { should == 0 }
153
+ its(:complained) { should == 0 }
154
+ its(:delivered) { should == 0 }
155
+ its(:dropped) { should == 0 }
156
+ its(:opened) { should == 0 }
157
+ its(:sent) { should == 0 }
158
+ its(:unsubscribed) { should == 0 }
159
+ end
160
+
161
+ context 'unique' do
162
+ context 'clicked' do
163
+ subject { response.unique.clicked }
164
+
165
+ its(:link) { should == 0 }
166
+ its(:recipient) { should == 0 }
167
+ end
168
+
169
+ context 'opened' do
170
+ subject { response.unique.opened }
171
+
172
+ its(:recipient) { should == 0 }
173
+ end
174
+ end
175
+ end
176
+
177
+ context '#clicks' do
178
+ let(:response) { resource.clicks('8ben', group_by: 'domain') }
179
+
180
+ subject { response }
181
+
182
+ specify { should be_success }
183
+
184
+ its(:status) { should == 200 }
185
+ its(:total_count) { should == 0 }
186
+
187
+ its(:items) { should == [] }
188
+ end
189
+
190
+ context '#opens' do
191
+ let(:response) { resource.opens('8ben', group_by: 'domain') }
192
+
193
+ subject { response }
194
+
195
+ specify { should be_success }
196
+
197
+ its(:status) { should == 200 }
198
+ its(:total_count) { should == 0 }
199
+
200
+ its(:items) { should == [] }
201
+ end
202
+
203
+ context '#unsubscribes' do
204
+ let(:response) { resource.unsubscribes('8ben', group_by: 'domain') }
205
+
206
+ subject { response }
207
+
208
+ specify { should be_success }
209
+
210
+ its(:status) { should == 200 }
211
+ its(:total_count) { should == 0 }
212
+
213
+ its(:items) { should == [] }
214
+ end
215
+
216
+ context '#complaints' do
217
+ let(:response) { resource.complaints('8ben', group_by: 'domain') }
218
+
219
+ subject { response }
220
+
221
+ specify { should be_success }
222
+
223
+ its(:status) { should == 200 }
224
+ its(:total_count) { should == 0 }
225
+
226
+ its(:items) { should == [] }
227
+ end
228
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe PewPew::Resources::Complaints, :resource, :domain do
4
+ let(:resource) { described_class.new(client) }
5
+
6
+ context '#all' do
7
+ let(:response) { resource.all }
8
+
9
+ subject { response }
10
+
11
+ specify { should be_success }
12
+
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 1 }
15
+
16
+ context 'item' do
17
+ subject { response.items.first }
18
+
19
+ its(:address) { should == 'test@example.com' }
20
+ its(:count) { should == 1 }
21
+ its(:created_at) { should == 'Sat, 02 Jun 2012 06:55:56 GMT' }
22
+ end
23
+ end
24
+
25
+ context '#find' do
26
+ let(:response) { resource.find('test@example.com') }
27
+
28
+ subject { response }
29
+
30
+ specify { should be_success }
31
+
32
+ its(:status) { should == 200 }
33
+
34
+ context 'complaint' do
35
+ subject { response.complaint }
36
+
37
+ its(:address) { should == 'test@example.com' }
38
+ its(:count) { should == 1 }
39
+ its(:created_at) { should == 'Sat, 02 Jun 2012 06:55:56 GMT' }
40
+ end
41
+ end
42
+
43
+ context '#create' do
44
+ let(:params) { { address: 'test@example.com' } }
45
+ let(:response) { resource.create(params) }
46
+
47
+ subject { response }
48
+
49
+ specify { should be_success }
50
+
51
+ its(:status) { should == 200 }
52
+ its(:message) { should == 'Address has been added to the complaints table' }
53
+
54
+ its(:address) { should == 'test@example.com' }
55
+ end
56
+
57
+ context '#remove' do
58
+ subject { response }
59
+
60
+ let(:response) { resource.remove('test@example.com') }
61
+
62
+ specify { should be_success }
63
+
64
+ its(:status) { should == 200 }
65
+ its(:message) { should == 'Spam complaint has been removed' }
66
+
67
+ its(:address) { should == 'test@example.com' }
68
+ end
69
+ end
@@ -0,0 +1,283 @@
1
+ require 'spec_helper'
2
+
3
+ describe PewPew::Resources::Lists, :resource do
4
+ let(:resource) { described_class.new(client) }
5
+
6
+ context '#all' do
7
+ let(:response) { resource.all }
8
+
9
+ subject { response }
10
+
11
+ specify { should be_success }
12
+
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 1 }
15
+
16
+ context 'item' do
17
+ subject { response.items.first }
18
+
19
+ its(:address) { should == 'newsletter@pewpew.mailgun.org' }
20
+ its(:created_at) { should == 'Mon, 04 Jun 2012 16:56:58 GMT' }
21
+ its(:description) { should == 'Weekly News and Updates' }
22
+ its(:members_count) { should == 0 }
23
+ its(:name) { should == 'Newsletter' }
24
+ end
25
+ end
26
+
27
+ context '#find' do
28
+ let(:response) { resource.find('newsletter@pewpew.mailgun.org') }
29
+
30
+ subject { response }
31
+
32
+ specify { should be_success }
33
+
34
+ its(:status) { should == 200 }
35
+
36
+ context 'list' do
37
+ subject { response.list }
38
+
39
+ its(:address) { should == 'newsletter@pewpew.mailgun.org' }
40
+ its(:created_at) { should == 'Mon, 04 Jun 2012 16:56:58 GMT' }
41
+ its(:description) { should == 'Weekly News and Updates' }
42
+ its(:members_count) { should == 0 }
43
+ its(:name) { should == 'Newsletter' }
44
+ end
45
+ end
46
+
47
+ context '#create' do
48
+ let(:params) do
49
+ {
50
+ address: 'newsletter@pewpew.mailgun.org',
51
+ description: 'Weekly News and Updates',
52
+ name: 'Newsletter'
53
+ }
54
+ end
55
+
56
+ let(:response) { resource.create(params) }
57
+
58
+ subject { response }
59
+
60
+ specify { should be_success }
61
+
62
+ its(:status) { should == 200 }
63
+ its(:message) { should == 'Mailing list has been created' }
64
+
65
+ context 'list' do
66
+ subject { response.list }
67
+
68
+ its(:address) { should == 'newsletter@pewpew.mailgun.org' }
69
+ its(:created_at) { should == 'Mon, 04 Jun 2012 16:56:58 GMT' }
70
+ its(:description) { should == 'Weekly News and Updates' }
71
+ its(:members_count) { should == 0 }
72
+ its(:name) { should == 'Newsletter' }
73
+ end
74
+ end
75
+
76
+ context '#update' do
77
+ let(:params) { { description: 'Monthly News and Updates' } }
78
+ let(:response) { resource.update('newsletter@pewpew.mailgun.org', params) }
79
+
80
+ subject { response }
81
+
82
+ specify { should be_success }
83
+
84
+ its(:status) { should == 200 }
85
+ its(:message) { should == 'Mailing list has been updated' }
86
+
87
+ context 'list' do
88
+ subject { response.list }
89
+
90
+ its(:address) { should == 'newsletter@pewpew.mailgun.org' }
91
+ its(:created_at) { should == 'Mon, 04 Jun 2012 16:56:58 GMT' }
92
+ its(:description) { should == 'Monthly News and Updates' }
93
+ its(:members_count) { should == 0 }
94
+ its(:name) { should == 'Newsletter' }
95
+ end
96
+ end
97
+
98
+ context '#remove' do
99
+ let(:response) { resource.remove('newsletter@pewpew.mailgun.org') }
100
+
101
+ subject { response }
102
+
103
+ specify { should be_success }
104
+
105
+ its(:status) { should == 200 }
106
+ its(:message) { should == 'Mailing list has been deleted' }
107
+
108
+ its(:address) { should == 'newsletter@pewpew.mailgun.org' }
109
+ end
110
+
111
+ context '#stats' do
112
+ let(:response) { resource.stats('newsletter@pewpew.mailgun.org') }
113
+
114
+ subject { response }
115
+
116
+ specify { should be_success }
117
+
118
+ its(:status) { should == 200 }
119
+
120
+ context 'total' do
121
+ subject { response.total }
122
+
123
+ its(:bounced) { should == 0 }
124
+ its(:clicked) { should == 0 }
125
+ its(:complained) { should == 0 }
126
+ its(:delivered) { should == 0 }
127
+ its(:dropped) { should == 0 }
128
+ its(:opened) { should == 0 }
129
+ its(:unsubscribed) { should == 0 }
130
+ end
131
+
132
+ context 'unique' do
133
+ context 'clicked' do
134
+ subject { response.unique.clicked }
135
+
136
+ its(:link) { should == 0 }
137
+ its(:recipient) { should == 0 }
138
+ end
139
+
140
+ context 'opened' do
141
+ subject { response.unique.opened }
142
+
143
+ its(:recipient) { should == 0 }
144
+ end
145
+ end
146
+ end
147
+
148
+ context '#all_members' do
149
+ let(:response) do
150
+ resource.all_members('newsletter@pewpew.mailgun.org')
151
+ end
152
+
153
+ subject { response }
154
+
155
+ specify { should be_success }
156
+
157
+ its(:status) { should == 200 }
158
+ its(:total_count) { should == 1 }
159
+
160
+ context 'member' do
161
+ subject { response.items.first }
162
+
163
+ its(:address) { should == 'member@example.com' }
164
+ its(:name) { should == 'Member Name' }
165
+ its(:subscribed) { should be_true }
166
+
167
+ context 'vars' do
168
+ subject { response.items.first.vars }
169
+
170
+ its(:awesome) { should be_true }
171
+ end
172
+ end
173
+ end
174
+
175
+ context '#find_member' do
176
+ let(:response) do
177
+ resource.find_member('newsletter@pewpew.mailgun.org', 'member@example.com')
178
+ end
179
+
180
+ subject { response }
181
+
182
+ specify { should be_success }
183
+
184
+ its(:status) { should == 200 }
185
+
186
+ context 'member' do
187
+ subject { response.member }
188
+
189
+ its(:address) { should == 'member@example.com' }
190
+ its(:name) { should == 'Member Name' }
191
+ its(:subscribed) { should be_true }
192
+
193
+ context 'vars' do
194
+ subject { response.member.vars }
195
+
196
+ its(:awesome) { should be_true }
197
+ end
198
+ end
199
+ end
200
+
201
+ context '#create_member' do
202
+ let(:params) do
203
+ {
204
+ address: 'member@example.com',
205
+ name: 'Member Name',
206
+ vars: { awesome: true },
207
+ }
208
+ end
209
+
210
+ let(:response) do
211
+ resource.create_member('newsletter@pewpew.mailgun.org', params)
212
+ end
213
+
214
+ subject { response }
215
+
216
+ specify { should be_success }
217
+
218
+ its(:status) { should == 200 }
219
+ its(:message) { should == 'Mailing list member has been created' }
220
+
221
+ context 'member' do
222
+ subject { response.member }
223
+
224
+ its(:address) { should == 'member@example.com' }
225
+ its(:name) { should == 'Member Name' }
226
+ its(:subscribed) { should be_true }
227
+
228
+ context 'vars' do
229
+ subject { response.member.vars }
230
+
231
+ its(:awesome) { should be_true }
232
+ end
233
+ end
234
+ end
235
+
236
+ context '#update_member' do
237
+ let(:params) { { subscribed: false } }
238
+
239
+ let(:response) do
240
+ resource.update_member('newsletter@pewpew.mailgun.org', 'member@example.com', params)
241
+ end
242
+
243
+ subject { response }
244
+
245
+ specify { should be_success }
246
+
247
+ its(:status) { should == 200 }
248
+ its(:message) { should == 'Mailing list member has been updated' }
249
+
250
+ context 'member' do
251
+ subject { response.member }
252
+
253
+ its(:address) { should == 'member@example.com' }
254
+ its(:name) { should == 'Member Name' }
255
+ its(:subscribed) { should be_false }
256
+
257
+ context 'vars' do
258
+ subject { response.member.vars }
259
+
260
+ its(:awesome) { should be_true }
261
+ end
262
+ end
263
+ end
264
+
265
+ context '#remove_member' do
266
+ let(:response) do
267
+ resource.remove_member('newsletter@pewpew.mailgun.org', 'member@example.com')
268
+ end
269
+
270
+ subject { response }
271
+
272
+ specify { should be_success }
273
+
274
+ its(:status) { should == 200 }
275
+ its(:message) { should == 'Mailing list member has been deleted' }
276
+
277
+ context 'member' do
278
+ subject { response.member }
279
+
280
+ its(:address) { should == 'member@example.com' }
281
+ end
282
+ end
283
+ end