Skip to content

Commit 751fcb4

Browse files
author
Dustin Shields-Cloues
committed
Add calls for managing message metadata
1 parent 03e3e28 commit 751fcb4

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

lib/mandrill.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def cast_error(body)
7474
'Unknown_IP' => UnknownIPError,
7575
'Invalid_EmptyDefaultPool' => InvalidEmptyDefaultPoolError,
7676
'Invalid_DeleteDefaultPool' => InvalidDeleteDefaultPoolError,
77-
'Invalid_DeleteNonEmptyPool' => InvalidDeleteNonEmptyPoolError
77+
'Invalid_DeleteNonEmptyPool' => InvalidDeleteNonEmptyPoolError,
78+
'Metadata_FieldLimit' => MetadataFieldLimitError,
79+
'Unknown_MetadataField' => UnknownMetadataFieldError
7880
}
7981

8082
begin
@@ -134,6 +136,9 @@ def webhooks()
134136
def senders()
135137
Senders.new self
136138
end
139+
def metadata()
140+
Metadata.new self
141+
end
137142
end
138143
end
139144

lib/mandrill/api.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,5 +1994,59 @@ def time_series(address)
19941994
end
19951995

19961996
end
1997+
class Metadata
1998+
attr_accessor :master
1999+
2000+
def initialize(master)
2001+
@master = master
2002+
end
2003+
2004+
# Get the list of custom metadata fields indexed for the account.
2005+
# @return [Array] the custom metadata fields for the account
2006+
# - [Hash] return[] the individual custom metadata field info
2007+
# - [String] name the unique identifier of the metadata field to update
2008+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
2009+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
2010+
def list()
2011+
_params = {}
2012+
return @master.call 'metadata/list', _params
2013+
end
2014+
2015+
# Add a new custom metadata field to be indexed for the account.
2016+
# @param [String] name a unique identifier for the metadata field
2017+
# @param [String] view_template optional Mustache template to control how the metadata is rendered in your activity log
2018+
# @return [Hash] the information saved about the new metadata field
2019+
# - [String] name the unique identifier of the metadata field to update
2020+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
2021+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
2022+
def add(name, view_template=nil)
2023+
_params = {:name => name, :view_template => view_template}
2024+
return @master.call 'metadata/add', _params
2025+
end
2026+
2027+
# Update an existing custom metadata field.
2028+
# @param [String] name the unique identifier of the metadata field to update
2029+
# @param [String] view_template optional Mustache template to control how the metadata is rendered in your activity log
2030+
# @return [Hash] the information for the updated metadata field
2031+
# - [String] name the unique identifier of the metadata field to update
2032+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
2033+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
2034+
def update(name, view_template)
2035+
_params = {:name => name, :view_template => view_template}
2036+
return @master.call 'metadata/update', _params
2037+
end
2038+
2039+
# Delete an existing custom metadata field. Deletion isn't instataneous, and /metadata/list will continue to return the field until the asynchronous deletion process is complete.
2040+
# @param [String] name the unique identifier of the metadata field to update
2041+
# @return [Hash] the information for the deleted metadata field
2042+
# - [String] name the unique identifier of the metadata field to update
2043+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
2044+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
2045+
def delete(name)
2046+
_params = {:name => name}
2047+
return @master.call 'metadata/delete', _params
2048+
end
2049+
2050+
end
19972051
end
19982052

lib/mandrill/errors.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,9 @@ class InvalidDeleteDefaultPoolError < Error
4747
end
4848
class InvalidDeleteNonEmptyPoolError < Error
4949
end
50+
class MetadataFieldLimitError < Error
51+
end
52+
class UnknownMetadataFieldError < Error
53+
end
5054
end
5155

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.49'
3+
s.version = '1.0.50'
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)