mailgun-ruby 1.2.12 → 1.2.14
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.
- checksums.yaml +4 -4
- data/.ruby-env.yml.example +1 -0
- data/CHANGELOG.md +21 -1
- data/README.md +4 -1
- data/docs/Domains.md +1 -1
- data/docs/EmailValidation.md +34 -0
- data/docs/Events.md +1 -1
- data/docs/MessageBuilder.md +1 -1
- data/docs/Messages.md +1 -1
- data/docs/OptInHandler.md +1 -1
- data/docs/Snippets.md +1 -1
- data/docs/Subaccounts.md +68 -0
- data/docs/Suppressions.md +10 -0
- data/docs/Webhooks.md +1 -1
- data/docs/railgun/EmailValidation.md +34 -0
- data/lib/mailgun/client.rb +23 -2
- data/lib/mailgun/domains/domains.rb +229 -1
- data/lib/mailgun/messages/message_builder.rb +8 -0
- data/lib/mailgun/subaccounts/subaccounts.rb +84 -0
- data/lib/mailgun/tags/tags.rb +120 -0
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/webhooks.rb +20 -4
- data/lib/mailgun.rb +2 -0
- data/lib/railgun/mailer.rb +31 -0
- data/mailgun.gemspec +1 -1
- data/spec/integration/domains_spec.rb +244 -0
- data/spec/integration/events_spec.rb +1 -1
- data/spec/integration/mailer_spec.rb +2 -8
- data/spec/integration/subaccounts_spec.rb +58 -0
- data/spec/integration/tags.rb +139 -0
- data/spec/integration/webhook_spec.rb +10 -10
- data/spec/unit/messages/message_builder_spec.rb +11 -0
- data/spec/unit/railgun/content_type_spec.rb +17 -0
- data/vcr_cassettes/domains.yml +1068 -1
- data/vcr_cassettes/subaccounts.yml +270 -0
- data/vcr_cassettes/tags.yml +417 -0
- data/vcr_cassettes/webhooks.yml +156 -186
- metadata +15 -4
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailgun'
|
3
|
+
|
4
|
+
vcr_opts = { :cassette_name => "tags" }
|
5
|
+
|
6
|
+
describe 'For the tags endpoints', vcr: vcr_opts do
|
7
|
+
let(:tag_name) { 'abtest-option-a' }
|
8
|
+
let(:domain) { "integration-test.domain.invalid" }
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
@mg_client = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
12
|
+
@tags = Mailgun::Tags.new(@mg_client)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get_tags' do
|
16
|
+
it 'returs tags info' do
|
17
|
+
result = @tags.get_tags(domain)
|
18
|
+
|
19
|
+
expect(result.first['tag']).to eq('You can track mails as tag-units!')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#get_tag' do
|
24
|
+
it "return the tag's info" do
|
25
|
+
result = @tags.get_tag(domain, tag_name)
|
26
|
+
|
27
|
+
expect(result['tag']).to eq(tag_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#update' do
|
32
|
+
it "returns true" do
|
33
|
+
result = @tags.update(
|
34
|
+
domain,
|
35
|
+
tag_name,
|
36
|
+
{ description: 'new description 2' }
|
37
|
+
)
|
38
|
+
|
39
|
+
expect(result).to eq(true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#get_tag_stats' do
|
44
|
+
it "returns tag stats info" do
|
45
|
+
result = @tags.get_tag_stats(
|
46
|
+
domain,
|
47
|
+
tag_name,
|
48
|
+
{
|
49
|
+
event: 'accepted',
|
50
|
+
start: 'Tue, 23 Jan 2024 11:23:45 EST',
|
51
|
+
resolution: 'day'
|
52
|
+
}
|
53
|
+
)
|
54
|
+
|
55
|
+
expect(result).to include('stats')
|
56
|
+
expect(result['stats'].first['accepted']).to include(
|
57
|
+
{
|
58
|
+
'incoming' => 0,
|
59
|
+
'outgoing' => 0,
|
60
|
+
'total' => 0
|
61
|
+
}
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#get_countries_aggregated_stats' do
|
67
|
+
it "returns countries of origin for a given domain" do
|
68
|
+
result = @tags.get_countries_aggregated_stats(
|
69
|
+
domain,
|
70
|
+
tag_name
|
71
|
+
)
|
72
|
+
|
73
|
+
expect(result).to include('country')
|
74
|
+
expect(result['country']['ad']).to include(
|
75
|
+
{
|
76
|
+
'clicked' => 0,
|
77
|
+
'complained' => 0,
|
78
|
+
'opened' => 0,
|
79
|
+
'unique_clicked' => 0,
|
80
|
+
'unique_opened' => 0,
|
81
|
+
'unsubscribed' => 0
|
82
|
+
}
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#get_providers_aggregated_stats' do
|
88
|
+
it "returns email providers for a given domain" do
|
89
|
+
result = @tags.get_providers_aggregated_stats(
|
90
|
+
domain,
|
91
|
+
tag_name
|
92
|
+
)
|
93
|
+
|
94
|
+
expect(result).to include('provider')
|
95
|
+
expect(result['provider']['aol.com']).to include(
|
96
|
+
{
|
97
|
+
'clicked' => 0,
|
98
|
+
'complained' => 0,
|
99
|
+
'opened' => 0,
|
100
|
+
'unique_clicked' => 0,
|
101
|
+
'unique_opened' => 0,
|
102
|
+
'unsubscribed' => 0
|
103
|
+
}
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#get_devices_aggregated_stats' do
|
109
|
+
it "returns devices for a given domain" do
|
110
|
+
result = @tags.get_devices_aggregated_stats(
|
111
|
+
domain,
|
112
|
+
tag_name
|
113
|
+
)
|
114
|
+
|
115
|
+
expect(result).to include('device')
|
116
|
+
expect(result['device']['desktop']).to include(
|
117
|
+
{
|
118
|
+
'clicked' => 0,
|
119
|
+
'complained' => 0,
|
120
|
+
'opened' => 28,
|
121
|
+
'unique_clicked' => 0,
|
122
|
+
'unique_opened' => 24,
|
123
|
+
'unsubscribed' => 0
|
124
|
+
}
|
125
|
+
)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#remove' do
|
130
|
+
it "returns true" do
|
131
|
+
result = @tags.remove(
|
132
|
+
domain,
|
133
|
+
tag_name
|
134
|
+
)
|
135
|
+
|
136
|
+
expect(result).to eq(true)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -7,48 +7,48 @@ describe 'For the webhooks endpoint', order: :defined, vcr: vcr_opts do
|
|
7
7
|
before(:all) do
|
8
8
|
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
9
9
|
@domain = TESTDOMAIN
|
10
|
-
@testhook = '
|
11
|
-
@testhookup = '
|
10
|
+
@testhook = 'accepted'
|
11
|
+
@testhookup = 'accepted'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'creates a webhook' do
|
15
|
-
result = @mg_obj.post("domains/#{@domain}/webhooks", { id:
|
15
|
+
result = @mg_obj.post("domains/#{@domain}/webhooks", { id: @testhook,
|
16
16
|
url: "http://example.com/mailgun/events/#{@testhook}" } )
|
17
17
|
|
18
18
|
result.to_h!
|
19
19
|
expect(result.body["message"]).to eq("Webhook has been created")
|
20
|
-
expect(result.body["webhook"]["
|
20
|
+
expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'gets a webhook.' do
|
24
24
|
result = @mg_obj.get("domains/#{@domain}/webhooks/#{@testhook}")
|
25
25
|
|
26
26
|
result.to_h!
|
27
|
-
expect(result.body["webhook"]["
|
27
|
+
expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'gets a list of all webhooks.' do
|
31
31
|
result = @mg_obj.get("domains/#{@domain}/webhooks")
|
32
32
|
|
33
33
|
result.to_h!
|
34
|
-
expect(result.body["webhooks"]["
|
34
|
+
expect(result.body["webhooks"]["accepted"]["urls"]).to include("http://example.com/mailgun/events/#{@testhook}")
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'updates a webhook.' do
|
38
|
-
result = @mg_obj.put("domains/#{@domain}/webhooks
|
38
|
+
result = @mg_obj.put("domains/#{@domain}/webhooks/#{@testhook}", {:id => @testhook,
|
39
39
|
:url => "http://example.com/mailgun/events/#{@testhookup}"})
|
40
40
|
|
41
41
|
result.to_h!
|
42
42
|
expect(result.body["message"]).to eq("Webhook has been updated")
|
43
|
-
expect(result.body["webhook"]["
|
43
|
+
expect(result.body["webhook"]["urls"]).to include("http://example.com/mailgun/events/#{@testhookup}")
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'removes a webhook' do
|
47
|
-
result = @mg_obj.delete("domains/#{@domain}/webhooks
|
47
|
+
result = @mg_obj.delete("domains/#{@domain}/webhooks/#{@testhook}")
|
48
48
|
|
49
49
|
result.to_h!
|
50
50
|
expect(result.body['message']).to eq("Webhook has been deleted")
|
51
|
-
expect(result.body['webhook']['
|
51
|
+
expect(result.body['webhook']['urls']).to include("http://example.com/mailgun/events/#{@testhookup}")
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -186,6 +186,17 @@ describe 'The method body_text' do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
describe 'The method amp_html' do
|
190
|
+
it 'sets amp-html to a string, not an array' do
|
191
|
+
the_text = 'Don\'t mess with Texas!'
|
192
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
193
|
+
@mb_obj.amp_html(the_text)
|
194
|
+
expect(@mb_obj.message['amp-html']).to be_a(String)
|
195
|
+
expect(@mb_obj.message['amp-html']).to eq(the_text)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
|
189
200
|
describe 'The method set_from_address' do
|
190
201
|
it 'warns of set_from_address deprecation' do
|
191
202
|
@mb_obj = Mailgun::MessageBuilder.new
|
@@ -26,6 +26,17 @@ describe 'extract_body' do
|
|
26
26
|
}
|
27
27
|
let(:html_content) { '<h3> [TEST] </h3> <br/> Hello, world!' }
|
28
28
|
|
29
|
+
let(:amp_mail_option) {
|
30
|
+
{
|
31
|
+
from: 'bob@example.com',
|
32
|
+
to: 'sally@example.com',
|
33
|
+
subject: 'RAILGUN TEST SAMPLE',
|
34
|
+
body: amp_content,
|
35
|
+
content_type: 'text/x-amp-html',
|
36
|
+
}
|
37
|
+
}
|
38
|
+
let(:amp_content) { '<h3> [TEST] </h3> <br/> Hello from AMP!' }
|
39
|
+
|
29
40
|
context 'with <Content-Type: text/plain>' do
|
30
41
|
let(:sample_mail) { Mail.new(text_mail_option) }
|
31
42
|
|
@@ -53,10 +64,12 @@ describe 'extract_body' do
|
|
53
64
|
context 'with <Content-Type: multipart/alternative>' do
|
54
65
|
let(:text_mail) { Mail.new(text_mail_option) }
|
55
66
|
let(:html_mail) { Mail.new(html_mail_option) }
|
67
|
+
let(:amp_mail) { Mail.new(amp_mail_option) }
|
56
68
|
|
57
69
|
before do
|
58
70
|
@sample_mail = Mail::Part.new(content_type: "multipart/alternative")
|
59
71
|
@sample_mail.add_part text_mail
|
72
|
+
@sample_mail.add_part amp_mail
|
60
73
|
@sample_mail.add_part html_mail
|
61
74
|
end
|
62
75
|
|
@@ -67,5 +80,9 @@ describe 'extract_body' do
|
|
67
80
|
it 'should return body html' do
|
68
81
|
expect(Railgun.extract_body_html(@sample_mail)).to eq(html_content)
|
69
82
|
end
|
83
|
+
|
84
|
+
it 'should return AMP html' do
|
85
|
+
expect(Railgun.extract_amp_html(@sample_mail)).to eq(amp_content)
|
86
|
+
end
|
70
87
|
end
|
71
88
|
end
|