pew_pew 0.0.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/.gitignore +19 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +84 -0
- data/Rakefile +3 -0
- data/lib/pew_pew.rb +32 -0
- data/lib/pew_pew/client.rb +90 -0
- data/lib/pew_pew/config.rb +15 -0
- data/lib/pew_pew/domain.rb +9 -0
- data/lib/pew_pew/resource.rb +52 -0
- data/lib/pew_pew/resources/bounces.rb +41 -0
- data/lib/pew_pew/resources/campaigns.rb +141 -0
- data/lib/pew_pew/resources/complaints.rb +40 -0
- data/lib/pew_pew/resources/lists.rb +121 -0
- data/lib/pew_pew/resources/logs.rb +12 -0
- data/lib/pew_pew/resources/mailboxes.rb +41 -0
- data/lib/pew_pew/resources/messages.rb +37 -0
- data/lib/pew_pew/resources/routes.rb +57 -0
- data/lib/pew_pew/resources/stats.rb +12 -0
- data/lib/pew_pew/resources/unsubscribes.rb +43 -0
- data/lib/pew_pew/response.rb +11 -0
- data/lib/pew_pew/version.rb +3 -0
- data/pew_pew.gemspec +20 -0
- data/spec/fixtures/bounces.yml +144 -0
- data/spec/fixtures/campaigns.yml +368 -0
- data/spec/fixtures/complaints.yml +142 -0
- data/spec/fixtures/image.png +0 -0
- data/spec/fixtures/lists.yml +403 -0
- data/spec/fixtures/logs.yml +133 -0
- data/spec/fixtures/mailboxes.yml +141 -0
- data/spec/fixtures/messages.yml +196 -0
- data/spec/fixtures/mime.eml +34 -0
- data/spec/fixtures/routes.yml +225 -0
- data/spec/fixtures/stats.yml +61 -0
- data/spec/fixtures/unsubscribes.yml +219 -0
- data/spec/pew_pew/client_spec.rb +51 -0
- data/spec/pew_pew/config_spec.rb +38 -0
- data/spec/pew_pew/resource_spec.rb +46 -0
- data/spec/pew_pew/resources/bounces_spec.rb +78 -0
- data/spec/pew_pew/resources/campaigns_spec.rb +228 -0
- data/spec/pew_pew/resources/complaints_spec.rb +69 -0
- data/spec/pew_pew/resources/lists_spec.rb +283 -0
- data/spec/pew_pew/resources/logs_spec.rb +28 -0
- data/spec/pew_pew/resources/mailboxes_spec.rb +59 -0
- data/spec/pew_pew/resources/messages_spec.rb +53 -0
- data/spec/pew_pew/resources/routes_spec.rb +135 -0
- data/spec/pew_pew/resources/stats_spec.rb +26 -0
- data/spec/pew_pew/resources/unsubscribes_spec.rb +99 -0
- data/spec/pew_pew/response_spec.rb +21 -0
- data/spec/pew_pew_spec.rb +13 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/contexts/api_requests.rb +23 -0
- data/spec/support/contexts/domain_resource.rb +17 -0
- data/spec/support/vcr.rb +6 -0
- metadata +211 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PewPew::Resources::Logs, :resource, :domain do
|
6
|
+
let(:resource) { described_class.new(client) }
|
7
|
+
|
8
|
+
context '#all' do
|
9
|
+
let(:response) { resource.all }
|
10
|
+
|
11
|
+
subject { response }
|
12
|
+
|
13
|
+
specify { should be_success }
|
14
|
+
|
15
|
+
its(:status) { should == 200 }
|
16
|
+
its(:total_count) { should == 27 }
|
17
|
+
|
18
|
+
context 'item' do
|
19
|
+
subject { response.items.first }
|
20
|
+
|
21
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 04:19:04 GMT' }
|
22
|
+
its(:hap) { should == 'delivered' }
|
23
|
+
its(:message) { should == "Delivered: postmaster@pewpew.mailgun.org → pewpew@devoh.com 'Test'" }
|
24
|
+
its(:message_id) { should == '4fc84273c474_48dd3fe70cc34cd05949d@rouge.local.mail' }
|
25
|
+
its(:type) { should == 'info' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Resources::Mailboxes, :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(:created_at) { should == 'Mon, 21 May 2012 22:12:54 GMT' }
|
20
|
+
its(:mailbox) { should == 'postmaster@pewpew.mailgun.org' }
|
21
|
+
its(:size_bytes) { should be_nil }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '#create' do
|
26
|
+
let(:params) { { mailbox: 'test', password: 'secret' } }
|
27
|
+
let(:response) { resource.create(params) }
|
28
|
+
|
29
|
+
subject { response }
|
30
|
+
|
31
|
+
specify { should be_success }
|
32
|
+
|
33
|
+
its(:status) { should == 200 }
|
34
|
+
its(:message) { should == 'Created 1 mailboxes' }
|
35
|
+
end
|
36
|
+
|
37
|
+
context '#update' do
|
38
|
+
let(:params) { { password: 's3cr3t' } }
|
39
|
+
let(:response) { resource.update('test', params) }
|
40
|
+
|
41
|
+
subject { response }
|
42
|
+
|
43
|
+
specify { should be_success }
|
44
|
+
|
45
|
+
its(:status) { should == 200 }
|
46
|
+
its(:message) { should == 'Password changed' }
|
47
|
+
end
|
48
|
+
|
49
|
+
context '#remove' do
|
50
|
+
let(:response) { resource.remove('test') }
|
51
|
+
|
52
|
+
subject { response }
|
53
|
+
|
54
|
+
specify { should be_success }
|
55
|
+
|
56
|
+
its(:status) { should == 200 }
|
57
|
+
its(:message) { should == 'Mailbox has been deleted' }
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Resources::Messages, :resource, :domain do
|
4
|
+
let(:resource) { described_class.new(client) }
|
5
|
+
|
6
|
+
context '#send_email' do
|
7
|
+
let(:params) {
|
8
|
+
{
|
9
|
+
to: 'pewpew@devoh.com',
|
10
|
+
from: 'pewpew@devoh.com',
|
11
|
+
subject: 'Test',
|
12
|
+
text: 'This is a test message.'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:file) { Faraday::UploadIO.new('spec/fixtures/image.png', 'image/png') }
|
17
|
+
|
18
|
+
subject { resource.send_email(params) }
|
19
|
+
|
20
|
+
specify { should be_success }
|
21
|
+
|
22
|
+
context 'with an attachment' do
|
23
|
+
before do
|
24
|
+
params.merge!(attachment: file)
|
25
|
+
end
|
26
|
+
|
27
|
+
specify { should be_success }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with an inline attachment' do
|
31
|
+
before do
|
32
|
+
params.merge!(
|
33
|
+
html: "#{params[:text]} <img src=\"cid:image.png\">",
|
34
|
+
inline: file
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
specify { should be_success }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#send_mime' do
|
43
|
+
let(:message) do
|
44
|
+
Faraday::UploadIO.new('spec/fixtures/mime.eml', 'message/rfc822')
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:params) { { to: 'pewpew@devoh.com', message: message } }
|
48
|
+
|
49
|
+
subject { resource.send_mime(params) }
|
50
|
+
|
51
|
+
specify { should be_success }
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Resources::Routes, :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(:id) { should == '4fc850083533542f7704bc05' }
|
20
|
+
its(:priority) { should == 1 }
|
21
|
+
its(:description) { should == 'Forward Gmail' }
|
22
|
+
its(:expression) { should == "match_recipient('.*@gmail.com')" }
|
23
|
+
its(:actions) { should == ["forward('gmail@example.com')"] }
|
24
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context '#find' do
|
29
|
+
let(:response) { resource.find('4fc850083533542f7704bc05') }
|
30
|
+
|
31
|
+
subject { response }
|
32
|
+
|
33
|
+
specify { should be_success }
|
34
|
+
|
35
|
+
its(:status) { should == 200 }
|
36
|
+
|
37
|
+
context 'route' do
|
38
|
+
subject { response.route }
|
39
|
+
|
40
|
+
its(:id) { should == '4fc850083533542f7704bc05' }
|
41
|
+
its(:priority) { should == 1 }
|
42
|
+
its(:description) { should == 'Forward Gmail' }
|
43
|
+
its(:expression) { should == "match_recipient('.*@gmail.com')" }
|
44
|
+
its(:actions) { should == ["forward('gmail@example.com')"] }
|
45
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context '#create' do
|
50
|
+
let(:params) do
|
51
|
+
{
|
52
|
+
priority: 1,
|
53
|
+
description: 'Forward Gmail',
|
54
|
+
expression: "match_recipient('.*@gmail.com')",
|
55
|
+
action: "forward('gmail@example.com')"
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:response) { resource.create(params) }
|
60
|
+
|
61
|
+
subject { response }
|
62
|
+
|
63
|
+
context 'with a single action' do
|
64
|
+
specify { should be_success }
|
65
|
+
|
66
|
+
its(:status) { should == 200 }
|
67
|
+
its(:message) { should == 'Route has been created' }
|
68
|
+
|
69
|
+
context 'route' do
|
70
|
+
subject { response.route }
|
71
|
+
|
72
|
+
its(:id) { should == '4fc850083533542f7704bc05' }
|
73
|
+
its(:priority) { should == params[:priority] }
|
74
|
+
its(:description) { should == params[:description] }
|
75
|
+
its(:expression) { should == params[:expression] }
|
76
|
+
its(:actions) { should == [params[:action]] }
|
77
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with multiple actions' do
|
82
|
+
before do
|
83
|
+
params.merge!(action: [params[:action], 'stop()'])
|
84
|
+
end
|
85
|
+
|
86
|
+
specify { should be_success }
|
87
|
+
|
88
|
+
its(:status) { should == 200 }
|
89
|
+
its(:message) { should == 'Route has been created' }
|
90
|
+
|
91
|
+
context 'route' do
|
92
|
+
subject { response.route }
|
93
|
+
|
94
|
+
its(:id) { should == '4fc854bd9d12a36fc504d4b3' }
|
95
|
+
its(:priority) { should == params[:priority] }
|
96
|
+
its(:description) { should == params[:description] }
|
97
|
+
its(:expression) { should == params[:expression] }
|
98
|
+
its(:actions) { should == params[:action] }
|
99
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 05:35:57 GMT' }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context '#update' do
|
105
|
+
let(:params) { { priority: 2 } }
|
106
|
+
let(:response) { resource.update('4fc850083533542f7704bc05', params) }
|
107
|
+
|
108
|
+
subject { response }
|
109
|
+
|
110
|
+
specify { should be_success }
|
111
|
+
|
112
|
+
its(:status) { should == 200 }
|
113
|
+
its(:message) { should == 'Route has been updated' }
|
114
|
+
|
115
|
+
its(:id) { should == '4fc850083533542f7704bc05' }
|
116
|
+
its(:priority) { should == params[:priority] }
|
117
|
+
its(:description) { should == 'Forward Gmail' }
|
118
|
+
its(:expression) { should == "match_recipient('.*@gmail.com')" }
|
119
|
+
its(:actions) { should == ["forward('gmail@example.com')"] }
|
120
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
|
121
|
+
end
|
122
|
+
|
123
|
+
context '#remove' do
|
124
|
+
let(:response) { resource.remove('4fc854bd9d12a36fc504d4b3') }
|
125
|
+
|
126
|
+
subject { response }
|
127
|
+
|
128
|
+
specify { should be_success }
|
129
|
+
|
130
|
+
its(:status) { should == 200 }
|
131
|
+
its(:message) { should == 'Route has been deleted' }
|
132
|
+
|
133
|
+
its(:id) { should == '4fc854bd9d12a36fc504d4b3' }
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Resources::Stats, :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 == 10 }
|
15
|
+
|
16
|
+
context 'item' do
|
17
|
+
subject { response.items.first }
|
18
|
+
|
19
|
+
its(:created_at) { should == 'Fri, 01 Jun 2012 00:00:00 GMT' }
|
20
|
+
its(:event) { should == 'sent' }
|
21
|
+
its(:id) { should == '4fc837558393c1618263d76c' }
|
22
|
+
its(:tags) { should == {} }
|
23
|
+
its(:total_count) { should == 11 }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Resources::Unsubscribes, :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 == 2 }
|
15
|
+
|
16
|
+
context 'item' do
|
17
|
+
subject { response.items.first }
|
18
|
+
|
19
|
+
its(:address) { should == 'test@example.com' }
|
20
|
+
its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
|
21
|
+
its(:id) { should == '4fc9806d8393c1618264c360' }
|
22
|
+
its(:tag) { should == '*' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#find' do
|
27
|
+
let(:response) { resource.find('test@example.com') }
|
28
|
+
|
29
|
+
subject { response }
|
30
|
+
|
31
|
+
specify { should be_success }
|
32
|
+
|
33
|
+
its(:status) { should == 200 }
|
34
|
+
its(:total_count) { should == 2 }
|
35
|
+
|
36
|
+
context 'unsubscribe' do
|
37
|
+
subject { response.items.first }
|
38
|
+
|
39
|
+
its(:address) { should == 'test@example.com' }
|
40
|
+
its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
|
41
|
+
its(:id) { should == '4fc9806d8393c1618264c360' }
|
42
|
+
its(:tag) { should == '*' }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context '#create' do
|
47
|
+
let(:response) { resource.create(params) }
|
48
|
+
|
49
|
+
subject { response }
|
50
|
+
|
51
|
+
context 'with a tag' do
|
52
|
+
let(:params) { { address: 'test@example.com', tag: 'newsletter' } }
|
53
|
+
|
54
|
+
specify { should be_success }
|
55
|
+
|
56
|
+
its(:status) { should == 200 }
|
57
|
+
its(:message) { should == 'Address has been added to the unsubscribes table' }
|
58
|
+
|
59
|
+
its(:address) { should == 'test@example.com' }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'without a tag' do
|
63
|
+
let(:params) { { address: 'test@example.com' } }
|
64
|
+
|
65
|
+
specify { should be_success }
|
66
|
+
|
67
|
+
its(:status) { should == 200 }
|
68
|
+
its(:message) { should == 'Address has been added to the unsubscribes table' }
|
69
|
+
|
70
|
+
its(:address) { should == 'test@example.com' }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '#remove' do
|
75
|
+
subject { response }
|
76
|
+
|
77
|
+
context 'with an address' do
|
78
|
+
let(:response) { resource.remove('test@example.com') }
|
79
|
+
|
80
|
+
specify { should be_success }
|
81
|
+
|
82
|
+
its(:status) { should == 200 }
|
83
|
+
its(:message) { should == 'Unsubscribe event has been removed' }
|
84
|
+
|
85
|
+
its(:address) { should == 'test@example.com' }
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with an unsubscribe event ID' do
|
89
|
+
let(:response) { resource.remove('4fc9806d8393c1618264c360') }
|
90
|
+
|
91
|
+
specify { should be_success }
|
92
|
+
|
93
|
+
its(:status) { should == 200 }
|
94
|
+
its(:message) { should == 'Unsubscribe event has been removed' }
|
95
|
+
|
96
|
+
its(:address) { should == '4fc9806d8393c1618264c360' }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew::Response do
|
4
|
+
it { should be_a(Hashie::Mash) }
|
5
|
+
|
6
|
+
context '#count' do
|
7
|
+
it 'returns the value of the count attribute' do
|
8
|
+
described_class.new(count: 2).count.should == 2
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#success?' do
|
13
|
+
it 'returns true if the status is 200' do
|
14
|
+
described_class.new(status: 200).should be_success
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false if the status is 400' do
|
18
|
+
described_class.new(status: 400).should_not be_success
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PewPew do
|
4
|
+
[
|
5
|
+
Relax::Client.instance_methods(false),
|
6
|
+
PewPew::Client.instance_methods(false)
|
7
|
+
].flatten.each do |method|
|
8
|
+
it "delegates .#{method} to .client" do
|
9
|
+
described_class.send(:client).should_receive(method)
|
10
|
+
described_class.send(method)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pew_pew'
|
2
|
+
|
3
|
+
# These defaults are only for use when developing this client library. Please
|
4
|
+
# do not use them in your own applications. Sign up for your own account here:
|
5
|
+
# https://mailgun.net/signup
|
6
|
+
ENV['MAILGUN_API_KEY'] ||= 'key-02n9f3ijl9sm9u97-8p7r-d7-15q-ui1'
|
7
|
+
ENV['MAILGUN_DOMAIN'] ||= 'pewpew.mailgun.org'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
|
16
|
+
require(file)
|
17
|
+
end
|