mailgun-ruby 1.2.6 → 1.2.7

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: 9dd7b99f66b317ffcbf86172b1534cdcb0ccf4b0b25a7b2e58599f20ef021f11
4
- data.tar.gz: 8b130d3344fe905d20d4230cb8b178d29b092ffa6d21c3dbb085376aa53b50a0
3
+ metadata.gz: b6f8edf9d12225755a4ddaba5a1974b8ccc30f4b150d9880a5dc174d0612c619
4
+ data.tar.gz: c676969ade04f6b2e8d2322ff68922d5065e5ca1720eeb821aa429849fddc7b5
5
5
  SHA512:
6
- metadata.gz: 34729e98ab4eb8cbfd04bdb5b7a090a30cb4a1961de9ef38e0adcab2d452e5873477d9b45de9703a6c5885b272a3d62429ece40ff6029bff2bbb0d8585a89410
7
- data.tar.gz: 235e7aed52a937315019498bbb710e90b97128d9fdfad86bfb0995daf9d25f8185683769fd84b32e4eda4c64774b49a708a57da90ccd473e7d69f0e967eed581
6
+ metadata.gz: dac9ef370272bed2a8bd78080dbc8e322aae34fe4fa9639d5c35c1de008d088ab8845355c96bac3efd331f43803cf9834047e7843620cc8602efd380aa6b8ae4
7
+ data.tar.gz: 1cc92c4983c7f3e2b94e0ae577caf8b0010e5e08d6e453adba658acce942186c3b443dbca4930feeeea4bfdaab16a5cfb2bc245ffdd42571de323f4abbbc9c52
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem install mailgun-ruby
19
19
  Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'mailgun-ruby', '~>1.2.6'
