mailgun-ruby 1.2.10 → 1.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -0
  3. data/.rubocop_todo.yml +0 -0
  4. data/.ruby-env.yml.example +0 -0
  5. data/CHANGELOG.md +16 -0
  6. data/README.md +4 -3
  7. data/lib/mailgun/chains.rb +0 -0
  8. data/lib/mailgun/client.rb +2 -2
  9. data/lib/mailgun/domains/domains.rb +1 -1
  10. data/lib/mailgun/events/events.rb +1 -1
  11. data/lib/mailgun/messages/message_builder.rb +2 -2
  12. data/lib/mailgun/response.rb +7 -0
  13. data/lib/mailgun/templates/templates.rb +187 -0
  14. data/lib/mailgun/version.rb +1 -1
  15. data/lib/mailgun/webhooks/webhooks.rb +2 -2
  16. data/lib/mailgun.rb +1 -0
  17. data/lib/railgun/mailer.rb +1 -1
  18. data/mailgun.gemspec +4 -1
  19. data/spec/integration/bounces_spec.rb +0 -0
  20. data/spec/integration/campaign_spec.rb +0 -0
  21. data/spec/integration/complaints_spec.rb +0 -0
  22. data/spec/integration/domains_spec.rb +0 -0
  23. data/spec/integration/email_validation_spec.rb +7 -0
  24. data/spec/integration/events_spec.rb +0 -0
  25. data/spec/integration/list_members_spec.rb +0 -0
  26. data/spec/integration/list_spec.rb +0 -0
  27. data/spec/integration/mailgun_spec.rb +16 -0
  28. data/spec/integration/routes_spec.rb +0 -0
  29. data/spec/integration/stats_spec.rb +0 -0
  30. data/spec/integration/suppressions_spec.rb +0 -0
  31. data/spec/integration/templates_spec.rb +135 -0
  32. data/spec/integration/unsubscribes_spec.rb +0 -0
  33. data/spec/integration/webhook_spec.rb +0 -0
  34. data/spec/unit/connection/test_client.rb +2 -2
  35. data/spec/unit/messages/message_builder_spec.rb +1 -1
  36. data/vcr_cassettes/bounces.yml +0 -0
  37. data/vcr_cassettes/complaints.yml +0 -0
  38. data/vcr_cassettes/domains.todo.yml +0 -0
  39. data/vcr_cassettes/domains.yml +0 -0
  40. data/vcr_cassettes/email_validation.yml +5 -5
  41. data/vcr_cassettes/events.yml +0 -0
  42. data/vcr_cassettes/list_members.yml +0 -0
  43. data/vcr_cassettes/mailing_list.todo.yml +0 -0
  44. data/vcr_cassettes/mailing_list.yml +0 -0
  45. data/vcr_cassettes/routes.yml +0 -0
  46. data/vcr_cassettes/send_message.yml +0 -0
  47. data/vcr_cassettes/stats.yml +0 -0
  48. data/vcr_cassettes/templates.yml +1065 -0
  49. data/vcr_cassettes/unsubscribes.yml +0 -0
  50. data/vcr_cassettes/webhooks.yml +0 -0
  51. metadata +13 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 846d1a1383139f176ad8508d5e465ddfa90617e1b7cc138de178344f11b97365
4
- data.tar.gz: b64fa898adc500f8c5ba7a21af1e02ec92eac3996905ce4a7851cebbe08d2bcd
3
+ metadata.gz: cf800982a326bb3cd2417126fc5a9de3de7ca0c4cf2c9387541244f3ee6d362d
4
+ data.tar.gz: f3515a9207e04c66d69afcaee25ee7aa746ee58f58ea4a48d2511363c1bc6005
5
5
  SHA512:
