mailgun-ruby 1.2.11 → 1.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17aa99cf0b68c595bdc9a923368c206da53c5eb2798d4a4faf9def78d9216129
4
- data.tar.gz: ede5046e9ddb743b5eadff56da85a7b32049c6c6451895442f4356675c946cc9
3
+ metadata.gz: 63fbab3c08481c2364ca4fef89def410a12672507954764103e900bb0f081858
4
+ data.tar.gz: e2fed301bb806d720b6e7f9f8707d415756ed92f5b841592ebc100eb53a71d74
5
5
  SHA512:
6
- metadata.gz: a9b57eb3df8f031b360871555f05681f4f585df44973844369f54f4acc0331e34977813275a36dab485d3b3c3268ce2a56d456c4b292bfd90399d226da1c66f5
7
- data.tar.gz: 99d18ff767e314c436891d4a56aa05e7037618c7aa03f3fc28d6be69ad41e49a58744f02024f94376ab9e69f0250ae3455e54d41f9b939da80cba64550ec71ea
6
+ metadata.gz: 69ad70a850bdb1cbc859647509315b118aa7508747c8af281eeb7ec4514156f1416aa16b4d0e10e07fa168adc705ba110d20b28aae3137b26c454cdf9115b191
7
+ data.tar.gz: e5f30539ca1dfd25ab6bd489c7544febd7b54ae00b407c3378e9ecd3c7166efd961d76f73943e931015436880eab72b607cea5629bf26fda811cbfec1dc1e787
@@ -10,3 +10,4 @@
10
10
  MAILGUN_APIKEY : '<MAILGUN_APIKEY>'
11
11
  MAILGUN_PUB_APIKEY : '<MAILGUN_PUBLIC_APIKEY>'
12
12
  MAILGUN_TESTDOMAIN : '<MAILGUN_SANDBOX_DOMAIN>'
13
+
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.13] - 2023-11-25
8
+
9
+ ### Added
10
+
11
+ - Subaccounts API 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.11'
22
+ gem 'mailgun-ruby', '~>1.2.12'
23
23
  ```
24
24
 
25
25
  Usage
@@ -183,13 +183,16 @@ pages. Or the [Snippets](docs/Snippets.md) file.
183
183
  This SDK includes the following components:
184
184
  - [Messages](docs/Messages.md)
185
185
  - [Message Builder](docs/MessageBuilder.md)
186
- - [Batch Message](docs/MessageBuilder.md)
186
+ - [Batch Message](docs/MessageBuilder.md#usage---batch-message)
187
187
  - [Opt-In Handler](docs/OptInHandler.md)
188
188
  - [Domains](docs/Domains.md)
189
189
  - [Webhooks](docs/Webhooks.md)
190
190
  - [Events](docs/Events.md)
191
+ - [Snippets](docs/Snippets.md)
192
+ - [Subaccounts](docs/Subaccounts.md)
191
193
  - [Suppressions](docs/Suppressions.md)
192
194
  - [Templates](docs/Templates.md)
195
+ - [EmailValidation](docs/EmailValidation.md)
193
196
 
194
197
  Message Builder allows you to quickly create the array of parameters, required
195
198
  to send a message, by calling a methods for each parameter.
@@ -0,0 +1,34 @@
1
+ Mailgun - Email Validation
2
+ ====================
3
+
4
+ This is the Mailgun Ruby *Email Validation* 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 - Email Validation
10
+ -----------------------
11
+
12
+ ```ruby
13
+ # First, instantiate the Mailgun Address. It pulls api key for Client from Mailgun.api_key variable.
14
+ email_validator = Mailgun::Address.new
15
+
16
+ # Given an arbitrary address, validates address based off defined checks.
17
+ # Response Example:
18
+ # {
19
+ # "address": "existingemail@realdomain.com",
20
+ # "is_disposable_address": false,
21
+ # "is_role_address": false,
22
+ # "reason": [],
23
+ # "result": "deliverable",
24
+ # "risk": "low"
25
+ # }
26
+ email_validator.validate('email@example.com')
27
+
28
+
29
+ ```
30
+
31
+ More Documentation
32
+ ------------------
33
+ See the official [Mailgun Email Validation Docs](https://documentation.mailgun.com/en/latest/api-email-validation.html)
34
+ for more information
@@ -0,0 +1,68 @@
1
+ Mailgun - [Subaccounts](https://help.mailgun.com/hc/en-us/articles/16380043681435-Subaccounts)
2
+ ====================
3
+
4
+ Rails
5
+ -----
6
+
7
+ The library can be initialized with a Rails initializer containing similar:
8
+ ```ruby
9
+ Mailgun.configure do |config|
10
+ config.api_key = 'your-secret-api-key'
11
+ end
12
+ ```
13
+ Or have the initializer read your environment setting if you prefer.
14
+
15
+ ```ruby
16
+ Mailgun.api_key = 'your-secret-api-key'
17
+ ```
18
+
19
+ ```ruby
20
+ mb_obj = Mailgun::Subaccounts.new
21
+
22
+ # Get subaccounts list
23
+ mb_obj.get_subaccounts(limit: 10, skip: 0, sort: 'ask', enabled: true)
24
+ => {"subaccounts"=>[{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}, {"id"=>"YYY", "name"=>"test.subaccount2", "status"=>"open"}], "total"=>2}
25
+
26
+ # Get subaccount information
27
+ mb_obj.info(subaccount_id)
28
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}
29
+
30
+ # Add Subaccount
31
+ mb_obj.create(name)
32
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}}
33
+
34
+ # Disable
35
+ mb_obj.disable(subaccount_id)
36
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"disabled"}}
37
+
38
+ # Enable
39
+ mb_obj.enable(subaccount_id)
40
+ => {"subaccount"=>{"id"=>"XYZ", "name"=>"test.subaccount1", "status"=>"open"}}
41
+ ```
42
+
43
+ Primary accounts can make API calls on behalf of their subaccounts.
44
+ ```ruby
45
+ # First, instantiate the Mailgun Client with your API key
46
+ mg_client = Mailgun::Client.new 'your-api-key'
47
+ mg_client.set_subaccount('SUBACCOUNT_ID')
48
+
49
+ # Define your message parameters
50
+ message_params = { from: 'bob@SUBACCOUNT_DOMAIN',
51
+ to: 'sally@example.com',
52
+ subject: 'The Ruby SDK is awesome!',
53
+ text: 'It is really easy to send a message!'
54
+ }
55
+
56
+ # Send your message through the client
57
+ # Note: This will not actually hit the API, and will return a generic OK response.
58
+ mg_client.send_message('SUBACCOUNT_DOMAIN', message_params)
59
+
60
+ # Reset subaccount for primary usage
61
+ mg_client.reset_subaccount
62
+ ```
63
+
64
+
65
+ More Documentation
66
+ ------------------
67
+ See the official [Mailgun Docs](https://documentation.mailgun.com/en/latest/subaccounts.html#subaccounts)
68
+ for more information.
data/docs/Suppressions.md CHANGED
@@ -38,6 +38,16 @@ supp_client.list_complaints
38
38
 
39
39
  ----
40
40
 
41
+ To get the next or previous suppressions page:
42
+
43
+ ```ruby
44
+ supp_client.list_bounces # returns first *limit* records + next, previous pages urls
45
+ supp_client.next # returns next *limit* records
46
+ supp_client.prev # returns previous *limit* records
47
+ ```
48
+
49
+ ----
50
+
41
51
  To batch-add a set of bounces:
42
52
 
43
53
  ```ruby
