mailgun-ruby 1.4.4 → 1.4.6
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/CHANGELOG.md +721 -71
- data/README.md +4 -1
- data/lib/mailgun/api_keys/api_keys.rb +65 -0
- data/lib/mailgun/client.rb +2 -2
- data/lib/mailgun/domains/domain_keys.rb +5 -5
- data/lib/mailgun/domains/domains.rb +12 -9
- data/lib/mailgun/events/events.rb +1 -1
- data/lib/mailgun/helpers/api_version_checker.rb +23 -12
- data/lib/mailgun/helpers/deprecation.rb +32 -0
- data/lib/mailgun/lists/mailing_lists.rb +250 -0
- data/lib/mailgun/messages/message_builder.rb +17 -7
- data/lib/mailgun/response.rb +1 -1
- data/lib/mailgun/routes/routes.rb +98 -0
- data/lib/mailgun/tags/analytics_tags.rb +2 -2
- data/lib/mailgun/tags/tags.rb +16 -8
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/account_webhooks.rb +2 -2
- data/lib/mailgun/webhooks/webhooks.rb +65 -18
- data/lib/mailgun.rb +2 -0
- metadata +7 -318
- data/.github/workflows/ci.yml +0 -49
- data/.gitignore +0 -24
- data/.rubocop.yml +0 -68
- data/.ruby-env.yml.example +0 -13
- data/Gemfile +0 -9
- data/Rakefile +0 -32
- data/docs/AccountWebhooks.md +0 -55
- data/docs/AnalyticsTags.md +0 -63
- data/docs/DomainKeys.md +0 -49
- data/docs/Domains.md +0 -82
- data/docs/EmailValidation.md +0 -34
- data/docs/Events.md +0 -48
- data/docs/Logs.md +0 -67
- data/docs/MessageBuilder.md +0 -120
- data/docs/Metrics.md +0 -108
- data/docs/OptInHandler.md +0 -103
- data/docs/Snippets.md +0 -519
- data/docs/Subaccounts.md +0 -68
- data/docs/Suppressions.md +0 -92
- data/docs/Templates.md +0 -92
- data/docs/Webhooks.md +0 -42
- data/docs/railgun/EmailValidation.md +0 -34
- data/docs/railgun/Overview.md +0 -11
- data/docs/railgun/Parameters.md +0 -83
- data/mailgun.gemspec +0 -47
- data/spec/integration/account_webhooks_spec.rb +0 -57
- data/spec/integration/analytics_tags_spec.rb +0 -54
- data/spec/integration/bounces_spec.rb +0 -45
- data/spec/integration/campaign_spec.rb +0 -62
- data/spec/integration/complaints_spec.rb +0 -40
- data/spec/integration/domain_keys_spec.rb +0 -124
- data/spec/integration/domains_spec.rb +0 -201
- data/spec/integration/email_validation_spec.rb +0 -73
- data/spec/integration/events_spec.rb +0 -28
- data/spec/integration/list_members_spec.rb +0 -64
- data/spec/integration/list_spec.rb +0 -59
- data/spec/integration/logs_spec.rb +0 -105
- data/spec/integration/mailer_spec.rb +0 -65
- data/spec/integration/mailgun_spec.rb +0 -198
- data/spec/integration/messages/sample_data/mime.txt +0 -38
- data/spec/integration/metrics_spec.rb +0 -224
- data/spec/integration/routes_spec.rb +0 -91
- data/spec/integration/stats_spec.rb +0 -17
- data/spec/integration/subaccounts_spec.rb +0 -57
- data/spec/integration/suppressions_spec.rb +0 -320
- data/spec/integration/templates_spec.rb +0 -137
- data/spec/integration/unsubscribes_spec.rb +0 -44
- data/spec/integration/webhook_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/client_spec.rb +0 -424
- data/spec/unit/connection/test_client.rb +0 -169
- data/spec/unit/events/events_spec.rb +0 -88
- data/spec/unit/exceptions/exceptions_spec.rb +0 -31
- data/spec/unit/helpers/api_version_checker_spec.rb +0 -206
- data/spec/unit/lists/opt_in_handler_spec.rb +0 -28
- data/spec/unit/mailgun_spec.rb +0 -171
- data/spec/unit/messages/batch_message_spec.rb +0 -148
- data/spec/unit/messages/message_builder_spec.rb +0 -745
- data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
- data/spec/unit/messages/sample_data/mime.txt +0 -38
- data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
- data/spec/unit/messages/sample_data/unknown.type +0 -0
- data/spec/unit/railgun/content_type_spec.rb +0 -89
- data/spec/unit/railgun/mailer_spec.rb +0 -391
- data/spec/unit/response_spec.rb +0 -225
- data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +0 -55
- data/vcr_cassettes/account_webhooks.yml +0 -269
- data/vcr_cassettes/analytics_tags.yml +0 -187
- data/vcr_cassettes/bounces.yml +0 -136
- data/vcr_cassettes/complaints.yml +0 -315
- data/vcr_cassettes/domains.todo.yml +0 -42
- data/vcr_cassettes/domains.yml +0 -1243
- data/vcr_cassettes/email_validation.yml +0 -152
- data/vcr_cassettes/events.yml +0 -69
- data/vcr_cassettes/exceptions-invalid-api-key.yml +0 -52
- data/vcr_cassettes/exceptions-invalid-data.yml +0 -52
- data/vcr_cassettes/exceptions-not-allowed.yml +0 -54
- data/vcr_cassettes/exceptions.yml +0 -92
- data/vcr_cassettes/list_members.yml +0 -328
- data/vcr_cassettes/logs.yml +0 -53
- data/vcr_cassettes/mailer_invalid_domain.yml +0 -109
- data/vcr_cassettes/mailing_list.todo.yml +0 -43
- data/vcr_cassettes/mailing_list.yml +0 -682
- data/vcr_cassettes/message_deliver.yml +0 -149
- data/vcr_cassettes/metrics.yml +0 -116
- data/vcr_cassettes/routes.yml +0 -359
- data/vcr_cassettes/send_message.yml +0 -158
- data/vcr_cassettes/stats.yml +0 -48
- data/vcr_cassettes/subaccounts.yml +0 -270
- data/vcr_cassettes/suppressions.yml +0 -1392
- data/vcr_cassettes/templates.yml +0 -1065
- data/vcr_cassettes/unsubscribes.yml +0 -401
- data/vcr_cassettes/webhooks.yml +0 -246
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailgun
|
|
4
|
+
# A Mailgun::Routes object is a simple CRUD interface to Mailgun Routes, the rules
|
|
5
|
+
# that handle incoming email.
|
|
6
|
+
# Uses Mailgun
|
|
7
|
+
class Routes
|
|
8
|
+
include ApiVersionChecker
|
|
9
|
+
|
|
10
|
+
enforces_api_version 'v3', :list, :create, :get, :update, :remove, :match
|
|
11
|
+
|
|
12
|
+
# Public: creates a new Mailgun::Routes instance.
|
|
13
|
+
# Defaults to Mailgun::Client
|
|
14
|
+
def initialize(client = Mailgun::Client.new)
|
|
15
|
+
@client = client
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Public: Get routes
|
|
19
|
+
#
|
|
20
|
+
# options - [Hash] of
|
|
21
|
+
# limit - [Integer] Maximum number of records to return. (100 by default)
|
|
22
|
+
# skip - [Integer] Number of records to skip. (0 by default)
|
|
23
|
+
#
|
|
24
|
+
# Returns [Array] A list of routes (hash)
|
|
25
|
+
def list(options = {})
|
|
26
|
+
@client.get('routes', options).to_h['items']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Public: Create a route
|
|
30
|
+
#
|
|
31
|
+
# options - [Hash] of
|
|
32
|
+
# expression - [String] The filtering rule, e.g. match_recipient(".*@example.com")
|
|
33
|
+
# action - [String, Array] Action(s) to take when the expression matches,
|
|
34
|
+
# e.g. forward("https://example.com/messages") or stop()
|
|
35
|
+
# priority - [Integer] Smaller numbers are handled first. Defaults to 0
|
|
36
|
+
# description - [String] Route description
|
|
37
|
+
#
|
|
38
|
+
# Returns [Hash] of the created route
|
|
39
|
+
def create(options = {})
|
|
40
|
+
@client.post('routes', options).to_h
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Public: Get a route
|
|
44
|
+
#
|
|
45
|
+
# route_id - [String] ID of the route
|
|
46
|
+
#
|
|
47
|
+
# Returns [Hash] Information on the requested route
|
|
48
|
+
def get(route_id)
|
|
49
|
+
require_route_id!(route_id, 'No route ID given to find')
|
|
50
|
+
|
|
51
|
+
@client.get("routes/#{route_id}").to_h!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Public: Update a route
|
|
55
|
+
#
|
|
56
|
+
# route_id - [String] ID of the route
|
|
57
|
+
# options - [Hash] of
|
|
58
|
+
# expression - [String] The filtering rule
|
|
59
|
+
# action - [String, Array] Action(s) to take when the expression matches
|
|
60
|
+
# priority - [Integer] Smaller numbers are handled first
|
|
61
|
+
# description - [String] Route description
|
|
62
|
+
#
|
|
63
|
+
# Returns [Hash] of the updated route
|
|
64
|
+
def update(route_id, options = {})
|
|
65
|
+
require_route_id!(route_id, 'No route ID given to update')
|
|
66
|
+
|
|
67
|
+
@client.put("routes/#{route_id}", options).to_h
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Public: Delete a route
|
|
71
|
+
#
|
|
72
|
+
# route_id - [String] ID of the route
|
|
73
|
+
#
|
|
74
|
+
# Returns [Boolean] if successful or not
|
|
75
|
+
def remove(route_id)
|
|
76
|
+
require_route_id!(route_id, 'No route ID given to remove')
|
|
77
|
+
|
|
78
|
+
@client.delete("routes/#{route_id}").status == 200
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Public: Find the route that handles an address
|
|
82
|
+
#
|
|
83
|
+
# address - [String] Email address to match against the routes
|
|
84
|
+
#
|
|
85
|
+
# Returns [Hash] with the matching route
|
|
86
|
+
def match(address)
|
|
87
|
+
raise(ParameterError, 'No address given to match', caller) if address.nil? || address.to_s.empty?
|
|
88
|
+
|
|
89
|
+
@client.get('routes/match', { address: address }).to_h
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
def require_route_id!(route_id, message)
|
|
95
|
+
raise(ParameterError, message, caller) if route_id.nil? || route_id.to_s.empty?
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -6,6 +6,8 @@ module Mailgun
|
|
|
6
6
|
class AnalyticsTags
|
|
7
7
|
include ApiVersionChecker
|
|
8
8
|
|
|
9
|
+
enforces_api_version 'v1', :update, :list, :remove, :limits
|
|
10
|
+
|
|
9
11
|
# Public: creates a new Mailgun::AnalyticsTags instance.
|
|
10
12
|
# Defaults to Mailgun::Client
|
|
11
13
|
def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
|
|
@@ -61,7 +63,5 @@ module Mailgun
|
|
|
61
63
|
def limits
|
|
62
64
|
@client.get('analytics/tags/limits').to_h
|
|
63
65
|
end
|
|
64
|
-
|
|
65
|
-
enforces_api_version 'v1', :update, :list, :remove, :limits
|
|
66
66
|
end
|
|
67
67
|
end
|
data/lib/mailgun/tags/tags.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Mailgun
|
|
|
21
21
|
#
|
|
22
22
|
# Returns [Array] A list of tags (hash)
|
|
23
23
|
def get_tags(domain, options = {})
|
|
24
|
-
|
|
24
|
+
warn_deprecated(__method__, 'Mailgun::AnalyticsTags#list')
|
|
25
25
|
raise(ParameterError, 'No domain given to store template on', caller) unless domain
|
|
26
26
|
|
|
27
27
|
@client.get("#{domain}/tags", options).to_h['items']
|
|
@@ -34,7 +34,7 @@ module Mailgun
|
|
|
34
34
|
#
|
|
35
35
|
# Returns [Hash] Information on the requested tag.
|
|
36
36
|
def get_tag(domain, tag)
|
|
37
|
-
|
|
37
|
+
warn_deprecated(__method__, 'Mailgun::AnalyticsTags#list')
|
|
38
38
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
39
39
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
40
40
|
|
|
@@ -50,7 +50,7 @@ module Mailgun
|
|
|
50
50
|
#
|
|
51
51
|
# Returns [Boolean] if successful or not
|
|
52
52
|
def update(domain, tag, options = {})
|
|
53
|
-
|
|
53
|
+
warn_deprecated(__method__, 'Mailgun::AnalyticsTags#update')
|
|
54
54
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
55
55
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
56
56
|
|
|
@@ -72,7 +72,7 @@ module Mailgun
|
|
|
72
72
|
#
|
|
73
73
|
# Returns [Hash] of tag stats info
|
|
74
74
|
def get_tag_stats(domain, tag, options = {})
|
|
75
|
-
|
|
75
|
+
warn_deprecated(__method__, 'Mailgun::Metrics#account_metrics')
|
|
76
76
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
77
77
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
78
78
|
|
|
@@ -87,7 +87,7 @@ module Mailgun
|
|
|
87
87
|
#
|
|
88
88
|
# Returns [Boolean] if successful or not
|
|
89
89
|
def remove(domain, tag)
|
|
90
|
-
|
|
90
|
+
warn_deprecated(__method__, 'Mailgun::AnalyticsTags#remove')
|
|
91
91
|
raise(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
|
|
92
92
|
raise(ParameterError, 'No template name given to find on provided domain', caller) unless tag
|
|
93
93
|
|
|
@@ -101,7 +101,7 @@ module Mailgun
|
|
|
101
101
|
#
|
|
102
102
|
# Returns [Hash] of countries of origin for a given domain
|
|
103
103
|
def get_countries_aggregated_stats(domain, tag)
|
|
104
|
-
|
|
104
|
+
warn_deprecated(__method__, 'Mailgun::Metrics#account_metrics')
|
|
105
105
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
106
106
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
107
107
|
|
|
@@ -115,7 +115,7 @@ module Mailgun
|
|
|
115
115
|
#
|
|
116
116
|
# Returns [Hash] of email providers for a given domain
|
|
117
117
|
def get_providers_aggregated_stats(domain, tag)
|
|
118
|
-
|
|
118
|
+
warn_deprecated(__method__, 'Mailgun::Metrics#account_metrics')
|
|
119
119
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
120
120
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
121
121
|
|
|
@@ -129,11 +129,19 @@ module Mailgun
|
|
|
129
129
|
#
|
|
130
130
|
# Returns [Hash] of devices for a given domain
|
|
131
131
|
def get_devices_aggregated_stats(domain, tag)
|
|
132
|
-
|
|
132
|
+
warn_deprecated(__method__, 'Mailgun::Metrics#account_metrics')
|
|
133
133
|
raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
|
|
134
134
|
raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
|
|
135
135
|
|
|
136
136
|
@client.get("#{domain}/tags/#{tag}/stats/aggregates/devices").to_h
|
|
137
137
|
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
# Internal: Warns that a Tags method is deprecated and names its replacement
|
|
142
|
+
def warn_deprecated(method_name, replacement)
|
|
143
|
+
Deprecation.warn("Mailgun::Tags##{method_name}", replacement,
|
|
144
|
+
reason: 'Mailgun deprecated the Tags API', removal: 'mailgun-ruby 1.5')
|
|
145
|
+
end
|
|
138
146
|
end
|
|
139
147
|
end
|
data/lib/mailgun/version.rb
CHANGED
|
@@ -6,6 +6,8 @@ module Mailgun
|
|
|
6
6
|
class AccountWebhooks
|
|
7
7
|
include ApiVersionChecker
|
|
8
8
|
|
|
9
|
+
enforces_api_version 'v1', :list, :create, :remove, :get, :update, :remove_by_id
|
|
10
|
+
|
|
9
11
|
# Public creates a new Mailgun::Webhooks instance.
|
|
10
12
|
# Defaults to Mailgun::Client
|
|
11
13
|
def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
|
|
@@ -79,7 +81,5 @@ module Mailgun
|
|
|
79
81
|
def remove_by_id(webhook_id)
|
|
80
82
|
@client.delete("webhooks/#{webhook_id}").status == 204
|
|
81
83
|
end
|
|
82
|
-
|
|
83
|
-
enforces_api_version 'v1', :list, :create, :remove, :get, :update, :remove_by_id
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -6,6 +6,9 @@ module Mailgun
|
|
|
6
6
|
class Webhooks
|
|
7
7
|
include ApiVersionChecker
|
|
8
8
|
|
|
9
|
+
enforces_api_version 'v3', :list, :get, :create, :update, :remove
|
|
10
|
+
enforces_api_version 'v4', :create_v4, :update_v4, :remove_v4
|
|
11
|
+
|
|
9
12
|
ACTIONS = %w[accepted clicked complained delivered opened permanent_fail temporary_fail unsubscribed].freeze
|
|
10
13
|
|
|
11
14
|
# Public creates a new Mailgun::Webhooks instance.
|
|
@@ -28,7 +31,7 @@ module Mailgun
|
|
|
28
31
|
# :nocov:
|
|
29
32
|
|
|
30
33
|
def get_webhooks(domain, options = {})
|
|
31
|
-
|
|
34
|
+
warn_deprecated(__method__, :list)
|
|
32
35
|
list(domain, options)
|
|
33
36
|
end
|
|
34
37
|
# :nocov:
|
|
@@ -48,7 +51,7 @@ module Mailgun
|
|
|
48
51
|
# :nocov:
|
|
49
52
|
%i[info get_webhook_url].each do |method|
|
|
50
53
|
define_method(method) do |domain, action|
|
|
51
|
-
|
|
54
|
+
warn_deprecated(method, :get)
|
|
52
55
|
get(domain, action)
|
|
53
56
|
end
|
|
54
57
|
end
|
|
@@ -58,19 +61,20 @@ module Mailgun
|
|
|
58
61
|
#
|
|
59
62
|
# domain - A String of the domain name (ex. domain.com)
|
|
60
63
|
# action - A String of the action to create a webhook for
|
|
61
|
-
# url - A String of the url of the webhook
|
|
64
|
+
# url - A String of the url of the webhook, or an Array of up to 3 urls
|
|
62
65
|
#
|
|
63
66
|
# Returns a Boolean of whether the webhook was created
|
|
64
67
|
def create(domain, action, url = '')
|
|
65
68
|
res = @client.post("domains/#{domain}/webhooks", id: action, url: url)
|
|
66
|
-
res.to_h['webhook']['urls']
|
|
69
|
+
urls = res.to_h['webhook']['urls']
|
|
70
|
+
Array(url).all? { |u| urls.include?(u) } && res.to_h['message'] == 'Webhook has been created'
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
# :nocov:
|
|
70
74
|
%i[add add_webhook].each do |method|
|
|
71
75
|
define_method(method) do |domain, action, url|
|
|
72
76
|
url ||= ''
|
|
73
|
-
|
|
77
|
+
warn_deprecated(method, :create)
|
|
74
78
|
create(domain, action, url)
|
|
75
79
|
end
|
|
76
80
|
end
|
|
@@ -84,8 +88,9 @@ module Mailgun
|
|
|
84
88
|
# Returns true or false
|
|
85
89
|
# :nocov:
|
|
86
90
|
%i[create_all add_all_webhooks].each do |method|
|
|
87
|
-
define_method(method) do |domain|
|
|
88
|
-
|
|
91
|
+
define_method(method) do |domain, url|
|
|
92
|
+
url ||= ''
|
|
93
|
+
warn_deprecated(method, :create)
|
|
89
94
|
|
|
90
95
|
ACTIONS.each do |action|
|
|
91
96
|
create domain, action, url
|
|
@@ -97,13 +102,13 @@ module Mailgun
|
|
|
97
102
|
# Public: Update webhook
|
|
98
103
|
#
|
|
99
104
|
# domain - A String of the domain name (ex. domain.com)
|
|
100
|
-
# action - A String of the action to
|
|
101
|
-
# url - A String of the url of the webhook
|
|
105
|
+
# action - A String of the action to update the webhook for
|
|
106
|
+
# url - A String of the url of the webhook, or an Array of up to 3 urls
|
|
102
107
|
#
|
|
103
108
|
# Returns a Boolean of whether the webhook was updated
|
|
104
109
|
def update(domain, action, url = '')
|
|
105
|
-
raise Mailgun::ParameterError
|
|
106
|
-
raise Mailgun::ParameterError
|
|
110
|
+
raise Mailgun::ParameterError, 'Domain not provided to update webhooks' if domain.to_s.empty?
|
|
111
|
+
raise Mailgun::ParameterError, 'Action not provided to identify webhook to update' if action.to_s.empty?
|
|
107
112
|
|
|
108
113
|
res = @client.put("domains/#{domain}/webhooks/#{action}", id: action, url: url)
|
|
109
114
|
res.to_h['message'] == 'Webhook has been updated'
|
|
@@ -111,7 +116,7 @@ module Mailgun
|
|
|
111
116
|
|
|
112
117
|
# :nocov:
|
|
113
118
|
def update_webhook(domain, action, url = '')
|
|
114
|
-
|
|
119
|
+
warn_deprecated(__method__, :update)
|
|
115
120
|
update(domain, action, url)
|
|
116
121
|
end
|
|
117
122
|
# :nocov:
|
|
@@ -123,8 +128,8 @@ module Mailgun
|
|
|
123
128
|
#
|
|
124
129
|
# Returns a Boolean of the success
|
|
125
130
|
def remove(domain, action)
|
|
126
|
-
raise Mailgun::ParameterError
|
|
127
|
-
raise Mailgun::ParameterError
|
|
131
|
+
raise Mailgun::ParameterError, 'Domain not provided to remove webhook from' if domain.to_s.empty?
|
|
132
|
+
raise Mailgun::ParameterError, 'Action not provided to identify webhook to remove' if action.to_s.empty?
|
|
128
133
|
|
|
129
134
|
@client.delete("domains/#{domain}/webhooks/#{action}").to_h['message'] == 'Webhook has been deleted'
|
|
130
135
|
end
|
|
@@ -132,7 +137,7 @@ module Mailgun
|
|
|
132
137
|
# :nocov:
|
|
133
138
|
%i[delete delete_webhook].each do |method|
|
|
134
139
|
define_method(method) do |domain, action|
|
|
135
|
-
|
|
140
|
+
warn_deprecated(method, :remove)
|
|
136
141
|
remove(domain, action)
|
|
137
142
|
end
|
|
138
143
|
end
|
|
@@ -146,9 +151,9 @@ module Mailgun
|
|
|
146
151
|
# :nocov:
|
|
147
152
|
%i[remove_all delete_all delete_all_webooks].each do |method|
|
|
148
153
|
define_method(method) do |domain|
|
|
149
|
-
|
|
154
|
+
warn_deprecated(method, :remove)
|
|
150
155
|
|
|
151
|
-
raise Mailgun::ParameterError
|
|
156
|
+
raise Mailgun::ParameterError, 'Domain not provided to remove webhooks from' if domain.to_s.empty?
|
|
152
157
|
|
|
153
158
|
ACTIONS.each do |action|
|
|
154
159
|
remove domain, action
|
|
@@ -157,6 +162,48 @@ module Mailgun
|
|
|
157
162
|
end
|
|
158
163
|
# :nocov:
|
|
159
164
|
|
|
160
|
-
|
|
165
|
+
# Public: Create webhooks for multiple event types (v4)
|
|
166
|
+
#
|
|
167
|
+
# domain - [String] The domain name to create webhooks for
|
|
168
|
+
# url - [String] The webhook URL that will receive POST requests
|
|
169
|
+
# event_types - [String, Array<String>] Event types to associate with the URL
|
|
170
|
+
#
|
|
171
|
+
# Returns a Hash of the domain webhooks keyed by event type
|
|
172
|
+
def create_v4(domain, url:, event_types:)
|
|
173
|
+
res = @client.post("domains/#{domain}/webhooks", { url: url, event_types: event_types })
|
|
174
|
+
res.to_h['webhooks']
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Public: Update the event types associated with a webhook URL (v4)
|
|
178
|
+
#
|
|
179
|
+
# domain - [String] The domain name to update webhooks for
|
|
180
|
+
# url - [String] The webhook URL to update
|
|
181
|
+
# event_types - [String, Array<String>] Event types to associate with the URL.
|
|
182
|
+
# Replaces the existing associations.
|
|
183
|
+
#
|
|
184
|
+
# Returns a Hash of the domain webhooks keyed by event type
|
|
185
|
+
def update_v4(domain, url:, event_types:)
|
|
186
|
+
res = @client.put("domains/#{domain}/webhooks", { url: url, event_types: event_types })
|
|
187
|
+
res.to_h['webhooks']
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Public: Delete webhook URLs from all event types they are associated with (v4)
|
|
191
|
+
#
|
|
192
|
+
# domain - [String] The domain name to delete webhooks from
|
|
193
|
+
# url - [String, Array<String>] The webhook URL(s) to delete
|
|
194
|
+
#
|
|
195
|
+
# Returns a Hash of the remaining domain webhooks keyed by event type
|
|
196
|
+
def remove_v4(domain, url:)
|
|
197
|
+
res = @client.delete("domains/#{domain}/webhooks", { url: url })
|
|
198
|
+
res.to_h['webhooks']
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
private
|
|
202
|
+
|
|
203
|
+
# Internal: Warns that a Webhooks method is deprecated and names its replacement
|
|
204
|
+
def warn_deprecated(method_name, replacement)
|
|
205
|
+
Deprecation.warn("Mailgun::Webhooks##{method_name}", "Mailgun::Webhooks##{replacement}",
|
|
206
|
+
removal: 'a future version of mailgun-ruby')
|
|
207
|
+
end
|
|
161
208
|
end
|
|
162
209
|
end
|
data/lib/mailgun.rb
CHANGED
|
@@ -23,6 +23,7 @@ Zeitwerk::Loader.for_gem.tap do |loader|
|
|
|
23
23
|
loader.ignore("#{__dir__}/railgun.rb")
|
|
24
24
|
loader.ignore("#{__dir__}/railgun")
|
|
25
25
|
|
|
26
|
+
loader.collapse("#{__dir__}/mailgun/api_keys")
|
|
26
27
|
loader.collapse("#{__dir__}/mailgun/analytics_tags")
|
|
27
28
|
loader.collapse("#{__dir__}/mailgun/domains")
|
|
28
29
|
loader.collapse("#{__dir__}/mailgun/events")
|
|
@@ -32,6 +33,7 @@ Zeitwerk::Loader.for_gem.tap do |loader|
|
|
|
32
33
|
loader.collapse("#{__dir__}/mailgun/logs")
|
|
33
34
|
loader.collapse("#{__dir__}/mailgun/messages")
|
|
34
35
|
loader.collapse("#{__dir__}/mailgun/metrics")
|
|
36
|
+
loader.collapse("#{__dir__}/mailgun/routes")
|
|
35
37
|
loader.collapse("#{__dir__}/mailgun/subaccounts")
|
|
36
38
|
loader.collapse("#{__dir__}/mailgun/tags")
|
|
37
39
|
loader.collapse("#{__dir__}/mailgun/templates")
|