Class: Mailgun::Domains

Inherits:
Object
  • Object
show all
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

Methods included from ApiVersionChecker

included

Constructor Details

#initialize(client = Mailgun::Client.new) ⇒ Domains

Public: creates a new Mailgun::Domains instance.

Defaults to Mailgun::Client


11
12
13
# File 'lib/mailgun/domains/domains.rb', line 11

def initialize(client = Mailgun::Client.new)
  @client = client
end

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, options = {})
  options = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge(options)
  options[:name] = domain
  @client.post('domains', options).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, options = {})
  @client.post("domains/#{domain}/credentials", options).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, )
  @client.delete("domains/#{domain}/credentials/#{}").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, options = {})
  options = { rotation_enabled: rotation_enabled }.merge(options)
  @client.put("dkim_management/domains/#{domain}/rotation", options)
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, options = {})
  @client.post("x509/#{domain}", options).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)

Raises:



247
248
249
250
251
# File 'lib/mailgun/domains/domains.rb', line 247

def get_domain_stats(domain, options = {})
  raise(ParameterError, 'No domain given to list stats on Mailgun', caller) unless domain

  @client.get("#{domain}/stats/total", options).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(options = {})
  @client.get('domains', options).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, options = {})
  @client.put("x509/#{domain}", options).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, options = {})
  @client.put("domains/#{domain}", options).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, options = {})
  @client.put("domains/#{domain}/tracking/click", options).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, options = {})
  @client.put("domains/#{domain}/tracking/open", options).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, options = {})
  @client.put("domains/#{domain}/tracking/unsubscribe", options).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, , options = {})
  @client.put("domains/#{domain}/credentials/#{}", options).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