6
- metadata.gz: bd26107fe4db4917f5e78141ed9fe6ca5d659ae1aea7959316bc12e5c18b130a9b5397c9aaf0c31001ba6bd4a2d490c1ec04f5c592c2653c0fa19b5342ff0996
7
- data.tar.gz: 47b6b488bdae399de35f1418cd92015f0764f884b8a39d2c45c002b4f6bb1db367bd4a24dd6e985b8392f5ef442dc789e17fdd3ac270ad798e44984ddcf3777d
6
+ metadata.gz: a65a2e514f1865825d8c4d7673fd2060e4dd3902402c0500e9dcf213052fff6fb7222379bd155430f30d6abf0300361228ec3cb1db53d2998b2718fb27ffb46a
7
+ data.tar.gz: 2f3988bcd4ecd490305543d3719b37f1531f796558879604263810d02d0bca068647634d8d9141f90711d1d9c4f3038ff29b385bdbe0df0537ac80bc451a05e1
data/.rubocop.yml CHANGED
File without changes
data/.rubocop_todo.yml CHANGED
File without changes
File without changes
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [1.2.12] - 2023-10-22
8
+
9
+ ### Added
10
+
11
+ - Templates CRUD support (https://github.com/mailgun/mailgun-ruby/pull/300).
12
+
13
+ ### Fixed
14
+
15
+ - transform_for_mailgun block iteration issue (https://github.com/mailgun/mailgun-ruby/pull/298).
16
+ - Typos in several files (https://github.com/mailgun/mailgun-ruby/pull/297).
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.10'
22
+ gem 'mailgun-ruby', '~>1.2.12'
23
23
  ```
24
24
 
25
25
  Usage
@@ -81,6 +81,7 @@ and replace `api-myapikey` and `mydomain.com` with your secret API key and domai
81
81
  api_key: 'api-myapikey',
82
82
  domain: 'mydomain.com',
83
83
  # api_host: 'api.eu.mailgun.net' # Uncomment this line for EU region domains
84
+ # timeout: 20 # Default depends on rest-client, whose default is 60s. Added in 1.2.3.
84
85
  }
85
86
  ```
86
87
 
@@ -96,7 +97,7 @@ class UserMailer < ApplicationMailer
96
97
  }
97
98
  end
98
99
  end
99
- end
100
+ end
100
101
  ```
101
102
 
102
103
  To get the Mailgun `message_id` after ActionMailer has successfully delivered the email:
@@ -182,7 +183,7 @@ pages. Or the [Snippets](docs/Snippets.md) file.
182
183
  This SDK includes the following components:
183
184
  - [Messages](docs/Messages.md)
184
185
  - [Message Builder](docs/MessageBuilder.md)
185
- - [Batch Message](docs/MessageBuilder.md)
186
+ - [Batch Message](docs/MessageBuilder.md#usage---batch-message)
186
187
  - [Opt-In Handler](docs/OptInHandler.md)
187
188
  - [Domains](docs/Domains.md)
188
189
  - [Webhooks](docs/Webhooks.md)
File without changes
@@ -222,11 +222,11 @@ module Mailgun
222
222
  message = data.respond_to?(:message) ? data.message : data
223
223
  fail ParameterError.new('Missing working domain', working_domain) unless working_domain
224
224
  fail ParameterError.new(
225
- 'Missing `to` recipient, message should containg at least 1 recipient',
225
+ 'Missing `to` recipient, message should contain at least 1 recipient',
226
226
  working_domain
227
227
  ) if message.fetch('to', []).empty? && message.fetch(:to, []).empty?
228
228
  fail ParameterError.new(
229
- 'Missing a `from` sender, message should containg at least 1 `from` sender',
229
+ 'Missing a `from` sender, message should contain at least 1 `from` sender',
230
230
  working_domain
231
231
  ) if message.fetch('from', []).empty? && message.fetch(:from, []).empty?
232
232
  end
@@ -56,7 +56,7 @@ module Mailgun
56
56
  # spam_action - [String] disabled, blocked or tag
57
57
  # Disable, no spam filtering will occur for inbound messages.
58
58
  # Block, inbound spam messages will not be delivered.
59
- # Tag, messages will be tagged wtih a spam header. See Spam Filter.
59
+ # Tag, messages will be tagged with a spam header. See Spam Filter.
60
60
  # wildcard - [Boolean] true or false Determines whether the domain will accept email for sub-domains.
61
61
  #
62
62
  # Returns [Hash] of created domain
@@ -88,7 +88,7 @@ module Mailgun
88
88
  # Return is irrelevant.
89
89
  def extract_paging(response)
90
90
  paging = response.to_h['paging']
91
- next_page_url = paging && paging['next'] # gives nil when any one of the keys doens't exist
91
+ next_page_url = paging && paging['next'] # gives nil when any one of the keys doesn't exist
92
92
  previous_page_url = paging && paging['previous'] # can be replaced with Hash#dig for ruby >= 2.3.0
93
93
  @paging_next = extract_endpoint_from(next_page_url)
94
94
  @paging_previous = extract_endpoint_from(previous_page_url)
@@ -125,7 +125,7 @@ module Mailgun
125
125
  add_file(:attachment, attachment, filename)
126
126
  end
127
127
 
128
- # Adds an inline image to the mesage object.
128
+ # Adds an inline image to the message object.
129
129
  #
130
130
  # @param [String|File] inline_image A file object for attaching an inline image.
131
131
  # @param [String] filename The filename you wish the inline image to be.
@@ -383,7 +383,7 @@ module Mailgun
383
383
  def bool_lookup(value)
384
384
  return 'yes' if %w(true yes yep).include? value.to_s.downcase
385
385
  return 'no' if %w(false no nope).include? value.to_s.downcase
386
- warn 'WARN: for bool type actions next values are prefered: true yes yep | false no nope | htmlonly'
386
+ warn 'WARN: for bool type actions next values are preferred: true yes yep | false no nope | htmlonly'
387
387
  value
388
388
  end
389
389
 
@@ -58,5 +58,12 @@ module Mailgun
58
58
  rescue => err
59
59
  raise ParseError.new(err), err
60
60
  end
61
+
62
+ # Returns true if response code is 2xx
63
+ #
64
+ # @return [Boolean] A boolean that binarizes the response code result.
65
+ def success?
66
+ (200..299).include?(code)
67
+ end
61
68
  end
62
69
  end
@@ -0,0 +1,187 @@
1
+ require 'mailgun/exceptions/exceptions'
2
+
3
+ module Mailgun
4
+
5
+ # A Mailgun::Templates object is a simple CRUD interface to Mailgun Templates.
6
+ # Uses Mailgun
7
+ class Templates
8
+
9
+ # Public: creates a new Mailgun::Templates instance.
10
+ # Defaults to Mailgun::Client
11
+ def initialize(client = Mailgun::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Public: Add template
16
+ #
17
+ # domain - [String] Name of the domain for new template(ex. domain.com)
18
+ # options - [Hash] of
19
+ # name - [String] Name of the template being stored.
20
+ # description - [String] Description of the template being stored
21
+ # template - [String] (Optional) Content of the template
22
+ # tag - [String] (Optional) Initial tag of the created version.
23
+ # comment - [String] (Optional) Version comment.
24
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the template.
25
+ # ex.('{"Subject": "{{subject}}"}')
26
+ #
27
+ # Returns [Hash] of created template
28
+ def create(domain, options = {})
29
+ fail(ParameterError, 'No domain given to store template on', caller) unless domain
30
+ @client.post("#{domain}/templates", options).to_h
31
+ end
32
+
33
+ # Public: Get template information
34
+ #
35
+ # domain - [String] Domain name where template is stored
36
+ # template_name - [String] Template name to lookup for
37
+ # options - [Hash] of
38
+ # active - [Boolean] (Optional) If this flag is set to yes the active version
39
+ # of the template is included in the response.
40
+ #
41
+ # Returns [Hash] Information on the requested template.
42
+ def info(domain, template_name, options = {})
43
+ fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
44
+ fail(ParameterError, 'No template name given to find on provided domain', caller) unless template_name
45
+ @client.get("#{domain}/templates/#{template_name}", options).to_h!
46
+ end
47
+
48
+ # Public: Update the metadata information of the template
49
+ #
50
+ # domain - [String] Domain name where template is stored
51
+ # template_name - [String] Template name to lookup for
52
+ # options - [Hash] of
53
+ # description - [String] Updated description of the template
54
+ #
55
+ # Returns [Hash] of updated domain
56
+ def update(domain, template_name, options = {})
57
+ fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
58
+ fail(ParameterError, 'No template name given to find on provided domain', caller) unless template_name
59
+ @client.put("#{domain}/templates/#{template_name}", options).to_h
60
+ end
61
+
62
+ # Public: Delete Template
63
+ # NOTE: This method deletes all versions of the specified template.
64
+ #
65
+ # domain - [String] Domain name where template is stored
66
+ # template_name - [String] Template name to lookup for
67
+ #
68
+ # Returns [Boolean] if successful or not
69
+ def remove(domain, template_name)
70
+ fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
71
+ fail(ParameterError, 'No template name given to find on provided domain', caller) unless template_name
72
+ @client.delete("#{domain}/templates/#{template_name}").to_h['message'] == 'template has been deleted'
73
+ end
74
+ alias_method :delete, :remove
75
+ alias_method :delete_template, :remove
76
+
77
+ # Public: Get Templates
78
+ #
79
+ # domain - [String] Domain name where template is stored
80
+ # page - [String] Name of a page to retrieve. first, last, next, prev
81
+ # limit - [Integer] Maximum number of records to return. (100 by default)
82
+ # p - [Integer] Pivot is used to retrieve records in chronological order
83
+ #
84
+ # Returns [Array] A list of templates (hash)
85
+ def list(domain, options = {})
86
+ fail(ParameterError, 'No domain given.', caller) unless domain
87
+ @client.get("#{domain}/templates", options).to_h['items']
88
+ end
89
+ alias_method :get_templates, :list
90
+
91
+ # Public: Delete Templates
92
+ # NOTE: This method deletes all stored templates for the domain.
93
+ #
94
+ # domain - [String] Domain name where template is stored
95
+ #
96
+ # Returns [Boolean] if successful or not
97
+ def remove_all(domain)
98
+ fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
99
+ @client.delete("#{domain}/templates").to_h['message'] == 'templates have been deleted'
100
+ end
101
+ alias_method :delete_templates, :remove_all
102
+
103
+ # Public: Create a new version of a template
104
+ #
105
+ # domain - [String] Name of the domain for new template(ex. domain.com)
106
+ # template_name - [String] Template name to lookup for
107
+ # options - [Hash] of
108
+ # template - [String] Content of the template
109
+ # tag - [String] Initial tag of the created version.
110
+ # comment - [String] (Optional) Version comment.
111
+ # active - [Boolean] (Optional) If this flag is set to yes, this version becomes active
112
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the template.
113
+ # ex.('{"Subject": "{{subject}}"}')
114
+ #
115
+ # Returns [Hash] of updated template
116
+ def create_version(domain, template_name, options = {})
117
+ fail(ParameterError, 'No domain given.', caller) unless domain
118
+ fail(ParameterError, 'No template name given.', caller) unless template_name
119
+ @client.post("#{domain}/templates/#{template_name}/versions", options).to_h
120
+ end
121
+
122
+ # Public: Get template version information
123
+ #
124
+ # domain - [String] Domain name where template is stored
125
+ # template_name - [String] Template name to lookup for
126
+ # tag - [String] Version tag to lookup for
127
+ #
128
+ # Returns [Hash] Information on the requested template + version.
129
+ def info_version(domain, template_name, tag)
130
+ fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
131
+ fail(ParameterError, 'No template name given to find on provided domain', caller) unless template_name
132
+ fail(ParameterError, 'No version tag given.', caller) unless tag
133
+ @client.get("#{domain}/templates/#{template_name}/versions/#{tag}").to_h!
134
+ end
135
+
136
+ # Public: Update the version of the template
137
+ #
138
+ # domain - [String] Domain name where template is stored
139
+ # template_name - [String] Template name to lookup for
140
+ # tag - [String] Version tag to lookup for
141
+ # options - [Hash] of
142
+ # template - [String] Content of the template
143
+ # comment - [String] (Optional) Version comment.
144
+ # active - [Boolean] (Optional) If this flag is set to yes, this version becomes active
145
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the template.
146
+ # ex.('{"Subject": "{{subject}}"}')
147
+ #
148
+ # Returns [Hash] of updated template's version
149
+ def update_version(domain, template_name, tag, options = {})
150
+ fail(ParameterError, 'No domain given.', caller) unless domain
151
+ fail(ParameterError, 'No template name given to find on provided domain.', caller) unless template_name
152
+ fail(ParameterError, 'No version tag given.', caller) unless tag
153
+ @client.put("#{domain}/templates/#{template_name}/versions/#{tag}", options).to_h
154
+ end
155
+
156
+ # Public: Delete the version of the template
157
+ #
158
+ # domain - [String] Domain name where template is stored
159
+ # template_name - [String] Template name to lookup for
160
+ # tag - [String] Version tag to lookup for
161
+ #
162
+ # Returns [Boolean] if successful or not
163
+ def delete_version(domain, template_name, tag)
164
+ fail(ParameterError, 'No domain given.', caller) unless domain
165
+ fail(ParameterError, 'No template name given to find on provided domain.', caller) unless template_name
166
+ fail(ParameterError, 'No version tag given.', caller) unless tag
167
+ @client.delete("#{domain}/templates/#{template_name}/versions/#{tag}")
168
+ .to_h['message'] == 'version has been deleted'
169
+ end
170
+
171
+ # Public: Get Template's Versions list
172
+ #
173
+ # domain - [String] Domain name where template is stored
174
+ # template_name - [String] Template name to lookup for
175
+ # options - [Hash] of
176
+ # page - [String] Name of a page to retrieve. first, last, next, prev
177
+ # limit - [Integer] Maximum number of records to return. (100 by default)
178
+ # p - [Integer] Pivot is used to retrieve records in chronological order
179
+ #
180
+ # Returns [Array] A list of template's versions (hash)
181
+ def template_versions_list(domain, template_name, options = {})
182
+ fail(ParameterError, 'No domain given.', caller) unless domain
183
+ fail(ParameterError, 'No template name given to find on provided domain.', caller) unless template_name
184
+ @client.get("#{domain}/templates/#{template_name}/versions", options).to_h
185
+ end
186
+ end
187
+ end
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.2.10'
3
+ VERSION = '1.2.12'
4
4
  end
@@ -58,7 +58,7 @@ module Mailgun
58
58
  #
59
59
  # Returns true or false
60
60
  def create_all(domain, url = '')
61
- %w(bounce click deliver drop open spam unsubscribe).each do |action|
61
+ %w(accepted clicked complained delivered opened permanent_fail temporary_fail unsubscribed).each do |action|
62
62
  add_webhook domain, action, url
63
63
  end
64
64
  true
@@ -90,7 +90,7 @@ module Mailgun
90
90
  # Returns a Boolean on the success
91
91
  def remove_all(domain)
92
92
  fail Mailgun::ParameterError('Domain not provided to remove webhooks from') unless domain
93
- %w(bounce click deliver drop open spam unsubscribe).each do |action|
93
+ %w(accepted clicked complained delivered opened permanent_fail temporary_fail unsubscribed).each do |action|
94
94
  delete_webhook domain, action
95
95
  end
96
96
  end
data/lib/mailgun.rb CHANGED
@@ -15,6 +15,7 @@ require 'mailgun/events/events'
15
15
  require 'mailgun/exceptions/exceptions'
16
16
  require 'mailgun/domains/domains'
17
17
  require 'mailgun/webhooks/webhooks'
18
+ require 'mailgun/templates/templates'
18
19
 
19
20
  # Module for interacting with the sweet Mailgun API.
20
21
  #
@@ -145,7 +145,7 @@ module Railgun
145
145
 
146
146
  # reject blank values
147
147
  message.delete_if do |k, v|
148
- return true if v.nil?
148
+ next true if v.nil?
149
149
 
150
150
  # if it's an array remove empty elements
151
151
  v.delete_if { |i| i.respond_to?(:empty?) && i.empty? } if v.is_a?(Array)
data/mailgun.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
 
8
8
  spec.name = 'mailgun-ruby'
9
9
  spec.version = Mailgun::VERSION
10
- spec.homepage = 'http://www.mailgun.com'
10
+ spec.homepage = 'https://www.mailgun.com/'
11
11
  spec.platform = Gem::Platform::RUBY
12
12
  spec.license = 'Apache-2.0'
13
13
 
@@ -17,6 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.authors = ['Mailgun', 'Travis Swientek']
18
18
  spec.email = 'support@mailgunhq.com'
19
19
 
20
+ spec.metadata['documentation_uri'] = 'https://documentation.mailgun.com/'
21
+ spec.metadata['source_code_uri'] = 'https://github.com/mailgun/mailgun-ruby'
22
+
20
23
  spec.files = `git ls-files -z`.split("\x0")
21
24
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
File without changes
File without changes
File without changes
File without changes
@@ -15,6 +15,13 @@ describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
15
15
  @all_addrs = @valid + @invalid
16
16
  end
17
17
 
18
+ it 'returns parsed and unparsable lists' do
19
+ res = @mg_obj.parse(@all_addrs)
20
+
21
+ expect(res["parsed"]).to eq(@valid)
22
+ expect(res["unparsable"]).to eq(@invalid)
23
+ end
24
+
18
25
  it 'validates alice@mailgun.net with info' do
19
26
  res = @mg_obj.validate("alice@mailgun.net")
20
27
 
File without changes
File without changes
File without changes
@@ -192,5 +192,21 @@ Testing some Mailgun awesomness!'
192
192
  expect(result.body).to include("message")
193
193
  expect(result.body).to include("id")
194
194
  end
195
+
196
+ it 'receives success response code' do
197
+ @mg_obj.enable_test_mode!
198
+
199
+ expect(@mg_obj.test_mode?).to eq(true)
200
+
201
+ data = { :from => "joe@#{@domain}",
202
+ :to => "bob@#{@domain}",
203
+ :subject => "Test",
204
+ :text => "Test Data" }
205
+
206
+ result = @mg_obj.send_message(@domain, data)
207
+ result.to_h!
208
+
209
+ expect(result.success?).to be(true)
210
+ end
195
211
  end
196
212
 
File without changes
File without changes
File without changes
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+ require 'mailgun'
3
+
4
+ vcr_opts = { :cassette_name => "templates" }
5
+
6
+ describe 'For the templates endpoints', vcr: vcr_opts do
7
+ let(:template_name) { 'test.template' }
8
+ let(:domain) { "integration-test.domain.invalid" }
9
+ let(:tag) { 'v2' }
10
+
11
+ before(:all) do
12
+ @mg_client = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
13
+ @mg_obj = Mailgun::Templates.new(@mg_client)
14
+ end
15
+
16
+ describe '#create' do
17
+ it 'creates the template' do
18
+ result = @mg_obj.create(
19
+ domain,
20
+ {
21
+ name: template_name,
22
+ description: 'Test',
23
+ template: '{{fname}} {{lname}}',
24
+ comment: 'test comment',
25
+ headers: '{"Subject": "{{subject}}"}',
26
+ tag: 'V1'
27
+ }
28
+ )
29
+
30
+ expect(result['template']["name"]).to eq('test.template')
31
+ expect(result['template']["description"]).to eq("Test")
32
+ end
33
+ end
34
+
35
+ describe '#info' do
36
+ it 'gets the templates info' do
37
+ result = @mg_obj.info(domain, 'test.template')
38
+
39
+ expect(result).to include("template")
40
+ expect(result["template"]["name"]).to eq(template_name)
41
+ end
42
+ end
43
+
44
+ describe '#update' do
45
+ it 'updates the template' do
46
+ result = @mg_obj.update(domain, template_name, { description: 'Updated Description' })
47
+
48
+ expect(result['message']).to eq('template has been updated')
49
+ end
50
+ end
51
+
52
+ describe '#list' do
53
+ it 'returns a list of templates' do
54
+ result = @mg_obj.list(domain)
55
+
56
+ expect(result.first).to have_key('name')
57
+ expect(result.first).to have_key('description')
58
+ end
59
+ end
60
+
61
+ describe '#delete' do
62
+ it 'deletes a template' do
63
+ result = @mg_obj.delete(domain, template_name)
64
+
65
+ expect(result).to be_truthy
66
+ end
67
+ end
68
+
69
+ describe '#remove_all' do
70
+ it 'deletes all templates from domain' do
71
+ result = @mg_obj.remove_all(domain)
72
+
73
+ expect(result).to be_truthy
74
+ end
75
+ end
76
+
77
+ describe '#create_version' do
78
+ it 'creates the version for the template' do
79
+ result = @mg_obj.create_version(
80
+ domain,
81
+ template_name,
82
+ {
83
+ template: '{{fname}} {{lname}}',
84
+ comment: 'test comment',
85
+ headers: '{"Subject": "{{subject}}"}',
86
+ tag: tag,
87
+ active: 'yes'
88
+ }
89
+ )
90
+
91
+ expect(result['template']["version"]['tag']).to eq(tag)
92
+ end
93
+ end
94
+
95
+ describe '#info_version' do
96
+ it "gets the template's version info" do
97
+ result = @mg_obj.info_version(domain, template_name, tag)
98
+
99
+ expect(result["template"]["version"]['tag']).to eq(tag)
100
+ end
101
+ end
102
+
103
+ describe '#update_version' do
104
+ it 'updates the template' do
105
+ result = @mg_obj.update_version(
106
+ domain,
107
+ template_name,
108
+ tag,
109
+ {
110
+ template: '{{fname}} {{lname}}',
111
+ comment: 'test comment 2',
112
+ headers: '{"Subject": "{{subject}}"}'
113
+ }
114
+ )
115
+
116
+ expect(result['message']).to eq('version has been updated')
117
+ end
118
+ end
119
+
120
+ describe '#template_versions_list' do
121
+ it "returns template's versions" do
122
+ result = @mg_obj.template_versions_list(domain, template_name)
123
+
124
+ expect(result["template"]["versions"].first).to include('tag')
125
+ end
126
+ end
127
+
128
+ describe '#delete_version' do
129
+ it "deletes template's version" do
130
+ result = @mg_obj.delete_version(domain, template_name, tag)
131
+
132
+ expect(result).to be_truthy
133
+ end
134
+ end
135
+ end
File without changes
File without changes
@@ -83,11 +83,11 @@ module Mailgun
83
83
  message = data.respond_to?(:message) ? data.message : data
84
84
 
85
85
  fail ParameterError.new(
86
- 'Missing `to` recipient, message should containg at least 1 recipient',
86
+ 'Missing `to` recipient, message should contain at least 1 recipient',
87
87
  working_domain
88
88
  ) if message.fetch('to', []).empty? && message.fetch(:to, []).empty?
89
89
  fail ParameterError.new(
90
- 'Missing a `from` sender, message should containg at least 1 `from` sender',
90
+ 'Missing a `from` sender, message should contain at least 1 `from` sender',
91
91
  working_domain
92
92
  ) if message.fetch('from', []).empty? && message.fetch(:from, []).empty?
93
93
  end
@@ -513,7 +513,7 @@ describe 'The method track_clicks' do
513
513
  end
514
514
 
515
515
  context 'when unexpected value is provided' do
516
- it 'warns about prefered values' do
516
+ it 'warns about preferred values' do
517
517
  expect(@mb_obj).to receive :warn
518
518
  @mb_obj.track_clicks('random')
519
519
  end
File without changes
File without changes
File without changes
File without changes