Class: Mailgun::Domains
- Inherits:
-
Object
- Object
- Mailgun::Domains
- Includes:
- ApiVersionChecker
- Defined in:
- lib/mailgun/domains/domains.rb
Overview
A Mailgun::Domains object is a simple CRUD interface to Mailgun Domains. Uses Mailgun
Instance Method Summary collapse
-
#activate_domain_key(domain, selector) ⇒ Object
Public: Activate a domain key for a specified authority and selector.
-
#create(domain, options = {}) ⇒ Object
Public: Add domain.
-
#create_domain_key(options = {}) ⇒ Object
Public: Create a domain key.
-
#create_smtp_credentials(domain, options = {}) ⇒ Object
Public: Creates a new set of SMTP credentials for the defined domain.
-
#deactivate_domain_key(domain, selector) ⇒ Object
Public: Deactivate a domain key for a specified authority and selector.
-
#delete_domain_key(options = {}) ⇒ Object
Public: Delete a domain key.
-
#delete_smtp_credentials(domain, login) ⇒ Object
Public: Deletes the defined SMTP credentials.
-
#dkim_rotate(domain) ⇒ Object
Public: Rotate Automatic Sender Security DKIM key for a domain.
-
#dkim_rotation(domain, rotation_enabled, options = {}) ⇒ Object
Public: Tracking Certificate: Generate.
-
#generate_domain_tracking_certificate(domain, options = {}) ⇒ Object
Public: Tracking Certificate: Generate.
-
#get(domain) ⇒ Object
Public: Get domain information.
-
#get_domain_keys(domain) ⇒ Object
Public: Lists the domain keys for a specified signing domain / authority.
-
#get_domain_stats(domain, options = {}) ⇒ Object
Public: Returns total stats for a given domains.
-
#get_domain_tracking_certificate(domain) ⇒ Object
Public: Tracking Certificate: Get certificate and status.
-
#get_domain_tracking_settings(domain) ⇒ Object
Public: Returns tracking settings for the defined domain.
-
#initialize(client = Mailgun::Client.new) ⇒ Domains
constructor
Public: creates a new Mailgun::Domains instance.
-
#list(options = {}) ⇒ Object
Public: Get Domains.
-
#list_domain_keys(options = {}) ⇒ Object
options - [Hash] of page - [String] Encoded paging information, provided via ‘next’, ‘previous’ links limit - [Integer] Limits the number of items returned in a request signing_domain - [String] Filter by signing domain selector - [String] Filter by selector.
-
#regenerate_domain_tracking_certificate(domain, options = {}) ⇒ Object
Tracking Certificate: Regenerate expired certificate.
-
#remove(domain) ⇒ Object
Public: Delete Domain.
-
#update(domain, options = {}) ⇒ Object
Public: Update domain.
-
#update_domain_dkim_authority(domain, options = {}) ⇒ Object
Public: Change the DKIM authority for a domain.
-
#update_domain_dkim_selector(domain, options = {}) ⇒ Object
Public: Update the DKIM selector for a domains.
-
#update_domain_tracking_click_settings(domain, options = {}) ⇒ Object
Public: Updates the click tracking settings for a domain.
-
#update_domain_tracking_open_settings(domain, options = {}) ⇒ Object
Public: Updates the open tracking settings for a domain.
-
#update_domain_tracking_unsubscribe_settings(domain, options = {}) ⇒ Object
Public: Updates unsubscribe tracking settings for a domain.
-
#update_smtp_credentials(domain, login, options = {}) ⇒ Object
Public: Updates the specified SMTP credentials.
-
#verify(domain) ⇒ Object
Public: Verify domain.
Methods included from ApiVersionChecker
Constructor Details
Instance Method Details
#activate_domain_key(domain, selector) ⇒ Object
Public: Activate a domain key for a specified authority and selector.
domain - [String] Name of the domain (ex. domain.com) selector - [String] The selector you want to activate for the domain key
Returns [Hash] with message key and autority + selector data
137 138 139 |
# File 'lib/mailgun/domains/domains.rb', line 137 def activate_domain_key(domain, selector) @client.put("domains/#{domain}/keys/#{selector}/activate", {}).to_h end |
#create(domain, options = {}) ⇒ Object
Public: Add domain
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
smtp_password - [String] Password for SMTP authentication
spam_action - [String] disabled, blocked or tag
Disable, no spam filtering will occur for inbound messages.
Block, inbound spam messages will not be delivered.
Tag, messages will be tagged with a spam header. See Spam Filter.
wildcard - [Boolean] true or false Determines whether the domain will accept email for sub-domains.
Returns [Hash] of created domain
38 39 40 41 42 |
# File 'lib/mailgun/domains/domains.rb', line 38 def create(domain, = {}) = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge() [:name] = domain @client.post('domains', ).to_h end |
#create_domain_key(options = {}) ⇒ Object
Public: Create a domain key
options - [Hash] of
signing_domain - [String] Name of the domain (ex. domain.com)
selector - [String] Selector to be used for the new domain key
bits - [Integer] Key size, can be 1024 or 2048
pem - [String] Private key PEM
Returns [Hash] with message key
116 117 118 |
# File 'lib/mailgun/domains/domains.rb', line 116 def create_domain_key( = {}) @client.post("dkim/keys", ).to_h end |
#create_smtp_credentials(domain, options = {}) ⇒ Object
Public: Creates a new set of SMTP credentials for the defined domain.
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
login - [String] The user name (ex. bob.bar)
password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
Returns [Hash] with message key
299 300 301 |
# File 'lib/mailgun/domains/domains.rb', line 299 def create_smtp_credentials(domain, = {}) @client.post("domains/#{domain}/credentials", ).to_h end |
#deactivate_domain_key(domain, selector) ⇒ Object
Public: Deactivate a domain key for a specified authority and selector
domain - [String] Name of the domain (ex. domain.com) selector - [String] The selector you want to activate for the domain key
Returns [Hash] with message key and autority + selector data
156 157 158 |
# File 'lib/mailgun/domains/domains.rb', line 156 def deactivate_domain_key(domain, selector) @client.put("domains/#{domain}/keys/#{selector}/deactivate", {}).to_h end |
#delete_domain_key(options = {}) ⇒ Object
Public: Delete a domain key.
options - [Hash] of
signing_domain - [Integer] Name of the domain (ex. domain.com)
selector - [String] Name of the selector
Returns [Hash] with message key
127 128 129 |
# File 'lib/mailgun/domains/domains.rb', line 127 def delete_domain_key( = {}) @client.delete("dkim/keys", ).to_h end |
#delete_smtp_credentials(domain, login) ⇒ Object
Public: Deletes the defined SMTP credentials.
domain - [String] Name of the domain (ex. domain.com) login - [String] The user name (ex. bob.bar)
Returns [Hash] with message and spec keys
321 322 323 |
# File 'lib/mailgun/domains/domains.rb', line 321 def delete_smtp_credentials(domain, login) @client.delete("domains/#{domain}/credentials/#{login}").to_h end |
#dkim_rotate(domain) ⇒ Object
Public: Rotate Automatic Sender Security DKIM key for a domain
domain - [String] The Domain name
Returns [Hash] Response message
283 284 285 |
# File 'lib/mailgun/domains/domains.rb', line 283 def dkim_rotate(domain) @client.post("dkim_management/domains/#{domain}/rotate", {}) end |
#dkim_rotation(domain, rotation_enabled, options = {}) ⇒ Object
Public: Tracking Certificate: Generate
domain - [String] The Domain name rotation_enabled - [Boolean] If true, enables DKIM Auto-Rotation. If false, disables it
options - [Hash] of
rotation_interval - [String] The interval at which to rotate keys. Example, '5d' for five days
Returns [Hash] domain object
273 274 275 276 |
# File 'lib/mailgun/domains/domains.rb', line 273 def dkim_rotation(domain, rotation_enabled, = {}) = { rotation_enabled: rotation_enabled }.merge() @client.put("dkim_management/domains/#{domain}/rotation", ) end |
#generate_domain_tracking_certificate(domain, options = {}) ⇒ Object
Public: Tracking Certificate: Generate
domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
Returns [Hash] A message indicating the status of the request.
255 256 257 |
# File 'lib/mailgun/domains/domains.rb', line 255 def generate_domain_tracking_certificate(domain, = {}) @client.post("x509/#{domain}", ).to_h end |
#get(domain) ⇒ Object
Public: Get domain information
domain - [String] Domain name to lookup
Returns [Hash] Information on the requested domains.
49 50 51 |
# File 'lib/mailgun/domains/domains.rb', line 49 def get(domain) @client.get("domains/#{domain}").to_h! end |
#get_domain_keys(domain) ⇒ Object
Public: Lists the domain keys for a specified signing domain / authority
domain - [String] Name of the domain (ex. domain.com)
Returns [Hash] with domain keys data
146 147 148 |
# File 'lib/mailgun/domains/domains.rb', line 146 def get_domain_keys(domain) @client.get("domains/#{domain}/keys").to_h end |
#get_domain_stats(domain, options = {}) ⇒ Object
Public: Returns total stats for a given domains
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
event - [String] The type of the event.
start - [String] The starting time. Should be in RFC 2822 or unix epoch format.
end - [String] The ending date. Should be in RFC 2822 or unix epoch format
resolution - [String] Can be either hour, day or month. Default: day
duration - [String] Period of time with resoluton encoded
Returns [Array] A list of domains (hash)
340 341 342 343 |
# File 'lib/mailgun/domains/domains.rb', line 340 def get_domain_stats(domain, = {}) fail(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain @client.get("#{domain}/stats/total", ).to_h end |
#get_domain_tracking_certificate(domain) ⇒ Object
Public: Tracking Certificate: Get certificate and status
domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
Returns [Hash] Status of certificate. Either ‘expired’ ‘processing’ ‘active’ or ‘error’
237 238 239 |
# File 'lib/mailgun/domains/domains.rb', line 237 def get_domain_tracking_certificate(domain) @client.get("x509/#{domain}/status").to_h end |
#get_domain_tracking_settings(domain) ⇒ Object
Public: Returns tracking settings for the defined domain.
domain - [String] Name of the domain (ex. domain.com)
Returns [Hash] Information on the tracking settings
192 193 194 |
# File 'lib/mailgun/domains/domains.rb', line 192 def get_domain_tracking_settings(domain) @client.get("domains/#{domain}/tracking").to_h end |
#list(options = {}) ⇒ Object
Public: Get Domains
limit - [Integer] Maximum number of records to return. (100 by default) skip - [Integer] Number of records to skip. (0 by default)
Returns [Array] A list of domains (hash)
22 23 24 |
# File 'lib/mailgun/domains/domains.rb', line 22 def list( = {}) @client.get('domains', ).to_h['items'] end |
#list_domain_keys(options = {}) ⇒ Object
options - [Hash] of
page - [String] Encoded paging information, provided via 'next', 'previous' links
limit - [Integer] Limits the number of items returned in a request
signing_domain - [String] Filter by signing domain
selector - [String] Filter by selector
Returns [Hash] with message key
103 104 105 |
# File 'lib/mailgun/domains/domains.rb', line 103 def list_domain_keys( = {}) @client.get("dkim/keys", ).to_h end |
#regenerate_domain_tracking_certificate(domain, options = {}) ⇒ Object
Tracking Certificate: Regenerate expired certificate
domain - [String] The tracking domain of the TLS certificate, formatted as web_prefix.domain_name
Returns [Hash] A message indicating the status of the request.
246 247 248 |
# File 'lib/mailgun/domains/domains.rb', line 246 def regenerate_domain_tracking_certificate(domain, = {}) @client.put("x509/#{domain}", ).to_h end |
#remove(domain) ⇒ Object
Public: Delete Domain
domain - [String] domain name to delete (ex. domain.com)
Returns [Boolean] if successful or not
85 86 87 |
# File 'lib/mailgun/domains/domains.rb', line 85 def remove(domain) @client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted' end |
#update(domain, options = {}) ⇒ Object
Public: Update domain
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
spam_action - [String] disabled, blocked or tag
Disable, no spam filtering will occur for inbound messages.
Block, inbound spam messages will not be delivered.
Tag, messages will be tagged wtih a spam header. See Spam Filter.
web_scheme - [String] http or https
Set your open, click and unsubscribe URLs to use http or https
wildcard - [Boolean] true or false Determines whether the domain will accept email for sub-domains.
Returns [Hash] of updated domain
66 67 68 |
# File 'lib/mailgun/domains/domains.rb', line 66 def update(domain, = {}) @client.put("domains/#{domain}", ).to_h end |
#update_domain_dkim_authority(domain, options = {}) ⇒ Object
Public: Change the DKIM authority for a domain.
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
self - [Boolean] true - the domain will be the DKIM authority for itself even
if the root domain is registered on the same mailgun account
Returns [Hash] Information on the DKIM authority
168 169 170 |
# File 'lib/mailgun/domains/domains.rb', line 168 def (domain, = {}) @client.put("domains/#{domain}/dkim_authority", ).to_h end |
#update_domain_dkim_selector(domain, options = {}) ⇒ Object
Public: Update the DKIM selector for a domains
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
dkim_selector - [String] change the DKIM selector for a domain.
Returns [Hash] with message key
179 180 181 |
# File 'lib/mailgun/domains/domains.rb', line 179 def update_domain_dkim_selector(domain, = {}) @client.put("domains/#{domain}/dkim_selector", ).to_h end |
#update_domain_tracking_click_settings(domain, options = {}) ⇒ Object
Public: Updates the click tracking settings for a domain.
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
active - [Boolean] yes or no. If set to yes, links will be overwritten and pointed to our servers so we can track clicks.
Returns [Hash] Information on the tracking click settings
203 204 205 |
# File 'lib/mailgun/domains/domains.rb', line 203 def update_domain_tracking_click_settings(domain, = {}) @client.put("domains/#{domain}/tracking/click", ).to_h end |
#update_domain_tracking_open_settings(domain, options = {}) ⇒ Object
Public: Updates the open tracking settings for a domain.
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
active - [Boolean] yes or no. If set to yes, a tracking pixel will be inserted below your HTML content.
place_at_the_top - [Boolean] yes or no. If set to yes, tracking pixel will be moved to top of your HTML content.
Returns [Hash] Information on the tracking open settings
215 216 217 |
# File 'lib/mailgun/domains/domains.rb', line 215 def update_domain_tracking_open_settings(domain, = {}) @client.put("domains/#{domain}/tracking/open", ).to_h end |
#update_domain_tracking_unsubscribe_settings(domain, options = {}) ⇒ Object
Public: Updates unsubscribe tracking settings for a domain.
domain - [String] Name of the domain (ex. domain.com) options - [Hash] of
active - [Boolean] true or false.
html_footer - [String] Custom HTML version of unsubscribe footer.
text_footer - [String] Custom text version of unsubscribe footer.
Returns [Hash] Information on the tracking unsubscribe settings
228 229 230 |
# File 'lib/mailgun/domains/domains.rb', line 228 def update_domain_tracking_unsubscribe_settings(domain, = {}) @client.put("domains/#{domain}/tracking/unsubscribe", ).to_h end |
#update_smtp_credentials(domain, login, options = {}) ⇒ Object
Public: Updates the specified SMTP credentials.
domain - [String] Name of the domain (ex. domain.com) login - [String] The user name (ex. bob.bar) options - [Hash] of
password - [String] A password for the SMTP credentials. (Length Min 5, Max 32)
Returns [Hash] with message key
311 312 313 |
# File 'lib/mailgun/domains/domains.rb', line 311 def update_smtp_credentials(domain, login, = {}) @client.put("domains/#{domain}/credentials/#{login}", ).to_h end |
#verify(domain) ⇒ Object
Public: Verify domain
domain - [String] Domain name
Returns [Hash] Information on the updated/verified domains
76 77 78 |
# File 'lib/mailgun/domains/domains.rb', line 76 def verify(domain) @client.put("domains/#{domain}/verify", nil).to_h! end |