mailgun-ruby 1.4.5 → 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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -1
  3. data/README.md +3 -1
  4. data/lib/mailgun/api_keys/api_keys.rb +2 -2
  5. data/lib/mailgun/client.rb +1 -1
  6. data/lib/mailgun/domains/domain_keys.rb +5 -5
  7. data/lib/mailgun/domains/domains.rb +12 -9
  8. data/lib/mailgun/events/events.rb +1 -1
  9. data/lib/mailgun/helpers/api_version_checker.rb +23 -12
  10. data/lib/mailgun/helpers/deprecation.rb +32 -0
  11. data/lib/mailgun/lists/mailing_lists.rb +250 -0
  12. data/lib/mailgun/messages/message_builder.rb +17 -7
  13. data/lib/mailgun/response.rb +1 -1
  14. data/lib/mailgun/routes/routes.rb +98 -0
  15. data/lib/mailgun/tags/analytics_tags.rb +2 -2
  16. data/lib/mailgun/tags/tags.rb +16 -8
  17. data/lib/mailgun/version.rb +1 -1
  18. data/lib/mailgun/webhooks/account_webhooks.rb +2 -2
  19. data/lib/mailgun/webhooks/webhooks.rb +17 -9
  20. data/lib/mailgun.rb +1 -0
  21. metadata +6 -326
  22. data/.github/workflows/ci.yml +0 -49
  23. data/.github_changelog_generator +0 -1
  24. data/.gitignore +0 -24
  25. data/.rubocop.yml +0 -68
  26. data/.ruby-env.yml.example +0 -13
  27. data/Gemfile +0 -9
  28. data/Rakefile +0 -32
  29. data/docs/AccountWebhooks.md +0 -55
  30. data/docs/AnalyticsTags.md +0 -63
  31. data/docs/ApiKeys.md +0 -65
  32. data/docs/DomainKeys.md +0 -49
  33. data/docs/Domains.md +0 -82
  34. data/docs/EmailValidation.md +0 -34
  35. data/docs/Events.md +0 -48
  36. data/docs/Logs.md +0 -67
  37. data/docs/MessageBuilder.md +0 -120
  38. data/docs/Metrics.md +0 -108
  39. data/docs/OptInHandler.md +0 -103
  40. data/docs/Snippets.md +0 -519
  41. data/docs/Subaccounts.md +0 -68
  42. data/docs/Suppressions.md +0 -92
  43. data/docs/Templates.md +0 -92
  44. data/docs/Webhooks.md +0 -65
  45. data/docs/railgun/EmailValidation.md +0 -34
  46. data/docs/railgun/Overview.md +0 -11
  47. data/docs/railgun/Parameters.md +0 -83
  48. data/mailgun.gemspec +0 -47
  49. data/spec/integration/account_webhooks_spec.rb +0 -57
  50. data/spec/integration/analytics_tags_spec.rb +0 -54
  51. data/spec/integration/api_keys_spec.rb +0 -50
  52. data/spec/integration/bounces_spec.rb +0 -45
  53. data/spec/integration/campaign_spec.rb +0 -62
  54. data/spec/integration/complaints_spec.rb +0 -40
  55. data/spec/integration/domain_keys_spec.rb +0 -124
  56. data/spec/integration/domains_spec.rb +0 -201
  57. data/spec/integration/email_validation_spec.rb +0 -73
  58. data/spec/integration/events_spec.rb +0 -28
  59. data/spec/integration/list_members_spec.rb +0 -64
  60. data/spec/integration/list_spec.rb +0 -59
  61. data/spec/integration/logs_spec.rb +0 -105
  62. data/spec/integration/mailer_spec.rb +0 -65
  63. data/spec/integration/mailgun_spec.rb +0 -198
  64. data/spec/integration/messages/sample_data/mime.txt +0 -38
  65. data/spec/integration/metrics_spec.rb +0 -224
  66. data/spec/integration/routes_spec.rb +0 -91
  67. data/spec/integration/stats_spec.rb +0 -17
  68. data/spec/integration/subaccounts_spec.rb +0 -57
  69. data/spec/integration/suppressions_spec.rb +0 -320
  70. data/spec/integration/templates_spec.rb +0 -137
  71. data/spec/integration/unsubscribes_spec.rb +0 -44
  72. data/spec/integration/webhook_spec.rb +0 -79
  73. data/spec/spec_helper.rb +0 -53
  74. data/spec/unit/client_spec.rb +0 -448
  75. data/spec/unit/connection/test_client.rb +0 -169
  76. data/spec/unit/events/events_spec.rb +0 -88
  77. data/spec/unit/exceptions/exceptions_spec.rb +0 -31
  78. data/spec/unit/helpers/api_version_checker_spec.rb +0 -206
  79. data/spec/unit/lists/opt_in_handler_spec.rb +0 -28
  80. data/spec/unit/mailgun_spec.rb +0 -171
  81. data/spec/unit/messages/batch_message_spec.rb +0 -148
  82. data/spec/unit/messages/message_builder_spec.rb +0 -745
  83. data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
  84. data/spec/unit/messages/sample_data/mime.txt +0 -38
  85. data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
  86. data/spec/unit/messages/sample_data/unknown.type +0 -0
  87. data/spec/unit/railgun/content_type_spec.rb +0 -89
  88. data/spec/unit/railgun/mailer_spec.rb +0 -391
  89. data/spec/unit/response_spec.rb +0 -225
  90. data/spec/unit/webhooks_spec.rb +0 -121
  91. data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +0 -55
  92. data/vcr_cassettes/account_webhooks.yml +0 -269
  93. data/vcr_cassettes/analytics_tags.yml +0 -187
  94. data/vcr_cassettes/api_keys.yml +0 -212
  95. data/vcr_cassettes/bounces.yml +0 -136
  96. data/vcr_cassettes/complaints.yml +0 -315
  97. data/vcr_cassettes/domains.todo.yml +0 -42
  98. data/vcr_cassettes/domains.yml +0 -1243
  99. data/vcr_cassettes/email_validation.yml +0 -152
  100. data/vcr_cassettes/events.yml +0 -69
  101. data/vcr_cassettes/exceptions-invalid-api-key.yml +0 -52
  102. data/vcr_cassettes/exceptions-invalid-data.yml +0 -52
  103. data/vcr_cassettes/exceptions-not-allowed.yml +0 -54
  104. data/vcr_cassettes/exceptions.yml +0 -92
  105. data/vcr_cassettes/list_members.yml +0 -328
  106. data/vcr_cassettes/logs.yml +0 -53
  107. data/vcr_cassettes/mailer_invalid_domain.yml +0 -109
  108. data/vcr_cassettes/mailing_list.todo.yml +0 -43
  109. data/vcr_cassettes/mailing_list.yml +0 -682
  110. data/vcr_cassettes/message_deliver.yml +0 -149
  111. data/vcr_cassettes/metrics.yml +0 -116
  112. data/vcr_cassettes/routes.yml +0 -359
  113. data/vcr_cassettes/send_message.yml +0 -158
  114. data/vcr_cassettes/stats.yml +0 -48
  115. data/vcr_cassettes/subaccounts.yml +0 -270
  116. data/vcr_cassettes/suppressions.yml +0 -1392
  117. data/vcr_cassettes/templates.yml +0 -1065
  118. data/vcr_cassettes/unsubscribes.yml +0 -401
  119. data/vcr_cassettes/webhooks.yml +0 -246
  120. data/vcr_cassettes/webhooks_v4.yml +0 -275