22
+ gem 'mailgun-ruby', '~>1.2.7'
23
23
  ```
24
24
 
25
25
  Usage
@@ -188,6 +188,7 @@ This SDK includes the following components:
188
188
  - [Webhooks](docs/Webhooks.md)
189
189
  - [Events](docs/Events.md)
190
190
  - [Suppressions](docs/Suppressions.md)
191
+ - [Templates](docs/Templates.md)
191
192
 
192
193
  Message Builder allows you to quickly create the array of parameters, required
193
194
  to send a message, by calling a methods for each parameter.
@@ -0,0 +1,92 @@
1
+ Mailgun - Templates
2
+ ====================
3
+
4
+ This is the Mailgun Ruby *Templates* utilities.
5
+
6
+ The below assumes you've already installed the Mailgun Ruby SDK in to your
7
+ project. If not, go back to the master README for instructions.
8
+
9
+ Usage - Templates
10
+ -----------------------
11
+
12
+ **Build a message with a template:**
13
+
14
+ ```ruby
15
+ mb_obj = Mailgun::MessageBuilder.new
16
+
17
+ mb_obj.from("sender@example.com")
18
+ mb_obj.add_recipient("to", "recipient@example.com")
19
+ mb_obj.subject ("This is the subject!")
20
+ message.template('example.template.name')
21
+ message.template_version('example.tag')
22
+
23
+ mg_client.send_message "sending_domain.com", mb_obj
24
+ ```
25
+
26
+ **Rails Example. Build a message with a template:**
27
+
28
+ ```ruby
29
+ class UserMailer < ApplicationMailer
30
+ def welcome_email
31
+ message = mail(
32
+ from: "sender@example.com",
33
+ to: "recipient@example.com",
34
+ subject: "This is the subject!",
35
+ template: 'example.template.name'
36
+ ) do |format|
37
+ format.text { render plain: "Test!" }
38
+ end
39
+ message.tap do |message|
40
+ message.mailgun_template_variables ||= {
41
+ 'version' => 'example.tag'
42
+ }
43
+ end
44
+ end
45
+ end
46
+ ```
47
+
48
+ Template Handlebars
49
+ -------------------------
50
+
51
+ ```
52
+ {{#if english}}
53
+ <p>This text is in the English language.</p>
54
+ {{else if spanish}}
55
+ <p>Este texto está en idioma español.</p>
56
+ {{else if french}}
57
+ <p>Ce texte est en langue française.</p>
58
+ {{/if}}
59
+ ```
60
+
61
+ In order to send the spanish version, for example:
62
+
63
+ ```ruby
64
+ message.variable('spanish', 'true')
65
+ ```
66
+
67
+ Also, Rails example:
68
+
69
+ ```ruby
70
+ class UserMailer < ApplicationMailer
71
+ def welcome_email
72
+ message = mail(
73
+ from: "sender@example.com",
74
+ to: "recipient@example.com",
75
+ subject: "This is the subject!",
76
+ template: 'example.template.name'
77
+ ) do |format|
78
+ format.text { render plain: "Test!" }
79
+ end
80
+ message.tap do |message|
81
+ message.mailgun_variables ||= {
82
+ 'spanish' => 'true'
83
+ }
84
+ end
85
+ end
86
+ end
87
+ ```
88
+
89
+ More Documentation
90
+ ------------------
91
+ See the official [Mailgun Templates Docs](https://documentation.mailgun.com/en/latest/api-templates.html)
92
+ for more information
@@ -11,12 +11,12 @@ module Mailgun
11
11
  class Client
12
12
 
13
13
  def initialize(api_key = Mailgun.api_key,
14
- api_host = 'api.mailgun.net',
15
- api_version = 'v3',
14
+ api_host = Mailgun.api_host || 'api.mailgun.net',
15
+ api_version = Mailgun.api_version || 'v3',
16
16
  ssl = true,
17
17
  test_mode = false,
18
18
  timeout = nil,
19
- proxy_url = nil)
19
+ proxy_url = Mailgun.proxy_url)
20
20
 
21
21
  rest_client_params = {
22
22
  user: 'api',
@@ -45,6 +45,11 @@ module Mailgun
45
45
  @test_mode = false
46
46
  end
47
47
 
48
+ # Change API key
49
+ def set_api_key(api_key)
50
+ @http_client.options[:password] = api_key
51
+ end
52
+
48
53
  # Client is in test mode?
49
54
  #
50
55
  # @return [Boolean] Is the client set in test mode?
@@ -45,11 +45,11 @@ module Mailgun
45
45
  end
46
46
 
47
47
  def get_bounce(address)
48
- @client.get("#{@domain}/bounces/#{address}", nil)
48
+ @client.get("#{@domain}/bounces/#{escape_address(address)}", nil)
49
49
  end
50
50
 
51
51
  def create_bounce(params = {})
52
- @client.post("#{@domain/bounces}", params)
52
+ @client.post("#{@domain}/bounces", params)
53
53
  end
54
54
 
55
55
  # Creates multiple bounces on the Mailgun API.
@@ -100,7 +100,7 @@ module Mailgun
100
100
  end
101
101
 
102
102
  def delete_bounce(address)
103
- @client.delete("#{@domain}/bounces/#{address}")
103
+ @client.delete("#{@domain}/bounces/#{escape_address(address)}")
104
104
  end
105
105
 
106
106
  def delete_all_bounces
@@ -118,7 +118,7 @@ module Mailgun
118
118
  end
119
119
 
120
120
  def get_unsubscribe(address)
121
- @client.get("#{@domain}/unsubscribes/#{address}")
121
+ @client.get("#{@domain}/unsubscribes/#{escape_address(address)}")
122
122
  end
123
123
 
124
124
  def create_unsubscribe(params = {})
@@ -173,7 +173,7 @@ module Mailgun
173
173
  end
174
174
 
175
175
  def delete_unsubscribe(address, params = {})
176
- @client.delete("#{@domain}/unsubscribes/#{address}")
176
+ @client.delete("#{@domain}/unsubscribes/#{escape_address(address)}")
177
177
  end
178
178
 
179
179
  ####
@@ -187,7 +187,7 @@ module Mailgun
187
187
  end
188
188
 
189
189
  def get_complaint(address)
190
- @client.get("#{@domain}/complaints/#{address}", nil)
190
+ @client.get("#{@domain}/complaints/#{escape_address(address)}", nil)
191
191
  end
192
192
 
193
193
  def create_complaint(params = {})
@@ -239,11 +239,15 @@ module Mailgun
239
239
  end
240
240
 
241
241
  def delete_complaint(address)
242
- @client.delete("#{@domain}/complaints/#{address}")
242
+ @client.delete("#{@domain}/complaints/#{escape_address(address)}")
243
243
  end
244
244
 
245
245
  private
246
246
 
247
+ def escape_address(address)
248
+ CGI.escape address
249
+ end
250
+
247
251
  def get_from_paging(uri, params = {})
248
252
  @client.get(uri, params)
249
253
  end
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.2.6'
3
+ VERSION = '1.2.7'
4
4
  end
@@ -48,7 +48,10 @@ module Railgun
48
48
 
49
49
  def deliver!(mail)
50
50
  @mg_domain = set_mg_domain(mail)
51
+ @mg_client.set_api_key(mail[:api_key].value) if mail[:api_key].present?
52
+
51
53
  mail[:domain] = nil if mail[:domain].present?
54
+ mail[:api_key] = nil if mail[:api_key].present?
52
55
 
53
56
  mg_message = Railgun.transform_for_mailgun(mail)
54
57
  response = @mg_client.send_message(@mg_domain, mg_message)
@@ -7,7 +7,7 @@ describe 'For the Bounces 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
- @email = "integration-test-email@#{TESTDOMAIN}"
10
+ @email = "integration-test+email@#{TESTDOMAIN}"
11
11
  end
12
12
 
13
13
  it 'creates a bounce' do
@@ -22,7 +22,7 @@ describe 'For the Bounces endpoint', order: :defined, vcr: vcr_opts do
22
22
  end
23
23
 
24
24
  it 'get a bounce.' do
25
- result = @mg_obj.get("#{@domain}/bounces/#{@email}")
25
+ result = @mg_obj.get("#{@domain}/bounces/#{CGI.escape(@email)}")
26
26
 
27
27
  result.to_h!
28
28
  expect(result.body["code"]).to eq("550")
@@ -38,7 +38,7 @@ describe 'For the Bounces endpoint', order: :defined, vcr: vcr_opts do
38
38
  end
39
39
 
40
40
  it 'deletes a bounce' do
41
- @mg_obj.delete("#{@domain}/bounces/#{@email}")
41
+ @mg_obj.delete("#{@domain}/bounces/#{CGI.escape(@email)}")
42
42
  end
43
43
 
44
44
  end
@@ -5,7 +5,7 @@ http_interactions:
5
5
  uri: https://api:<APIKEY>@api.mailgun.net/v3/DOMAIN.TEST/bounces
6
6
  body:
7
7
  encoding: US-ASCII
8
- string: address=integration-test-email%40DOMAIN.TEST&code=550&error=Integration%20Test
8
+ string: address=integration-test%2Bemail%40DOMAIN.TEST&code=550&error=Integration%20Test
9
9
  headers:
10
10
  Accept:
11
11
  - "*/*; q=0.5, application/xml"
@@ -42,13 +42,13 @@ http_interactions:
42
42
  - Content-Type, x-requested-with
43
43
  body:
44
44
  encoding: UTF-8
45
- string: '{"address":"integration-test-email@DOMAIN.TEST","message":"Address
45
+ string: '{"address":"integration-test+email@DOMAIN.TEST","message":"Address
46
46
  has been added to the bounces table"}'
47
- http_version:
47
+ http_version:
48
48
  recorded_at: Fri, 08 Jan 2016 20:33:29 GMT
49
49
  - request:
50
50
  method: get
51
- uri: https://api:<APIKEY>@api.mailgun.net/v3/DOMAIN.TEST/bounces/integration-test-email@DOMAIN.TEST
51
+ uri: https://api:<APIKEY>@api.mailgun.net/v3/DOMAIN.TEST/bounces/integration-test+email@DOMAIN.TEST
52
52
  body:
53
53
  encoding: US-ASCII
54
54
  string: ''
@@ -84,9 +84,9 @@ http_interactions:
84
84
  - Content-Type, x-requested-with
85
85
  body:
86
86
  encoding: UTF-8
87
- string: '{"address":"integration-test-email@DOMAIN.TEST","code":"550","error":"Integration
87
+ string: '{"address":"integration-test+email@DOMAIN.TEST","code":"550","error":"Integration
88
88
  Test","created_at":"Fri, 08 Jan 2016 20:33:28 UTC"}'
89
- http_version:
89
+ http_version:
90
90
  recorded_at: Fri, 08 Jan 2016 20:33:29 GMT
91
91
  - request:
92
92
  method: get
@@ -126,13 +126,13 @@ http_interactions:
126
126
  - Content-Type, x-requested-with
127
127
  body:
128
128
  encoding: UTF-8
129
- string: '{"items":[{"address":"integration-test-email@DOMAIN.TEST","code":"550","error":"Integration
130
- Test","created_at":"Fri, 08 Jan 2016 20:33:28 UTC"}],"paging":{"first":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?limit=100","last":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=last\u0026limit=100","next":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=next\u0026address=integration-test-email%40DOMAIN.TEST\u0026limit=100","previous":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=previous\u0026address=integration-test-email%40DOMAIN.TEST\u0026limit=100"}}'
131
- http_version:
129
+ string: '{"items":[{"address":"integration-test+email@DOMAIN.TEST","code":"550","error":"Integration
130
+ Test","created_at":"Fri, 08 Jan 2016 20:33:28 UTC"}],"paging":{"first":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?limit=100","last":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=last\u0026limit=100","next":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=next\u0026address=integration-test%2Bemaill%40DOMAIN.TEST\u0026limit=100","previous":"https://api.mailgun.net/v3/DOMAIN.TEST/bounces?page=previous\u0026address=integration-test%2Bemail%40DOMAIN.TEST\u0026limit=100"}}'
131
+ http_version:
132
132
  recorded_at: Fri, 08 Jan 2016 20:33:29 GMT
133
133
  - request:
134
134
  method: delete
135
- uri: https://api:<APIKEY>@api.mailgun.net/v3/DOMAIN.TEST/bounces/integration-test-email@DOMAIN.TEST
135
+ uri: https://api:<APIKEY>@api.mailgun.net/v3/DOMAIN.TEST/bounces/integration-test+email@DOMAIN.TEST
136
136
  body:
137
137
  encoding: US-ASCII
138
138
  string: ''
@@ -168,8 +168,8 @@ http_interactions:
168
168
  - Content-Type, x-requested-with
169
169
  body:
170
170
  encoding: UTF-8
171
- string: '{"address":"integration-test-email@DOMAIN.TEST","message":"Bounced
171
+ string: '{"address":"integration-test+email@DOMAIN.TEST","message":"Bounced
172
172
  address has been removed"}'
173
- http_version:
173
+ http_version:
174
174
  recorded_at: Fri, 08 Jan 2016 20:33:30 GMT
175
175
  recorded_with: VCR 3.0.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-11-20 00:00:00.000000000 Z
12
+ date: 2023-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -162,6 +162,7 @@ files:
162
162
  - docs/Webhooks.md
163
163
  - docs/railgun/Overview.md
164
164
  - docs/railgun/Parameters.md
165
+ - docs/railgun/Templates.md
165
166
  - lib/mailgun-ruby.rb
166
167
  - lib/mailgun.rb
167
168
  - lib/mailgun/address.rb