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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffd33ded9bd33ca044bbe54fc8d89a876bb9949fb91c98ef0f677cc0ca82f4f5
4
- data.tar.gz: 7d4ba505f5b1de914fc360b23f64d14497e40e6ca01ecb4e8421560c0404e36d
3
+ metadata.gz: 335c9306bcba99a231c0346ae15845bf458f76b673246d2c22b1359b846f1a55
4
+ data.tar.gz: ef5b9d5c4af263b98e9bc9384f4e800fe06bea4919a2db0a7710deb14c12e001
5
5
  SHA512:
6
- metadata.gz: bfea517bd1e392add5a730c417a8aa479279503a574b9855e22a37a8bf1da56c8d972900173fbecb1cc39b73cf0c5eb6772a44b3681c3f2566c5ce9ff2aa4559
7
- data.tar.gz: 739a82133f746ad9117dbd6655dec76324de3b1cf3394c2c35672a44306e9cab643e7b29174f7cd2823a477d82e174cbb68a40cf21c54f4dd007dc0c528c1ac0
6
+ metadata.gz: 5ee12a7c01d4d978f520eede84647b49e5c44434dc8040cbd1a75596c7580b6f25a40f3caad2db727cafe0b320e5d48ea93a278cf0bab4fba193ccd6ba7be0dd
7
+ data.tar.gz: bab9b97bd1ea0c7ad3c872c6ed1ebe4f0d4d8db77272207aa5d6e57f92c129cae048fec5b5bcdec30b55aa44ccccf5a8226af6fa5443f0ba69cae7a08ab04f16
@@ -0,0 +1,218 @@
1
+ # 3.2.1
2
+
3
+ * Fixed outdated changelog_uri
4
+
5
+ # 3.2.0
6
+
7
+ * Added update_web_prefix method
8
+
9
+ * Added update_dkim_selector method
10
+
11
+ * Added update_dkim_authority method
12
+
13
+ * Added verify_domain method (#23)
14
+
15
+ # 3.1.1
16
+
17
+ * Fixed missing keyword argument in Mailgunner::Client#get_whitelists method
18
+
19
+ * Fixed last argument as keyword parameters deprecation warning on Ruby 2.7
20
+
21
+ # 3.1.0
22
+
23
+ * Allow delivery method settings to be modified before delivery (#22)
24
+
25
+ # 3.0.0
26
+
27
+ * Changed required_ruby_version to >= 2.5.0
28
+
29
+ * Added Mailgunner::Config class
30
+
31
+ You can now configure options globally. For example:
32
+
33
+ Mailgunner.configure do |config|
34
+ config.api_host = 'api.eu.mailgun.net'
35
+ end
36
+
37
+ This may or may not be a breaking change, depending on how you are currently initializing client objects.
38
+
39
+ * Added Mailgunner::Struct class
40
+
41
+ Return values are now instances of the Mailgunner::Struct class. You can access nested keys in various ways:
42
+
43
+ response.items
44
+ response['items']
45
+ response[:items]
46
+ response.to_h.dig('items')
47
+
48
+ This may or may not be a breaking change, depending on how you are currently using return values.
49
+
50
+ * Added parsing of error messages in response bodies
51
+
52
+ * Removed Mailgunner::Client#get_stats method
53
+
54
+ * Removed Mailgunner::Client#parse_addresses method
55
+
56
+ * Changed Mailgunner::Client#validate_address to v4 endpoint
57
+
58
+ * Changed Mailgunner::Client#get_lists method to new endpoint
59
+
60
+ * Changed Mailgunner::Client#get_list_members method to new endpoint
61
+
62
+ * Added Mailgunner::Client#get_bulk_validations method
63
+
64
+ * Added Mailgunner::Client#create_bulk_validation method
65
+
66
+ * Added Mailgunner::Client#get_bulk_validation method
67
+
68
+ * Added Mailgunner::Client#cancel_bulk_validation method
69
+
70
+ * Added Mailgunner::Client#get_whitelists method
71
+
72
+ * Added Mailgunner::Client#get_whitelist method
73
+
74
+ * Added Mailgunner::Client#add_whitelist method
75
+
76
+ * Added Mailgunner::Client#delete_whitelist method
77
+
78
+ * Added Mailgunner::Client#get_tracking_settings method
79
+
80
+ * Added Mailgunner::Client#update_open_tracking_settings method
81
+
82
+ * Added Mailgunner::Client#update_click_tracking_settings method
83
+
84
+ * Added Mailgunner::Client#update_unsubscribe_tracking_settings method
85
+
86
+ # 2.6.0
87
+
88
+ * Added `api_host` option for EU region (thanks @drummerroma and @markoudev)
89
+
90
+ * Added Mailgunner::Client#get_all_ips method
91
+
92
+ * Added Mailgunner::Client#get_ip method
93
+
94
+ * Added Mailgunner::Client#get_ips method
95
+
96
+ * Added Mailgunner::Client#add_ip method
97
+
98
+ * Added Mailgunner::Client#delete_ip method
99
+
100
+ * Removed legacy campaign methods
101
+
102
+ # 2.5.0
103
+
104
+ * Fixed compatibility with mail v2.6.6+ (#13)
105
+
106
+ * Added Mailgunner::Client#get_webhooks method
107
+
108
+ * Added Mailgunner::Client#get_webhook method
109
+
110
+ * Added Mailgunner::Client#add_webhook method
111
+
112
+ * Added Mailgunner::Client#update_webhook method
113
+
114
+ * Added Mailgunner::Client#delete_webhook method
115
+
116
+ * Added Mailgun::AuthenticationError exception class
117
+
118
+ * Added Mailgun::ClientError exception class
119
+
120
+ * Added Mailgun::ServerError exception class
121
+
122
+ # 2.4.0
123
+
124
+ * Fixed Rails load order issue when specifying mailgun_settings (#10)
125
+
126
+ * Added Mailgunner::Client#get_connection_settings method
127
+
128
+ * Added Mailgunner::Client#update_connection_settings method
129
+
130
+ * Added Mailgunner::Client#get_tags method
131
+
132
+ * Added Mailgunner::Client#get_tag method
133
+
134
+ * Added Mailgunner::Client#update_tag method
135
+
136
+ * Added Mailgunner::Client#get_tag_stats method
137
+
138
+ * Added Mailgunner::Client#delete_tag method
139
+
140
+ * Added Mailgunner::Client#delete_bounces method
141
+
142
+ # 2.3.0
143
+
144
+ * Added Mailgunner::Client#get_total_stats method
145
+
146
+ * Deprecated Mailgunner::Client#get_stats method
147
+
148
+ * Removed Mailgunner::Client#get_list_stats method
149
+
150
+ # 2.2.2
151
+
152
+ * Fixed cc and bcc recipients not included in multipart sends (#9)
153
+
154
+ # 2.2.1
155
+
156
+ * Fixed Rails load order issue (#8)
157
+
158
+ # 2.2.0
159
+
160
+ * Added Mailgunner::Client#get_message method
161
+
162
+ * Added Mailgunner::Client#get_mime_message method
163
+
164
+ * Added Mailgunner::Client#delete_message method
165
+
166
+ * Updated API version prefix from v2 to v3
167
+
168
+ # 2.1.0
169
+
170
+ * Mailgunner::DeliveryMethod can now be used with Mail directly
171
+
172
+ * An exception is now raised when calling domain methods if the domain is not provided
173
+
174
+ * The api_key option can now be specified in ActionMailer::Base.mailgun_settings
175
+
176
+ # 2.0.0
177
+
178
+ * Removed deprecated :json option
179
+
180
+ * Removed Mailgunner::Response class in favour of using exceptions to signal errors
181
+
182
+ * Added Mailgunner::Client#delete_domain method
183
+
184
+ * Added Mailgunner::Client methods for managing SMTP credentials
185
+
186
+ # 1.3.0
187
+
188
+ * Added [ActionMailer](https://rubygems.org/gems/actionmailer) integration
189
+
190
+ * Added Mailgunner::Client#send_mime method for sending [mail](https://rubygems.org/gems/mail) objects in MIME format
191
+
192
+ * Fixed default behaviour to allow for nil domain
193
+
194
+ * Removed deprecated Mailgunner::Client#get_log method
195
+
196
+ * Removed deprecated mailbox methods
197
+
198
+ * Removed deprecated json accessor methods
199
+
200
+ # 1.2.0
201
+
202
+ * Added methods for the new [Email Validation endpoint](http://documentation.mailgun.com/api-email-validation.html)
203
+
204
+ * Added Mailgunner::Client#get_events method for the new [Events API endpoint](http://documentation.mailgun.com/api-events.html)
205
+
206
+ * Deprecated the Mailgunner::Client#get_log method (use Mailgunner::Client#get_events instead)
207
+
208
+ # 1.1.0
209
+
210
+ * Fixed use of insecure JSON.load
211
+
212
+ * Deprecated the mailbox methods (legacy Mailgun feature)
213
+
214
+ * Deprecated the :json option and associated accessor methods
215
+
216
+ # 1.0.0
217
+
218
+ * First version!
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2018 TIMCRAFT
1
+ Copyright (c) 2012-2020 TIMCRAFT
2
2
 
3
3
  This is an Open Source project licensed under the terms of the LGPLv3 license.
4
4
  Please see <http://www.gnu.org/licenses/lgpl-3.0.html> for license text.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # mailgunner
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/mailgunner.svg)](https://badge.fury.io/rb/mailgunner) [![Build Status](https://api.travis-ci.org/readysteady/mailgunner.svg?branch=master)](https://travis-ci.org/readysteady/mailgunner)
3
+ ![Gem Version](https://badge.fury.io/rb/mailgunner.svg)
4
+ ![Build Status](https://github.com/readysteady/mailgunner/workflows/Test/badge.svg)
4
5
 
5
6
 
6
7
  Ruby client for the [Mailgun API](https://documentation.mailgun.com/en/latest/api_reference.html).
@@ -11,20 +12,20 @@ Ruby client for the [Mailgun API](https://documentation.mailgun.com/en/latest/ap
11
12
  $ gem install mailgunner
12
13
 
13
14
 
14
- ## Quick start
15
+ ## Usage
15
16
 
16
17
  ```ruby
17
18
  require 'mailgunner'
18
19
 
19
- mailgun = Mailgunner::Client.new({
20
- domain: 'samples.mailgun.org',
21
- api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
22
- })
20
+ Mailgunner.configure do |config|
21
+ config.domain = 'samples.mailgun.org'
22
+ config.api_key = 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
23
+ end
23
24
 
24
- response = mailgun.get_domains
25
+ mailgun = Mailgunner::Client.new
25
26
 
26
- response['items'].each do |item|
27
- p item.values_at('id', 'name')
27
+ mailgun.get_domains.items.each do |item|
28
+ puts "#{item.id} #{item.name}"
28
29
  end
29
30
  ```
30
31
 
@@ -62,30 +63,12 @@ Outside of Rails you can set `ActionMailer::Base.delivery_method` directly.
62
63
 
63
64
  ## Specifying the region
64
65
 
65
- Mailgun offers both a US and EU region to send your e-mail from. Mailgunner uses
66
+ Mailgun offers both a US and EU region to send your email from. Mailgunner uses
66
67
  the US region by default. If you wish to use the EU region set the `api_host`
67
68
  config option like so:
68
69
 
69
70
  ```ruby
70
- mailgun = Mailgunner::Client.new({
71
- domain: 'eu.samples.mailgun.org',
72
- api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0',
73
- api_host: 'api.eu.mailgun.net'
74
- })
75
- ```
76
-
77
-
78
- ## Email validation
79
-
80
- If you only need to use Mailgun's [email address validation service](http://documentation.mailgun.com/api-email-validation.html),
81
- you can instead use your Mailgun public key to authenticate like this:
82
-
83
- ```ruby
84
- require 'mailgunner'
85
-
86
- public_key = 'pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7'
87
-
88
- mailgun = Mailgunner::Client.new(api_key: public_key)
89
-
90
- response = mailgun.validate_address('john@gmail.com')
71
+ Mailgunner.configure do |config|
72
+ config.api_host = 'api.eu.mailgun.net'
73
+ end
91
74
  ```
@@ -1,5 +1,8 @@
1
1
  require 'mailgunner/version'
2
2
  require 'mailgunner/errors'
3
+ require 'mailgunner/params'
4
+ require 'mailgunner/config'
5
+ require 'mailgunner/struct'
3
6
  require 'mailgunner/client'
4
7
  require 'mailgunner/client/domains'
5
8
  require 'mailgunner/client/email_validation'
@@ -14,3 +17,13 @@ require 'mailgunner/client/tags'
14
17
  require 'mailgunner/client/webhooks'
15
18
  require 'mailgunner/delivery_method' if defined?(Mail)
16
19
  require 'mailgunner/railtie' if defined?(Rails)
20
+
21
+ module Mailgunner
22
+ def self.config
23
+ @config ||= Config.new
24
+ end
25
+
26
+ def self.configure
27
+ yield config
28
+ end
29
+ end
@@ -1,18 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
  require 'net/http'
3
3
  require 'json'
4
- require 'cgi'
5
4
 
6
5
  module Mailgunner
7
6
  class Client
8
- attr_accessor :domain, :api_key, :http
7
+ def initialize(domain: nil, api_key: nil, api_host: nil)
8
+ @domain = domain || Mailgunner.config.domain
9
9
 
10
- def initialize(options = {})
11
- @domain = options.fetch(:domain) { default_domain }
10
+ @api_key = api_key || Mailgunner.config.api_key
12
11
 
13
- @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }
14
-
15
- @api_host = options.fetch(:api_host) { 'api.mailgun.net' }
12
+ @api_host = api_host || Mailgunner.config.api_host
16
13
 
17
14
  @http = Net::HTTP.new(@api_host, Net::HTTP.https_default_port)
18
15
 
@@ -21,21 +18,20 @@ module Mailgunner
21
18
 
22
19
  private
23
20
 
24
- def default_domain
25
- return NoDomainProvided unless ENV.key?('MAILGUN_SMTP_LOGIN')
21
+ ATTRIBUTES = PARAMS = HEADERS = {}.freeze
26
22
 
27
- ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last
28
- end
23
+ def get(path, query: PARAMS, headers: HEADERS)
24
+ uri = URI(path)
25
+ uri.query = Params.encode(query) unless query.empty?
29
26
 
30
- def get(path, params = {}, headers = {})
31
- request = Net::HTTP::Get.new(request_uri(path, params))
27
+ request = Net::HTTP::Get.new(uri.to_s)
32
28
 
33
29
  headers.each { |k, v| request[k] = v }
34
30
 
35
31
  transmit(request)
36
32
  end
37
33
 
38
- def post(path, attributes = {})
34
+ def post(path, attributes = ATTRIBUTES)
39
35
  transmit(Net::HTTP::Post.new(path)) { |message| message.set_form_data(attributes) }
40
36
  end
41
37
 
@@ -43,7 +39,7 @@ module Mailgunner
43
39
  transmit(Net::HTTP::Post.new(path)) { |message| message.set_form(data, 'multipart/form-data') }
44
40
  end
45
41
 
46
- def put(path, attributes = {})
42
+ def put(path, attributes = ATTRIBUTES)
47
43
  transmit(Net::HTTP::Put.new(path)) { |message| message.set_form_data(attributes) }
48
44
  end
49
45
 
@@ -51,52 +47,27 @@ module Mailgunner
51
47
  transmit(Net::HTTP::Delete.new(path))
52
48
  end
53
49
 
54
- USER_AGENT = "Ruby/#{RUBY_VERSION} Mailgunner/#{VERSION}"
55
-
56
50
  def transmit(message)
57
51
  message.basic_auth('api', @api_key)
58
- message['User-Agent'] = USER_AGENT
52
+ message['User-Agent'] = Mailgunner.config.user_agent
59
53
 
60
54
  yield message if block_given?
61
55
 
62
- parse(@http.request(message))
63
- end
56
+ response = @http.request(message)
64
57
 
65
- def parse(response)
66
- case response
67
- when Net::HTTPSuccess
68
- parse_success(response)
69
- when Net::HTTPUnauthorized
70
- raise AuthenticationError, "HTTP #{response.code}"
71
- when Net::HTTPClientError
72
- raise ClientError, "HTTP #{response.code}"
73
- when Net::HTTPServerError
74
- raise ServerError, "HTTP #{response.code}"
75
- else
76
- raise Error, "HTTP #{response.code}"
58
+ unless response.is_a?(Net::HTTPSuccess)
59
+ raise Error.parse(response)
77
60
  end
78
- end
79
61
 
80
- def parse_success(response)
81
- return JSON.parse(response.body) if json?(response)
62
+ if response['Content-Type']&.start_with?('application/json')
63
+ return JSON.parse(response.body, object_class: Struct)
64
+ end
82
65
 
83
66
  response.body
84
67
  end
85
68
 
86
- def json?(response)
87
- content_type = response['Content-Type']
88
-
89
- content_type && content_type.split(';').first == 'application/json'
90
- end
91
-
92
- def request_uri(path, params)
93
- return path if params.empty?
94
-
95
- path + '?' + params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
96
- end
97
-
98
69
  def escape(component)
99
- CGI.escape(component.to_s)
70
+ Params.escape(component)
100
71
  end
101
72
  end
102
73
  end