@@ -0,0 +1,34 @@
1
+ Mailgun - Email Validation
2
+ ====================
3
+
4
+ This is the Mailgun Ruby *Email Validation* 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 - Email Validation
10
+ -----------------------
11
+
12
+ ```ruby
13
+ # First, instantiate the Mailgun Address. It pulls api key for Client from Mailgun.api_key variable.
14
+ email_validator = Mailgun::Address.new
15
+
16
+ # Given an arbitrary address, validates address based off defined checks.
17
+ # Response Example:
18
+ # {
19
+ # "address": "existingemail@realdomain.com",
20
+ # "is_disposable_address": false,
21
+ # "is_role_address": false,
22
+ # "reason": [],
23
+ # "result": "deliverable",
24
+ # "risk": "low"
25
+ # }
26
+ email_validator.validate('email@example.com')
27
+
28
+
29
+ ```
30
+
31
+ More Documentation
32
+ ------------------
33
+ See the official [Mailgun Email Validation Docs](https://documentation.mailgun.com/en/latest/api-email-validation.html)
34
+ for more information
@@ -9,6 +9,7 @@ module Mailgun
9
9
  #
10
10
  # See the Github documentation for full examples.
11
11
  class Client
12
+ SUBACCOUNT_HEADER = 'X-Mailgun-On-Behalf-Of'.freeze
12
13
 
13
14
  def initialize(api_key = Mailgun.api_key,
14
15
  api_host = Mailgun.api_host || 'api.mailgun.net',
@@ -50,6 +51,16 @@ module Mailgun
50
51
  @http_client.options[:password] = api_key
51
52
  end
52
53
 
54
+ # Add subaccount id to headers
55
+ def set_subaccount(subaccount_id)
56
+ @http_client.options[:headers] = { SUBACCOUNT_HEADER => subaccount_id }
57
+ end
58
+
59
+ # Reset subaccount for primary usage
60
+ def reset_subaccount
61
+ @http_client.options[:headers].delete(SUBACCOUNT_HEADER)
62
+ end
63
+
53
64
  # Client is in test mode?
54
65
  #
55
66
  # @return [Boolean] Is the client set in test mode?
@@ -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,84 @@
1
+ require 'mailgun/exceptions/exceptions'
2
+
3
+ module Mailgun
4
+
5
+ # A Mailgun::Subaccounts object is a simple CRUD interface to Mailgun Subaccounts.
6
+ # Uses Mailgun
7
+ class Subaccounts
8
+ attr_reader :client
9
+
10
+ # Public: creates a new Mailgun::Subaccounts instance.
11
+ # Defaults to Mailgun::Client
12
+ def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v5'))
13
+ @client = client
14
+ end
15
+
16
+ # Public: Get subaccounts
17
+ # options - [Hash] of
18
+ # limit - [Integer] Maximum number of records to return. (10 by default)
19
+ # skip [Integer] Number of records to skip
20
+ # sort [Array] “asc” or “desc”
21
+ # enabled [boolean] (Optional) Returns all enabled/disabled subaccounts, defaults to all if omitted
22
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
23
+ # ex.('{"Subject": "{{subject}}"}')
24
+ #
25
+ # Returns [Array] A list of subaccounts (hash)
26
+ def list(options = {})
27
+ client.get("accounts/subaccounts", options).to_h!
28
+ end
29
+ alias_method :get_subaccounts, :list
30
+
31
+ # Public: Get subaccount information
32
+ #
33
+ # subaccount_id - [String] subaccount name to lookup for
34
+ # options - [Hash] of
35
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
36
+ # ex.('{"Subject": "{{subject}}"}')
37
+ #
38
+ # Returns [Hash] Information on the requested subaccount.
39
+ def info(subaccount_id, options = {})
40
+ fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id
41
+ client.get("accounts/subaccounts/#{subaccount_id}", options).to_h!
42
+ end
43
+
44
+ # Public: Add Subaccount
45
+ #
46
+ # name - [String] Name of the subaccount being created
47
+ # options - [Hash] of
48
+ # name - [String] Name of the subaccount being created.
49
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
50
+ # ex.('{"Subject": "{{subject}}"}')
51
+ #
52
+ # Returns [Hash] of created subaccount
53
+ def create(name, options = {})
54
+ fail(ParameterError, 'No name given to create subaccount', caller) unless name
55
+ client.post("accounts/subaccounts", options.merge!(name: name)).to_h!
56
+ end
57
+
58
+ # Public: Disable a subaccount
59
+ #
60
+ # subaccount_id - [String] subaccount name to disable
61
+ # options - [Hash] of
62
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
63
+ # ex.('{"Subject": "{{subject}}"}')
64
+ #
65
+ # Returns [Hash] Information on the requested subaccount.
66
+ def disable(subaccount_id, options = {})
67
+ fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id
68
+ client.post("accounts/subaccounts/#{subaccount_id}/disable", options).to_h!
69
+ end
70
+
71
+ # Public: Enable a subaccount
72
+ #
73
+ # subaccount_id - [String] subaccount name to enable
74
+ # options - [Hash] of
75
+ # headers - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
76
+ # ex.('{"Subject": "{{subject}}"}')
77
+ #
78
+ # Returns [Hash] Information on the requested subaccount.
79
+ def enable(subaccount_id, options = {})
80
+ fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id
81
+ client.post("accounts/subaccounts/#{subaccount_id}/enable", options).to_h!
82
+ end
83
+ end
84
+ 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.11'
3
+ VERSION = '1.2.13'
4
4
  end
data/lib/mailgun.rb CHANGED
@@ -15,6 +15,8 @@ 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'
19
+ require 'mailgun/subaccounts/subaccounts'
18
20
 
19
21
  # Module for interacting with the sweet Mailgun API.
20
22
  #
@@ -49,9 +49,11 @@ module Railgun
49
49
  def deliver!(mail)
50
50
  @mg_domain = set_mg_domain(mail)
51
51
  @mg_client.set_api_key(mail[:api_key].value) if mail[:api_key].present?
52
+ @mg_client.set_subaccount(mail[:subaccount_id].value) if mail[:subaccount_id].present?
52
53
 
53
54
  mail[:domain] = nil if mail[:domain].present?
54
55
  mail[:api_key] = nil if mail[:api_key].present?
56
+ mail[:subaccount_id] = nil if mail[:subaccount_id].present?
55
57
 
56
58
  mg_message = Railgun.transform_for_mailgun(mail)
57
59
  response = @mg_client.send_message(@mg_domain, mg_message)
@@ -145,7 +147,7 @@ module Railgun
145
147
 
146
148
  # reject blank values
147
149
  message.delete_if do |k, v|
148
- return true if v.nil?
150
+ next true if v.nil?
149
151
 
150
152
  # if it's an array remove empty elements
151
153
  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)/})
@@ -27,7 +30,7 @@ Gem::Specification.new do |spec|
27
30
  spec.add_development_dependency 'bundler', '>= 1.16.2'
28
31
  spec.add_development_dependency 'rspec', '~> 3.8.0'
29
32
  spec.add_development_dependency 'rake', '~> 12.3.2'
30
- spec.add_development_dependency 'webmock', '~> 3.4.2'
33
+ spec.add_development_dependency 'webmock', '~> 3.7'
31
34
  spec.add_development_dependency 'pry', '~> 0.11.3'
32
35
  spec.add_development_dependency 'vcr', '~> 3.0.3'
33
36
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
@@ -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