mailgunner 2.6.0 → 3.2.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.
- checksums.yaml +4 -4
- data/CHANGES.md +218 -0
- data/LICENSE.txt +1 -1
- data/README.md +14 -31
- data/lib/mailgunner.rb +13 -0
- data/lib/mailgunner/client.rb +19 -48
- data/lib/mailgunner/client/domains.rb +35 -3
- data/lib/mailgunner/client/email_validation.rb +15 -3
- data/lib/mailgunner/client/events.rb +2 -2
- data/lib/mailgunner/client/ips.rb +2 -2
- data/lib/mailgunner/client/mailing_lists.rb +6 -6
- data/lib/mailgunner/client/messages.rb +2 -2
- data/lib/mailgunner/client/routes.rb +4 -4
- data/lib/mailgunner/client/stats.rb +2 -8
- data/lib/mailgunner/client/suppressions.rb +25 -9
- data/lib/mailgunner/client/tags.rb +3 -3
- data/lib/mailgunner/client/webhooks.rb +2 -2
- data/lib/mailgunner/config.rb +45 -0
- data/lib/mailgunner/delivery_method.rb +4 -2
- data/lib/mailgunner/errors.rb +25 -7
- data/lib/mailgunner/params.rb +16 -0
- data/lib/mailgunner/railtie.rb +1 -0
- data/lib/mailgunner/struct.rb +49 -0
- data/lib/mailgunner/version.rb +1 -1
- data/mailgunner.gemspec +4 -9
- metadata +14 -83
- data/spec/mailgunner_delivery_method_spec.rb +0 -37
- data/spec/mailgunner_spec.rb +0 -747
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def get_domains(params =
|
6
|
-
get('/v3/domains', params)
|
5
|
+
def get_domains(params = PARAMS)
|
6
|
+
get('/v3/domains', query: params)
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_domain(name)
|
10
10
|
get("/v3/domains/#{escape name}")
|
11
11
|
end
|
12
12
|
|
13
|
-
def add_domain(attributes =
|
13
|
+
def add_domain(attributes = ATTRIBUTES)
|
14
14
|
post('/v3/domains', attributes)
|
15
15
|
end
|
16
16
|
|
@@ -18,6 +18,10 @@ module Mailgunner
|
|
18
18
|
delete("/v3/domains/#{escape name}")
|
19
19
|
end
|
20
20
|
|
21
|
+
def verify_domain(name)
|
22
|
+
put("/v3/domains/#{escape name}/verify")
|
23
|
+
end
|
24
|
+
|
21
25
|
def get_credentials
|
22
26
|
get("/v3/domains/#{escape @domain}/credentials")
|
23
27
|
end
|
@@ -41,5 +45,33 @@ module Mailgunner
|
|
41
45
|
def update_connection_settings(attributes)
|
42
46
|
put("/v3/domains/#{escape @domain}/connection", attributes)
|
43
47
|
end
|
48
|
+
|
49
|
+
def get_tracking_settings
|
50
|
+
get("/v3/domains/#{escape @domain}/tracking")
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_open_tracking_settings(params = PARAMS)
|
54
|
+
put("/v3/domains/#{escape @domain}/tracking/open", params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_click_tracking_settings(params = PARAMS)
|
58
|
+
put("/v3/domains/#{escape @domain}/tracking/click", params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update_unsubscribe_tracking_settings(params = PARAMS)
|
62
|
+
put("/v3/domains/#{escape @domain}/tracking/unsubscribe", params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_dkim_authority(params = PARAMS)
|
66
|
+
put("/v3/domains/#{escape @domain}/dkim_authority", params)
|
67
|
+
end
|
68
|
+
|
69
|
+
def update_dkim_selector(params = PARAMS)
|
70
|
+
put("/v3/domains/#{escape @domain}/dkim_selector", params)
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_web_prefix(params = PARAMS)
|
74
|
+
put("/v3/domains/#{escape @domain}/web_prefix", params)
|
75
|
+
end
|
44
76
|
end
|
45
77
|
end
|
@@ -3,11 +3,23 @@
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
5
|
def validate_address(value)
|
6
|
-
get('/
|
6
|
+
get('/v4/address/validate', query: {address: value})
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
get('/
|
9
|
+
def get_bulk_validations
|
10
|
+
get('/v4/address/validate/bulk')
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_bulk_validation(list_id)
|
14
|
+
post("/v4/address/validate/bulk/#{escape list_id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_bulk_validation(list_id)
|
18
|
+
get("/v4/address/validate/bulk/#{escape list_id}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def cancel_bulk_validation(list_id)
|
22
|
+
delete("/v4/address/validate/bulk/#{escape list_id}")
|
11
23
|
end
|
12
24
|
end
|
13
25
|
end
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def get_lists(params =
|
6
|
-
get('/v3/lists', params)
|
5
|
+
def get_lists(params = PARAMS)
|
6
|
+
get('/v3/lists/pages', query: params)
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_list(address)
|
10
10
|
get("/v3/lists/#{escape address}")
|
11
11
|
end
|
12
12
|
|
13
|
-
def add_list(attributes =
|
13
|
+
def add_list(attributes = ATTRIBUTES)
|
14
14
|
post('/v3/lists', attributes)
|
15
15
|
end
|
16
16
|
|
17
|
-
def update_list(address, attributes =
|
17
|
+
def update_list(address, attributes = ATTRIBUTES)
|
18
18
|
put("/v3/lists/#{escape address}", attributes)
|
19
19
|
end
|
20
20
|
|
@@ -22,8 +22,8 @@ module Mailgunner
|
|
22
22
|
delete("/v3/lists/#{escape address}")
|
23
23
|
end
|
24
24
|
|
25
|
-
def get_list_members(list_address, params =
|
26
|
-
get("/v3/lists/#{escape list_address}/members", params)
|
25
|
+
def get_list_members(list_address, params = PARAMS)
|
26
|
+
get("/v3/lists/#{escape list_address}/members/pages", query: params)
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_list_member(list_address, member_address)
|
@@ -7,10 +7,10 @@ module Mailgunner
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_mime_message(key)
|
10
|
-
get("/v3/domains/#{escape @domain}/messages/#{escape key}",
|
10
|
+
get("/v3/domains/#{escape @domain}/messages/#{escape key}", headers: {'Accept' => 'message/rfc2822'})
|
11
11
|
end
|
12
12
|
|
13
|
-
def send_message(attributes =
|
13
|
+
def send_message(attributes = ATTRIBUTES)
|
14
14
|
post("/v3/#{escape @domain}/messages", attributes)
|
15
15
|
end
|
16
16
|
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def get_routes(params =
|
6
|
-
get('/v3/routes', params)
|
5
|
+
def get_routes(params = PARAMS)
|
6
|
+
get('/v3/routes', query: params)
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_route(id)
|
10
10
|
get("/v3/routes/#{escape id}")
|
11
11
|
end
|
12
12
|
|
13
|
-
def add_route(attributes =
|
13
|
+
def add_route(attributes = ATTRIBUTES)
|
14
14
|
post('/v3/routes', attributes)
|
15
15
|
end
|
16
16
|
|
17
|
-
def update_route(id, attributes =
|
17
|
+
def update_route(id, attributes = ATTRIBUTES)
|
18
18
|
put("/v3/routes/#{escape id}", attributes)
|
19
19
|
end
|
20
20
|
|
@@ -2,14 +2,8 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
get("/v3/#{escape @domain}/stats", params)
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_total_stats(params = {})
|
12
|
-
get("/v3/#{escape @domain}/stats/total", params)
|
5
|
+
def get_total_stats(params = PARAMS)
|
6
|
+
get("/v3/#{escape @domain}/stats/total", query: params)
|
13
7
|
end
|
14
8
|
end
|
15
9
|
end
|
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def get_bounces(params =
|
6
|
-
get("/v3/#{escape @domain}/bounces", params)
|
5
|
+
def get_bounces(params = PARAMS)
|
6
|
+
get("/v3/#{escape @domain}/bounces", query: params)
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_bounce(address)
|
10
10
|
get("/v3/#{escape @domain}/bounces/#{escape address}")
|
11
11
|
end
|
12
12
|
|
13
|
-
def add_bounce(attributes =
|
13
|
+
def add_bounce(attributes = ATTRIBUTES)
|
14
14
|
post("/v3/#{escape @domain}/bounces", attributes)
|
15
15
|
end
|
16
16
|
|
@@ -22,8 +22,8 @@ module Mailgunner
|
|
22
22
|
delete("/v3/#{escape @domain}/bounces")
|
23
23
|
end
|
24
24
|
|
25
|
-
def get_unsubscribes(params =
|
26
|
-
get("/v3/#{escape @domain}/unsubscribes", params)
|
25
|
+
def get_unsubscribes(params = PARAMS)
|
26
|
+
get("/v3/#{escape @domain}/unsubscribes", query: params)
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_unsubscribe(address)
|
@@ -34,24 +34,40 @@ module Mailgunner
|
|
34
34
|
delete("/v3/#{escape @domain}/unsubscribes/#{escape address_or_id}")
|
35
35
|
end
|
36
36
|
|
37
|
-
def add_unsubscribe(attributes =
|
37
|
+
def add_unsubscribe(attributes = ATTRIBUTES)
|
38
38
|
post("/v3/#{escape @domain}/unsubscribes", attributes)
|
39
39
|
end
|
40
40
|
|
41
|
-
def get_complaints(params =
|
42
|
-
get("/v3/#{escape @domain}/complaints", params)
|
41
|
+
def get_complaints(params = PARAMS)
|
42
|
+
get("/v3/#{escape @domain}/complaints", query: params)
|
43
43
|
end
|
44
44
|
|
45
45
|
def get_complaint(address)
|
46
46
|
get("/v3/#{escape @domain}/complaints/#{escape address}")
|
47
47
|
end
|
48
48
|
|
49
|
-
def add_complaint(attributes =
|
49
|
+
def add_complaint(attributes = ATTRIBUTES)
|
50
50
|
post("/v3/#{escape @domain}/complaints", attributes)
|
51
51
|
end
|
52
52
|
|
53
53
|
def delete_complaint(address)
|
54
54
|
delete("/v3/#{escape @domain}/complaints/#{escape address}")
|
55
55
|
end
|
56
|
+
|
57
|
+
def get_whitelists(params = PARAMS)
|
58
|
+
get("/v3/#{escape @domain}/whitelists", query: params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_whitelist(address_or_domain)
|
62
|
+
get("/v3/#{escape @domain}/whitelists/#{escape address_or_domain}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_whitelist(attributes = ATTRIBUTES)
|
66
|
+
post("/v3/#{escape @domain}/whitelists", attributes)
|
67
|
+
end
|
68
|
+
|
69
|
+
def delete_whitelist(address_or_domain)
|
70
|
+
delete("/v3/#{escape @domain}/whitelists/#{escape address_or_domain}")
|
71
|
+
end
|
56
72
|
end
|
57
73
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Mailgunner
|
4
4
|
class Client
|
5
|
-
def get_tags(params =
|
6
|
-
get("/v3/#{escape @domain}/tags", params)
|
5
|
+
def get_tags(params = PARAMS)
|
6
|
+
get("/v3/#{escape @domain}/tags", query: params)
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_tag(id)
|
@@ -15,7 +15,7 @@ module Mailgunner
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get_tag_stats(id, params)
|
18
|
-
get("/v3/#{escape @domain}/tags/#{escape id}/stats", params)
|
18
|
+
get("/v3/#{escape @domain}/tags/#{escape id}/stats", query: params)
|
19
19
|
end
|
20
20
|
|
21
21
|
def delete_tag(id)
|
@@ -10,11 +10,11 @@ module Mailgunner
|
|
10
10
|
get("/v3/domains/#{escape @domain}/webhooks/#{escape id}")
|
11
11
|
end
|
12
12
|
|
13
|
-
def add_webhook(attributes =
|
13
|
+
def add_webhook(attributes = ATTRIBUTES)
|
14
14
|
post("/v3/domains/#{escape @domain}/webhooks", attributes)
|
15
15
|
end
|
16
16
|
|
17
|
-
def update_webhook(id, attributes =
|
17
|
+
def update_webhook(id, attributes = ATTRIBUTES)
|
18
18
|
put("/v3/domains/#{escape @domain}/webhooks/#{escape id}", attributes)
|
19
19
|
end
|
20
20
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mailgunner
|
4
|
+
class Config
|
5
|
+
def domain
|
6
|
+
@domain ||= default_domain
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_writer :domain
|
10
|
+
|
11
|
+
def api_key
|
12
|
+
@api_key ||= ENV.fetch('MAILGUN_API_KEY')
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_writer :api_key
|
16
|
+
|
17
|
+
def api_host
|
18
|
+
@api_host ||= 'api.mailgun.net'
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_writer :api_host
|
22
|
+
|
23
|
+
def user_agent
|
24
|
+
@user_agent ||= "Ruby/#{RUBY_VERSION} Mailgunner/#{VERSION}"
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_writer :user_agent
|
28
|
+
|
29
|
+
module NoDomainProvided
|
30
|
+
def self.to_s
|
31
|
+
raise Error, 'No domain provided'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private_constant :NoDomainProvided
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def default_domain
|
40
|
+
return NoDomainProvided unless ENV.key?('MAILGUN_SMTP_LOGIN')
|
41
|
+
|
42
|
+
ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
require 'mail/check_delivery_params'
|
2
2
|
|
3
3
|
module Mailgunner
|
4
|
+
# @private
|
4
5
|
class DeliveryMethod
|
5
6
|
attr_accessor :settings
|
6
7
|
|
7
8
|
def initialize(values)
|
8
|
-
|
9
|
+
self.settings = values
|
9
10
|
end
|
10
11
|
|
11
12
|
def deliver!(mail)
|
12
13
|
check(mail)
|
13
14
|
|
14
|
-
|
15
|
+
client = Client.new(**settings)
|
16
|
+
client.send_mime(mail)
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
data/lib/mailgunner/errors.rb
CHANGED
@@ -1,15 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mailgunner
|
2
|
-
class Error < StandardError
|
4
|
+
class Error < StandardError
|
5
|
+
# @private
|
6
|
+
def self.parse(response)
|
7
|
+
exception_class = case response
|
8
|
+
when Net::HTTPUnauthorized
|
9
|
+
AuthenticationError
|
10
|
+
when Net::HTTPClientError
|
11
|
+
ClientError
|
12
|
+
when Net::HTTPServerError
|
13
|
+
ServerError
|
14
|
+
else
|
15
|
+
Error
|
16
|
+
end
|
17
|
+
|
18
|
+
message = if response['Content-Type']&.start_with?('application/json')
|
19
|
+
JSON.parse(response.body)['message']
|
20
|
+
end
|
21
|
+
|
22
|
+
message ||= "HTTP #{response.code} response from Mailgun API"
|
23
|
+
|
24
|
+
exception_class.new(message)
|
25
|
+
end
|
26
|
+
end
|
3
27
|
|
4
28
|
class ClientError < Error; end
|
5
29
|
|
6
30
|
class AuthenticationError < ClientError; end
|
7
31
|
|
8
32
|
class ServerError < Error; end
|
9
|
-
|
10
|
-
module NoDomainProvided
|
11
|
-
def self.to_s
|
12
|
-
raise Error, 'No domain provided'
|
13
|
-
end
|
14
|
-
end
|
15
33
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Mailgunner
|
5
|
+
module Params
|
6
|
+
def self.encode(params)
|
7
|
+
params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.escape(component)
|
11
|
+
CGI.escape(component.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private_constant :Params
|
16
|
+
end
|