Skip to content

Commit 329a6ce

Browse files
author
MailChimp Devs
committed
Add API calls for template labels, tracking domains, and inbound domains and routes
1 parent c14a52b commit 329a6ce

4 files changed

Lines changed: 149 additions & 7 deletions

File tree

lib/mandrill.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ def cast_error(body)
6363
'Invalid_Reject' => InvalidRejectError,
6464
'Unknown_Sender' => UnknownSenderError,
6565
'Unknown_Url' => UnknownUrlError,
66+
'Unknown_TrackingDomain' => UnknownTrackingDomainError,
6667
'Invalid_Template' => InvalidTemplateError,
6768
'Unknown_Webhook' => UnknownWebhookError,
6869
'Unknown_InboundDomain' => UnknownInboundDomainError,
70+
'Unknown_InboundRoute' => UnknownInboundRouteError,
6971
'Unknown_Export' => UnknownExportError,
7072
'IP_ProvisionLimit' => IPProvisionLimitError,
7173
'Unknown_Pool' => UnknownPoolError,

lib/mandrill/api.rb

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ def initialize(master)
1616
# @param [String] code the HTML code for the template with mc:edit attributes for the editable elements
1717
# @param [String] text a default text part to be used when sending with this template
1818
# @param [Boolean] publish set to false to add a draft template without publishing
19+
# @param [Array] labels an optional array of up to 10 labels to use for filtering templates
20+
# - [String] labels[] a single label
1921
# @return [Hash] the information saved about the new template
2022
# - [String] slug the immutable unique code name of the template
2123
# - [String] name the name of the template
24+
# - [Array] labels the list of labels applied to the template
25+
# - [String] labels[] a single label
2226
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
2327
# - [String] subject the subject line of the template, if provided - draft version
2428
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -33,8 +37,8 @@ def initialize(master)
3337
# - [String] published_at the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
3438
# - [String] created_at the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
3539
# - [String] updated_at the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
36-
def add(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil, publish=true)
37-
_params = {:name => name, :from_email => from_email, :from_name => from_name, :subject => subject, :code => code, :text => text, :publish => publish}
40+
def add(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil, publish=true, labels=[])
41+
_params = {:name => name, :from_email => from_email, :from_name => from_name, :subject => subject, :code => code, :text => text, :publish => publish, :labels => labels}
3842
return @master.call 'templates/add', _params
3943
end
4044

