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
-
#create(domain, options = {}) ⇒ Object
Public: Add domain.
-
#create_smtp_credentials(domain, options = {}) ⇒ Object
Public: Creates a new set of SMTP credentials for the defined domain.
-
#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_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.
-
#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_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
#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
39 40 41 42 43 |
# File 'lib/mailgun/domains/domains.rb', line 39 def create(domain, = {}) = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge() [:name] = domain @client.post('domains', ).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
206 207 208 |
# File 'lib/mailgun/domains/domains.rb', line 206 def create_smtp_credentials(domain, = {}) @client.post("domains/#{domain}/credentials", ).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
228 229 230 |
# File 'lib/mailgun/domains/domains.rb', line 228 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
190 191 192 |
# File 'lib/mailgun/domains/domains.rb', line 190 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
180 181 182 183 |
# File 'lib/mailgun/domains/domains.rb', line 180 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.
163 164 165 |
# File 'lib/mailgun/domains/domains.rb', line 163 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.
50 51 52 |
# File 'lib/mailgun/domains/domains.rb', line 50 def get(domain) @client.get("domains/#{domain}").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)
247 248 249 250 251 |
# File 'lib/mailgun/domains/domains.rb', line 247 def get_domain_stats(domain, = {}) raise(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’
145 146 147 |
# File 'lib/mailgun/domains/domains.rb', line 145 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
98 99 100 |
# File 'lib/mailgun/domains/domains.rb', line 98 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)
23 24 25 |
# File 'lib/mailgun/domains/domains.rb', line 23 def list( = {}) @client.get('domains', ).to_h['items'] 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.
154 155 156 |
# File 'lib/mailgun/domains/domains.rb', line 154 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
67 68 69 |
# File 'lib/mailgun/domains/domains.rb', line 67 def update(domain, = {}) @client.put("domains/#{domain}", ).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
110 111 112 |
# File 'lib/mailgun/domains/domains.rb', line 110 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
123 124 125 |
# File 'lib/mailgun/domains/domains.rb', line 123 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
136 137 138 |
# File 'lib/mailgun/domains/domains.rb', line 136 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
218 219 220 |
# File 'lib/mailgun/domains/domains.rb', line 218 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 |