@@ -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
@@ -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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
- warn('This API is deprecated in favor of our new analytics Tags API')
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # It's the version. Yeay!
4
4
  module Mailgun
5
- VERSION = '1.4.5'
5
+ VERSION = '1.4.6'
6
6
  end
@@ -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
- warn('`get_webhooks` method will be deprecated in future versions of Mailgun. Please use `list` instead.')
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
- warn("`#{method}` method will be deprecated in future versions of Mailgun. Please use `get` instead.")
54
+ warn_deprecated(method, :get)
52
55
  get(domain, action)
53
56
  end
54
57
  end
@@ -71,7 +74,7 @@ module Mailgun
71
74
  %i[add add_webhook].each do |method|
72
75
  define_method(method) do |domain, action, url|
73
76
  url ||= ''
74
- warn("`#{method}` method will be deprecated in future versions of Mailgun. Please use `create` instead.")
77
+ warn_deprecated(method, :create)
75
78
  create(domain, action, url)
76
79
  end
77
80
  end
@@ -87,7 +90,7 @@ module Mailgun
87
90
  %i[create_all add_all_webhooks].each do |method|
88
91
  define_method(method) do |domain, url|
89
92
  url ||= ''
90
- warn("`#{method}` method will be deprecated in future versions of Mailgun. Please use `create` instead.")
93
+ warn_deprecated(method, :create)
91
94
 
92
95
  ACTIONS.each do |action|
93
96
  create domain, action, url
@@ -113,7 +116,7 @@ module Mailgun
113
116
 
114
117
  # :nocov:
115
118
  def update_webhook(domain, action, url = '')
116
- warn('`update_webhook` method will be deprecated in future versions of Mailgun. Please use `update` instead.')
119
+ warn_deprecated(__method__, :update)
117
120
  update(domain, action, url)
118
121
  end
119
122
  # :nocov:
@@ -134,7 +137,7 @@ module Mailgun
134
137
  # :nocov:
135
138
  %i[delete delete_webhook].each do |method|
136
139
  define_method(method) do |domain, action|
137
- warn("`#{method}` method will be deprecated in future versions of Mailgun. Please use `remove` instead.")
140
+ warn_deprecated(method, :remove)
138
141
  remove(domain, action)
139
142
  end
140
143
  end
@@ -148,7 +151,7 @@ module Mailgun
148
151
  # :nocov:
149
152
  %i[remove_all delete_all delete_all_webooks].each do |method|
150
153
  define_method(method) do |domain|
151
- warn("`#{method}` method will be deprecated in future versions of Mailgun. Please use `remove` instead.")
154
+ warn_deprecated(method, :remove)
152
155
 
153
156
  raise Mailgun::ParameterError, 'Domain not provided to remove webhooks from' if domain.to_s.empty?
154
157
 
@@ -195,7 +198,12 @@ module Mailgun
195
198
  res.to_h['webhooks']
196
199
  end
197
200
 
198
- enforces_api_version 'v3', :list, :get, :create, :update, :remove
199
- enforces_api_version 'v4', :create_v4, :update_v4, :remove_v4
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
200
208
  end
201
209
  end
data/lib/mailgun.rb CHANGED
@@ -33,6 +33,7 @@ Zeitwerk::Loader.for_gem.tap do |loader|
33
33
  loader.collapse("#{__dir__}/mailgun/logs")
34
34
  loader.collapse("#{__dir__}/mailgun/messages")
35
35
  loader.collapse("#{__dir__}/mailgun/metrics")
36
+ loader.collapse("#{__dir__}/mailgun/routes")
36
37
  loader.collapse("#{__dir__}/mailgun/subaccounts")
37
38
  loader.collapse("#{__dir__}/mailgun/tags")
38
39
  loader.collapse("#{__dir__}/mailgun/templates")