@@ -43,6 +47,8 @@ def add(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil, pu
4347
# @return [Hash] the requested template information
4448
# - [String] slug the immutable unique code name of the template
4549
# - [String] name the name of the template
50+
# - [Array] labels the list of labels applied to the template
51+
# - [String] labels[] a single label
4652
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
4753
# - [String] subject the subject line of the template, if provided - draft version
4854
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -70,9 +76,13 @@ def info(name)
7076
# @param [String] code the new code for the template
7177
# @param [String] text the new default text part to be used
7278
# @param [Boolean] publish set to false to update the draft version of the template without publishing
79+
# @param [Array] labels an optional array of up to 10 labels to use for filtering templates
80+
# - [String] labels[] a single label
7381
# @return [Hash] the template that was updated
7482
# - [String] slug the immutable unique code name of the template
7583
# - [String] name the name of the template
84+
# - [Array] labels the list of labels applied to the template
85+
# - [String] labels[] a single label
7686
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
7787
# - [String] subject the subject line of the template, if provided - draft version
7888
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -87,8 +97,8 @@ def info(name)
8797
# - [String] published_at the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
8898
# - [String] created_at the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
8999
# - [String] updated_at the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
90-
def update(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil, publish=true)
91-
_params = {:name => name, :from_email => from_email, :from_name => from_name, :subject => subject, :code => code, :text => text, :publish => publish}
100+
def update(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil, publish=true, labels=nil)
101+
_params = {:name => name, :from_email => from_email, :from_name => from_name, :subject => subject, :code => code, :text => text, :publish => publish, :labels => labels}
92102
return @master.call 'templates/update', _params
93103
end
94104

@@ -97,6 +107,8 @@ def update(name, from_email=nil, from_name=nil, subject=nil, code=nil, text=nil,
97107
# @return [Hash] the template that was published
98108
# - [String] slug the immutable unique code name of the template
99109
# - [String] name the name of the template
110+
# - [Array] labels the list of labels applied to the template
111+
# - [String] labels[] a single label
100112
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
101113
# - [String] subject the subject line of the template, if provided - draft version
102114
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -121,6 +133,8 @@ def publish(name)
121133
# @return [Hash] the template that was deleted
122134
# - [String] slug the immutable unique code name of the template
123135
# - [String] name the name of the template
136+
# - [Array] labels the list of labels applied to the template
137+
# - [String] labels[] a single label
124138
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
125139
# - [String] subject the subject line of the template, if provided - draft version
126140
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -141,10 +155,13 @@ def delete(name)
141155
end
142156

143157
# Return a list of all the templates available to this user
158+
# @param [String] label an optional label to filter the templates
144159
# @return [Array] an array of structs with information about each template
145160
# - [Hash] return[] the information on each template in the account
146161
# - [String] slug the immutable unique code name of the template
147162
# - [String] name the name of the template
163+
# - [Array] labels the list of labels applied to the template
164+
# - [String] labels[] a single label
148165
# - [String] code the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
149166
# - [String] subject the subject line of the template, if provided - draft version
150167
# - [String] from_email the default sender address for the template, if provided - draft version
@@ -159,8 +176,8 @@ def delete(name)
159176
# - [String] published_at the date and time the template was last published as a UTC string in YYYY-MM-DD HH:MM:SS format, or null if it has not been published
160177
# - [String] created_at the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
161178
# - [String] updated_at the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
162-
def list()
163-
_params = {}
179+
def list(label=nil)
180+
_params = {:label => label}
164181
return @master.call 'templates/list', _params
165182
end
166183

@@ -486,17 +503,88 @@ def domains()
486503
return @master.call 'inbound/domains', _params
487504
end
488505

506+
# Add an inbound domain to your account
507+
# @param [String] domain a domain name
508+
# @return [Hash] information about the domain
509+
# - [String] domain the domain name that is accepting mail
510+
# - [String] created_at the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
511+
# - [Boolean] valid_mx true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
512+
def add_domain(domain)
513+
_params = {:domain => domain}
514+
return @master.call 'inbound/add-domain', _params
515+
end
516+
517+
# Check the MX settings for an inbound domain. The domain must have already been added with the add-domain call
518+
# @param [String] domain an existing inbound domain
519+
# @return [Hash] information about the inbound domain
520+
# - [String] domain the domain name that is accepting mail
521+
# - [String] created_at the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
522+
# - [Boolean] valid_mx true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
523+
def check_domain(domain)
524+
_params = {:domain => domain}
525+
return @master.call 'inbound/check-domain', _params
526+
end
527+
528+
# Delete an inbound domain from the account. All mail will stop routing for this domain immediately.
529+
# @param [String] domain an existing inbound domain
530+
# @return [Hash] information about the deleted domain
531+
# - [String] domain the domain name that is accepting mail
532+
# - [String] created_at the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
533+
# - [Boolean] valid_mx true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
534+
def delete_domain(domain)
535+
_params = {:domain => domain}
536+
return @master.call 'inbound/delete-domain', _params
537+
end
538+
489539
# List the mailbox routes defined for an inbound domain
490540
# @param [String] domain the domain to check
491541
# @return [Array] the routes associated with the domain
492542
# - [Hash] return[] the individual mailbox route
543+
# - [String] id the unique identifier of the route
493544
# - [String] pattern the search pattern that the mailbox name should match
494545
# - [String] url the webhook URL where inbound messages will be published
495546
def routes(domain)
496547
_params = {:domain => domain}
497548
return @master.call 'inbound/routes', _params
498549
end
499550

551+
# Add a new mailbox route to an inbound domain
552+
# @param [String] domain an existing inbound domain
553+
# @param [String] pattern the search pattern that the mailbox name should match
554+
# @param [String] url the webhook URL where the inbound messages will be published
555+
# @return [Hash] the added mailbox route information
556+
# - [String] id the unique identifier of the route
557+
# - [String] pattern the search pattern that the mailbox name should match
558+
# - [String] url the webhook URL where inbound messages will be published
559+
def add_route(domain, pattern, url)
560+
_params = {:domain => domain, :pattern => pattern, :url => url}
561+
return @master.call 'inbound/add-route', _params
562+
end
563+
564+
# Update the pattern or webhook of an existing inbound mailbox route. If null is provided for any fields, the values will remain unchanged.
565+
# @param [String] id the unique identifier of an existing mailbox route
566+
# @param [String] pattern the search pattern that the mailbox name should match
567+
# @param [String] url the webhook URL where the inbound messages will be published
568+
# @return [Hash] the updated mailbox route information
569+
# - [String] id the unique identifier of the route
570+
# - [String] pattern the search pattern that the mailbox name should match
571+
# - [String] url the webhook URL where inbound messages will be published
572+
def update_route(id, pattern=nil, url=nil)
573+
_params = {:id => id, :pattern => pattern, :url => url}
574+
return @master.call 'inbound/update-route', _params
575+
end
576+
577+
# Delete an existing inbound mailbox route
578+
# @param [String] id the unique identifier of an existing route
579+
# @return [Hash] the deleted mailbox route information
580+
# - [String] id the unique identifier of the route
581+
# - [String] pattern the search pattern that the mailbox name should match
582+
# - [String] url the webhook URL where inbound messages will be published
583+
def delete_route(id)
584+
_params = {:id => id}
585+
return @master.call 'inbound/delete-route', _params
586+
end
587+
500588
# Take a raw MIME document destined for a domain with inbound domains set up, and send it to the inbound hook exactly as if it had been sent over SMTP
501589
# @param [String] raw_message the full MIME document of an email message
502590
# @param [Array, nil] to optionally define the recipients to receive the message - otherwise we'll use the To, Cc, and Bcc headers provided in the document
@@ -1523,6 +1611,54 @@ def time_series(url)
15231611
return @master.call 'urls/time-series', _params
15241612
end
15251613

1614+
# Get the list of tracking domains set up for this account
1615+
# @return [Array] the tracking domains and their status
1616+
# - [Hash] return[] the individual tracking domain
1617+
# - [String] domain the tracking domain name
1618+
# - [String] created_at the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
1619+
# - [String] last_tested_at when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
1620+
# - [Hash] cname details about the domain's CNAME record
1621+
# - [Boolean] valid whether the domain's CNAME record is valid for use with Mandrill
1622+
# - [String] valid_after when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
1623+
# - [String] error an error describing the CNAME record, or null if the record is correct
1624+
# - [Boolean] valid_tracking whether this domain can be used as a tracking domain for email.
1625+
def tracking_domains()
1626+
_params = {}
1627+
return @master.call 'urls/tracking-domains', _params
1628+
end
1629+
1630+
# Add a tracking domain to your account
1631+
# @param [String] domain a domain name
1632+
# @return [Hash] information about the domain
1633+
# - [String] domain the tracking domain name
1634+
# - [String] created_at the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
1635+
# - [String] last_tested_at when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
1636+
# - [Hash] cname details about the domain's CNAME record
1637+
# - [Boolean] valid whether the domain's CNAME record is valid for use with Mandrill
1638+
# - [String] valid_after when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
1639+
# - [String] error an error describing the CNAME record, or null if the record is correct
1640+
# - [Boolean] valid_tracking whether this domain can be used as a tracking domain for email.
1641+
def add_tracking_domain(domain)
1642+
_params = {:domain => domain}
1643+
return @master.call 'urls/add-tracking-domain', _params
1644+
end
1645+
1646+
# Checks the CNAME settings for a tracking domain. The domain must have been added already with the add-tracking-domain call
1647+
# @param [String] domain an existing tracking domain name
1648+
# @return [Hash] information about the tracking domain
1649+
# - [String] domain the tracking domain name
1650+
# - [String] created_at the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
1651+
# - [String] last_tested_at when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
1652+
# - [Hash] cname details about the domain's CNAME record
1653+
# - [Boolean] valid whether the domain's CNAME record is valid for use with Mandrill
1654+
# - [String] valid_after when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
1655+
# - [String] error an error describing the CNAME record, or null if the record is correct
1656+
# - [Boolean] valid_tracking whether this domain can be used as a tracking domain for email.
1657+
def check_tracking_domain(domain)
1658+
_params = {:domain => domain}
1659+
return @master.call 'urls/check-tracking-domain', _params
1660+
end
1661+
15261662
end
15271663
class Webhooks
15281664
attr_accessor :master

lib/mandrill/errors.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ class UnknownSenderError < Error
2323
end
2424
class UnknownUrlError < Error
2525
end
26+
class UnknownTrackingDomainError < Error
27+
end
2628
class InvalidTemplateError < Error
2729
end
2830
class UnknownWebhookError < Error
2931
end
3032
class UnknownInboundDomainError < Error
3133
end
34+
class UnknownInboundRouteError < Error
35+
end
3236
class UnknownExportError < Error
3337
end
3438
class IPProvisionLimitError < Error

mandrill-api.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'mandrill-api'
3-
s.version = '1.0.47'
3+
s.version = '1.0.48'
44
s.summary = 'A Ruby API library for the Mandrill email as a service platform.'
55
s.description = s.summary
66
s.authors = ['Mandrill Devs']

0 commit comments

Comments
 (0)