MailChimp avatar MailChimp committed 12c2038

Initial import of the official Mandrill Python client

Comments (0)

Files changed (7)

+Mandrill is a Python API client and suite of CLI-based tools for the Mandrill email as a platform service.
+
+The API client is comprehensive, but the CLI functionality is minimal at this time.
+
+Examples:
+import mandrill
+m = mandrill.Mandrill('YOUR_API_KEY')
+print m.users.ping()
+--> "PONG!"
+
+CLI Examples:
+mandrill setup
+mandrill ping -c10
+mandrill send -f from@example.com -t to@example.com -s "My Subject Line" < content.html
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = _build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/mandrill.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/mandrill.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/mandrill"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/mandrill"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# mandrill documentation build configuration file, created by
+# sphinx-quickstart on Fri Jul  6 19:53:07 2012.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = 'mandrill'
+copyright = '2012, Mandrill Devs'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.1'
+# The full version, including alpha/beta/rc tags.
+release = '0.1.0'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'mandrilldoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'mandrill.tex', 'mandrill Documentation',
+   'Mandrill Devs', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'mandrill', 'mandrill Documentation',
+     ['Mandrill Devs'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+  ('index', 'mandrill', 'mandrill Documentation',
+   'Mandrill Devs', 'mandrill', 'One line description of project.',
+   'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+.. mandrill documentation master file, created by
+   sphinx-quickstart on Fri Jul  6 19:53:07 2012.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to mandrill's documentation!
+====================================
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+import requests, os.path, logging, sys, time
+try:
+    import json as json
+except:
+    import simplejson as json
+
+class Error(Exception):
+    pass
+class ValidationError(Error):
+    pass
+class InvalidKeyError(Error):
+    pass
+class UnknownTemplateError(Error):
+    pass
+class InvalidTagNameError(Error):
+    pass
+class InvalidRejectError(Error):
+    pass
+class UnknownSenderError(Error):
+    pass
+class UnknownUrlError(Error):
+    pass
+class InvalidTemplateError(Error):
+    pass
+class UnknownWebhookError(Error):
+    pass
+
+ROOT = 'https://mandrillapp.com/api/1.0/'
+ERROR_MAP = {
+    'ValidationError': ValidationError,
+    'Invalid_Key': InvalidKeyError,
+    'Unknown_Template': UnknownTemplateError,
+    'Invalid_Tag_Name': InvalidTagNameError,
+    'Invalid_Reject': InvalidRejectError,
+    'Unknown_Sender': UnknownSenderError,
+    'Unknown_Url': UnknownUrlError,
+    'Invalid_Template': InvalidTemplateError,
+    'Unknown_Webhook': UnknownWebhookError
+}
+
+logger = logging.getLogger('mandrill')
+logger.setLevel(logging.INFO)
+logger.addHandler(logging.StreamHandler(sys.stderr))
+
+class Mandrill(object):
+    def __init__(self, apikey=None, debug=False):
+        '''Initialize the API client
+
+        Args:
+           apikey (str|None): provide your Mandrill API key.  If this is left as None, we will attempt to get the API key from the following locations::
+               - MANDRILL_APIKEY in the environment vars
+               - ~/.mandrill.key for the user executing the script
+               - /etc/mandrill.key
+           debug (bool): set to True to log all the request and response information to the "mandrill" logger at the INFO level.  When set to false, it will log at the DEBUG level.  By default it will write log entries to STDERR
+       '''
+
+        self.session = requests.session()
+        if debug:
+            self.level = logging.INFO
+        else:
+            self.level = logging.DEBUG
+        self.last_request = None
+
+        if apikey is None:
+            if 'MANDRILL_APIKEY' in os.environ:
+                apikey = os.environ['MANDRILL_APIKEY']
+            else:
+                apikey = self.read_configs()
+
+        if apikey is None: raise Error('You must provide a Mandrill API key')
+        self.apikey = apikey
+
+        self.templates = Templates(self)
+        self.users = Users(self)
+        self.rejects = Rejects(self)
+        self.tags = Tags(self)
+        self.messages = Messages(self)
+        self.urls = Urls(self)
+        self.webhooks = Webhooks(self)
+        self.senders = Senders(self)
+    
+    def call(self, url, params=None):
+        '''Actually make the API call with the given params - this should only be called by the namespace methods - use the helpers in regular usage like m.tags.list()'''
+        if params is None: params = {}
+        params['key'] = self.apikey
+        params = json.dumps(params)
+        self.log('POST to %s%s.json: %s' % (ROOT, url, params))
+        start = time.time()
+        r = self.session.post('%s%s.json' % (ROOT, url), data=params, headers={'content-type': 'application/json', 'user-agent': 'Mandrill-Python/1.0'})
+        try:
+            remote_addr = r.raw._original_response.fp._sock.getpeername() # grab the remote_addr before grabbing the text since the socket will go away
+        except:
+            remote_addr = (None, None) #we use two private fields when getting the remote_addr, so be a little robust against errors
+
+        response_body = r.text
+        complete_time = time.time() - start
+        self.log('Received %s in %.2fms: %s' % (r.status_code, complete_time * 1000, r.text))
+        self.last_request = {'url': url, 'request_body': params, 'response_body': r.text, 'remote_addr': remote_addr, 'response': r, 'time': complete_time}
+
+        result = r.json
+        if r.status_code != requests.codes.ok:
+            raise self.cast_error(result)
+        return result
+
+    def cast_error(self, result):
+        '''Take a result representing an error and cast it to a specific exception if possible (use a generic mandrill.Error exception for unknown cases)'''
+        if not 'status' in result or result['status'] != 'error' or not 'name' in result:
+            raise Error('We received an unexpected error: %r' % result)
+
+        if result['name'] in ERROR_MAP:
+            return ERROR_MAP[result['name']](result['message'])
+        return Error(result['message'])
+
+    def read_configs(self):
+        '''Try to read the API key from a series of files if it's not provided in code'''
+        paths = [os.path.expanduser('~/.mandrill.key'), '/etc/mandrill.key']
+        for path in paths:
+            try:
+                f = open(path, 'r')
+                apikey = f.read().strip()
+                f.close()
+                if apikey != '':
+                    return apikey
+            except:
+                pass
+
+        return None
+
+    def log(self, *args, **kwargs):
+        '''Proxy access to the mandrill logger, changing the level based on the debug setting'''
+        logger.log(self.level, *args, **kwargs)
+
+    def __repr__(self):
+        return '<Mandrill %s>' % self.apikey
+
+class Templates(object):
+    def __init__(self, master):
+        self.master = master
+
+    def add(self, name, code, publish=True):
+        """Add a new template
+
+        Args:
+           name (string): the name for the new template - must be unique
+           code (string): the HTML code for the template with mc:edit attributes for the editable elements
+           publish (boolean): set to false to add a draft template without publishing
+
+        Returns:
+           struct.  the information saved about the new template::
+               name (string): the name of the template - draft version
+               code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+               publish_name (string): the name that the template was published as, if it has been published
+               publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+               published_at (string): 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
+               created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+        Raises:
+           InvalidTemplateError: The given template name already exists or contains invalid characters
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name, 'code': code, 'publish': publish}
+        return self.master.call('templates/add', _params)
+
+    def info(self, name):
+        """Get the information for an existing template
+
+        Args:
+           name (string): the name of an existing template
+
+        Returns:
+           struct.  the requested template information::
+               name (string): the name of the template - draft version
+               code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+               publish_name (string): the name that the template was published as, if it has been published
+               publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+               published_at (string): 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
+               created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name}
+        return self.master.call('templates/info', _params)
+
+    def update(self, name, code, publish=True):
+        """Update the code for an existing template
+
+        Args:
+           name (string): the name of an existing template
+           code (string): the new code for the template
+           publish (boolean): set to false to update the draft version of the template without publishing
+
+        Returns:
+           struct.  the template that was updated::
+               name (string): the name of the template - draft version
+               code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+               publish_name (string): the name that the template was published as, if it has been published
+               publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+               published_at (string): 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
+               created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name, 'code': code, 'publish': publish}
+        return self.master.call('templates/update', _params)
+
+    def publish(self, name):
+        """Publish the content for the template. Any new messages sent using this template will start using the content that was previously in draft.
+
+        Args:
+           name (string): the name of an existing template
+
+        Returns:
+           struct.  the template that was published::
+               name (string): the name of the template - draft version
+               code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+               publish_name (string): the name that the template was published as, if it has been published
+               publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+               published_at (string): 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
+               created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name}
+        return self.master.call('templates/publish', _params)
+
+    def delete(self, name):
+        """Delete a template
+
+        Args:
+           name (string): the name of an existing template
+
+        Returns:
+           struct.  the template that was deleted::
+               name (string): the name of the template - draft version
+               code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+               publish_name (string): the name that the template was published as, if it has been published
+               publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+               published_at (string): 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
+               created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name}
+        return self.master.call('templates/delete', _params)
+
+    def list(self, ):
+        """Return a list of all the templates available to this user
+
+        Returns:
+           array.  an array of structs with information about each template::
+               [] (struct): the information on each template in the account::
+                   [].name (string): the name of the template - draft version
+                   [].code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements - draft version
+                   [].publish_name (string): the name that the template was published as, if it has been published
+                   [].publish_code (string): the full HTML code of the template, with mc:edit attributes marking the editable elements that are available as published, if it has been published
+                   [].published_at (string): 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
+                   [].created_at (string): the date and time the template was first created as a UTC string in YYYY-MM-DD HH:MM:SS format
+                   [].updated_at (string): the date and time the template was last modified as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('templates/list', _params)
+
+    def time_series(self, name):
+        """Return the recent history (hourly stats for the last 30 days) for a template
+
+        Args:
+           name (string): the name of an existing template
+
+        Returns:
+           array.  the array of history information::
+               [] (struct): the stats for a single hour::
+                   [].time (string): the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the number of emails that were sent during the hour
+                   [].hard_bounces (integer): the number of emails that hard bounced during the hour
+                   [].soft_bounces (integer): the number of emails that soft bounced during the hour
+                   [].rejects (integer): the number of emails that were rejected during the hour
+                   [].complaints (integer): the number of spam complaints received during the hour
+                   [].opens (integer): the number of emails opened during the hour
+                   [].unique_opens (integer): the number of unique opens generated by messages sent during the hour
+                   [].clicks (integer): the number of tracked URLs clicked during the hour
+                   [].unique_clicks (integer): the number of unique clicks generated by messages sent during the hour
+
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'name': name}
+        return self.master.call('templates/time-series', _params)
+
+    def render(self, template_name, template_content, merge_vars=None):
+        """Inject content and optionally merge fields into a template, returning the HTML that results
+
+        Args:
+           template_name (string): the name of a template that exists in the user's account
+           template_content (array): an array of template content to render.  Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block::
+               template_content[] (struct): the injection of a single piece of content into a single editable region::
+                   template_content[].name (string): the name of the mc:edit editable region to inject into
+                   template_content[].content (string): the content to inject
+
+           merge_vars (array): optional merge variables to use for injecting merge field content.  If this is not provided, no merge fields will be replaced.::
+               merge_vars[] (struct): a single merge variable::
+                   merge_vars[].name (string): the merge variable's name. Merge variable names are case-insensitive and may not start with _
+                   merge_vars[].content (string): the merge variable's content
+
+
+        Returns:
+           struct.  the result of rendering the given template with the content and merge field values injected::
+               html (string): the rendered HTML as a string
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'template_name': template_name, 'template_content': template_content, 'merge_vars': merge_vars}
+        return self.master.call('templates/render', _params)
+
+
+class Users(object):
+    def __init__(self, master):
+        self.master = master
+
+    def info(self, ):
+        """Return the information about the API-connected user
+
+        Returns:
+           struct.  the user information including username, key, reputation, quota, and historical sending stats::
+               username (string): the username of the user (used for SMTP authentication)
+               created_at (string): the date and time that the user's Mandrill account was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               public_id (string): a unique, permanent identifier for this user
+               reputation (integer): the reputation of the user on a scale from 0 to 100, with 75 generally being a "good" reputation
+               hourly_quota (integer): the maximum number of emails Mandrill will deliver for this user each hour.  Any emails beyond that will be accepted and queued for later delivery.  Users with higher reputations will have higher hourly quotas
+               backlog (integer): the number of emails that are queued for delivery due to exceeding your monthly or hourly quotas
+               stats (struct): an aggregate summary of the account's sending stats::
+                   stats.today (struct): stats for this user so far today::
+                       stats.today.sent (integer): the number of emails sent for this user so far today
+                       stats.today.hard_bounces (integer): the number of emails hard bounced for this user so far today
+                       stats.today.soft_bounces (integer): the number of emails soft bounced for this user so far today
+                       stats.today.rejects (integer): the number of emails rejected for sending this user so far today
+                       stats.today.complaints (integer): the number of spam complaints for this user so far today
+                       stats.today.unsubs (integer): the number of unsubscribes for this user so far today
+                       stats.today.opens (integer): the number of times emails have been opened for this user so far today
+                       stats.today.unique_opens (integer): the number of unique opens for emails sent for this user so far today
+                       stats.today.clicks (integer): the number of URLs that have been clicked for this user so far today
+                       stats.today.unique_clicks (integer): the number of unique clicks for emails sent for this user so far today
+
+                   stats.last_7_days (struct): stats for this user in the last 7 days::
+                       stats.last_7_days.sent (integer): the number of emails sent for this user in the last 7 days
+                       stats.last_7_days.hard_bounces (integer): the number of emails hard bounced for this user in the last 7 days
+                       stats.last_7_days.soft_bounces (integer): the number of emails soft bounced for this user in the last 7 days
+                       stats.last_7_days.rejects (integer): the number of emails rejected for sending this user in the last 7 days
+                       stats.last_7_days.complaints (integer): the number of spam complaints for this user in the last 7 days
+                       stats.last_7_days.unsubs (integer): the number of unsubscribes for this user in the last 7 days
+                       stats.last_7_days.opens (integer): the number of times emails have been opened for this user in the last 7 days
+                       stats.last_7_days.unique_opens (integer): the number of unique opens for emails sent for this user in the last 7 days
+                       stats.last_7_days.clicks (integer): the number of URLs that have been clicked for this user in the last 7 days
+                       stats.last_7_days.unique_clicks (integer): the number of unique clicks for emails sent for this user in the last 7 days
+
+                   stats.last_30_days (struct): stats for this user in the last 30 days::
+                       stats.last_30_days.sent (integer): the number of emails sent for this user in the last 30 days
+                       stats.last_30_days.hard_bounces (integer): the number of emails hard bounced for this user in the last 30 days
+                       stats.last_30_days.soft_bounces (integer): the number of emails soft bounced for this user in the last 30 days
+                       stats.last_30_days.rejects (integer): the number of emails rejected for sending this user in the last 30 days
+                       stats.last_30_days.complaints (integer): the number of spam complaints for this user in the last 30 days
+                       stats.last_30_days.unsubs (integer): the number of unsubscribes for this user in the last 30 days
+                       stats.last_30_days.opens (integer): the number of times emails have been opened for this user in the last 30 days
+                       stats.last_30_days.unique_opens (integer): the number of unique opens for emails sent for this user in the last 30 days
+                       stats.last_30_days.clicks (integer): the number of URLs that have been clicked for this user in the last 30 days
+                       stats.last_30_days.unique_clicks (integer): the number of unique clicks for emails sent for this user in the last 30 days
+
+                   stats.last_60_days (struct): stats for this user in the last 60 days::
+                       stats.last_60_days.sent (integer): the number of emails sent for this user in the last 60 days
+                       stats.last_60_days.hard_bounces (integer): the number of emails hard bounced for this user in the last 60 days
+                       stats.last_60_days.soft_bounces (integer): the number of emails soft bounced for this user in the last 60 days
+                       stats.last_60_days.rejects (integer): the number of emails rejected for sending this user in the last 60 days
+                       stats.last_60_days.complaints (integer): the number of spam complaints for this user in the last 60 days
+                       stats.last_60_days.unsubs (integer): the number of unsubscribes for this user in the last 60 days
+                       stats.last_60_days.opens (integer): the number of times emails have been opened for this user in the last 60 days
+                       stats.last_60_days.unique_opens (integer): the number of unique opens for emails sent for this user in the last 60 days
+                       stats.last_60_days.clicks (integer): the number of URLs that have been clicked for this user in the last 60 days
+                       stats.last_60_days.unique_clicks (integer): the number of unique clicks for emails sent for this user in the last 60 days
+
+                   stats.last_90_days (struct): stats for this user in the last 90 days::
+                       stats.last_90_days.sent (integer): the number of emails sent for this user in the last 90 days
+                       stats.last_90_days.hard_bounces (integer): the number of emails hard bounced for this user in the last 90 days
+                       stats.last_90_days.soft_bounces (integer): the number of emails soft bounced for this user in the last 90 days
+                       stats.last_90_days.rejects (integer): the number of emails rejected for sending this user in the last 90 days
+                       stats.last_90_days.complaints (integer): the number of spam complaints for this user in the last 90 days
+                       stats.last_90_days.unsubs (integer): the number of unsubscribes for this user in the last 90 days
+                       stats.last_90_days.opens (integer): the number of times emails have been opened for this user in the last 90 days
+                       stats.last_90_days.unique_opens (integer): the number of unique opens for emails sent for this user in the last 90 days
+                       stats.last_90_days.clicks (integer): the number of URLs that have been clicked for this user in the last 90 days
+                       stats.last_90_days.unique_clicks (integer): the number of unique clicks for emails sent for this user in the last 90 days
+
+                   stats.all_time (struct): stats for the lifetime of the user's account::
+                       stats.all_time.sent (integer): the number of emails sent in the lifetime of the user's account
+                       stats.all_time.hard_bounces (integer): the number of emails hard bounced in the lifetime of the user's account
+                       stats.all_time.soft_bounces (integer): the number of emails soft bounced in the lifetime of the user's account
+                       stats.all_time.rejects (integer): the number of emails rejected for sending this user so far today
+                       stats.all_time.complaints (integer): the number of spam complaints in the lifetime of the user's account
+                       stats.all_time.unsubs (integer): the number of unsubscribes in the lifetime of the user's account
+                       stats.all_time.opens (integer): the number of times emails have been opened in the lifetime of the user's account
+                       stats.all_time.unique_opens (integer): the number of unique opens for emails sent in the lifetime of the user's account
+                       stats.all_time.clicks (integer): the number of URLs that have been clicked in the lifetime of the user's account
+                       stats.all_time.unique_clicks (integer): the number of unique clicks for emails sent in the lifetime of the user's account
+
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('users/info', _params)
+
+    def ping(self, ):
+        """Validate an API key and respond to a ping
+
+        Returns:
+           string.  the string "PONG!"
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('users/ping', _params)
+
+    def ping2(self, ):
+        """Validate an API key and respond to a ping (anal JSON parser version)
+
+        Returns:
+           struct.  a struct with one key "PING" with a static value "PONG!"
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('users/ping2', _params)
+
+    def senders(self, ):
+        """Return the senders that have tried to use this account, both verified and unverified
+
+        Returns:
+           array.  an array of sender data, one for each sending addresses used by the account::
+               [] (struct): the information on each sending address in the account::
+                   [].address (string): the sender's email address
+                   [].created_at (string): the date and time that the sender was first seen by Mandrill as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the total number of messages sent by this sender
+                   [].hard_bounces (integer): the total number of hard bounces by messages by this sender
+                   [].soft_bounces (integer): the total number of soft bounces by messages by this sender
+                   [].rejects (integer): the total number of rejected messages by this sender
+                   [].complaints (integer): the total number of spam complaints received for messages by this sender
+                   [].unsubs (integer): the total number of unsubscribe requests received for messages by this sender
+                   [].opens (integer): the total number of times messages by this sender have been opened
+                   [].clicks (integer): the total number of times tracked URLs in messages by this sender have been clicked
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('users/senders', _params)
+
+
+class Rejects(object):
+    def __init__(self, master):
+        self.master = master
+
+    def list(self, email=None):
+        """Retrieves your email rejection blacklist. You can provide an email
+address to limit the results. Returns up to 1000 results.
+
+        Args:
+           email (string): an optional email address to search by
+
+        Returns:
+           array.  Up to 1000 rejection entries::
+               [] (struct): the information for each rejection blacklist entry::
+                   [].email (string): the email that is blocked
+                   [].reason (string): the type of event (hard-bounce, soft-bounce, spam, unsub) that caused this rejection
+                   [].created_at (string): when the email was added to the blacklist
+                   [].expires_at (string): when the blacklist entry will expire (this may be in the past)
+                   [].expired (boolean): whether the blacklist entry has expired
+                   [].Sender (struct): sender the sender that this blacklist entry applies to, or null if none.
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'email': email}
+        return self.master.call('rejects/list', _params)
+
+    def delete(self, email):
+        """Deletes an email rejection. There is no limit to how many rejections
+you can remove from your blacklist, but keep in mind that each deletion
+has an affect on your reputation.
+
+        Args:
+           email (string): an email address
+
+        Returns:
+           struct.  a status object containing the address and whether the deletion succeeded.::
+               email (string): the email address that was removed from the blacklist
+               deleted (boolean): whether the address was deleted successfully.
+
+        Raises:
+           InvalidRejectError: The requested email is not in the rejection list
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'email': email}
+        return self.master.call('rejects/delete', _params)
+
+
+class Tags(object):
+    def __init__(self, master):
+        self.master = master
+
+    def list(self, ):
+        """Return all of the user-defined tag information
+
+        Returns:
+           array.  a list of user-defined tags::
+               [] (struct): a user-defined tag::
+                   [].tag (string): the actual tag as a string
+                   [].sent (integer): the total number of messages sent with this tag
+                   [].hard_bounces (integer): the total number of hard bounces by messages with this tag
+                   [].soft_bounces (integer): the total number of soft bounces by messages with this tag
+                   [].rejects (integer): the total number of rejected messages with this tag
+                   [].complaints (integer): the total number of spam complaints received for messages with this tag
+                   [].unsubs (integer): the total number of unsubscribe requests received for messages with this tag
+                   [].opens (integer): the total number of times messages with this tag have been opened
+                   [].clicks (integer): the total number of times tracked URLs in messages with this tag have been clicked
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('tags/list', _params)
+
+    def info(self, tag):
+        """Return more detailed information about a single tag, including aggregates of recent stats
+
+        Args:
+           tag (string): an existing tag name
+
+        Returns:
+           struct.  the detailed information on the tag::
+               tag (string): the actual tag as a string
+               sent (integer): the total number of messages sent with this tag
+               hard_bounces (integer): the total number of hard bounces by messages with this tag
+               soft_bounces (integer): the total number of soft bounces by messages with this tag
+               rejects (integer): the total number of rejected messages with this tag
+               complaints (integer): the total number of spam complaints received for messages with this tag
+               unsubs (integer): the total number of unsubscribe requests received for messages with this tag
+               opens (integer): the total number of times messages with this tag have been opened
+               clicks (integer): the total number of times tracked URLs in messages with this tag have been clicked
+               stats (struct): an aggregate summary of the tag's sending stats::
+                   stats.today (struct): stats with this tag so far today::
+                       stats.today.sent (integer): the number of emails sent with this tag so far today
+                       stats.today.hard_bounces (integer): the number of emails hard bounced with this tag so far today
+                       stats.today.soft_bounces (integer): the number of emails soft bounced with this tag so far today
+                       stats.today.rejects (integer): the number of emails rejected for sending this tag so far today
+                       stats.today.complaints (integer): the number of spam complaints with this tag so far today
+                       stats.today.unsubs (integer): the number of unsubscribes with this tag so far today
+                       stats.today.opens (integer): the number of times emails have been opened with this tag so far today
+                       stats.today.unique_opens (integer): the number of unique opens for emails sent with this tag so far today
+                       stats.today.clicks (integer): the number of URLs that have been clicked with this tag so far today
+                       stats.today.unique_clicks (integer): the number of unique clicks for emails sent with this tag so far today
+
+                   stats.last_7_days (struct): stats with this tag in the last 7 days::
+                       stats.last_7_days.sent (integer): the number of emails sent with this tag in the last 7 days
+                       stats.last_7_days.hard_bounces (integer): the number of emails hard bounced with this tag in the last 7 days
+                       stats.last_7_days.soft_bounces (integer): the number of emails soft bounced with this tag in the last 7 days
+                       stats.last_7_days.rejects (integer): the number of emails rejected for sending this tag in the last 7 days
+                       stats.last_7_days.complaints (integer): the number of spam complaints with this tag in the last 7 days
+                       stats.last_7_days.unsubs (integer): the number of unsubscribes with this tag in the last 7 days
+                       stats.last_7_days.opens (integer): the number of times emails have been opened with this tag in the last 7 days
+                       stats.last_7_days.unique_opens (integer): the number of unique opens for emails sent with this tag in the last 7 days
+                       stats.last_7_days.clicks (integer): the number of URLs that have been clicked with this tag in the last 7 days
+                       stats.last_7_days.unique_clicks (integer): the number of unique clicks for emails sent with this tag in the last 7 days
+
+                   stats.last_30_days (struct): stats with this tag in the last 30 days::
+                       stats.last_30_days.sent (integer): the number of emails sent with this tag in the last 30 days
+                       stats.last_30_days.hard_bounces (integer): the number of emails hard bounced with this tag in the last 30 days
+                       stats.last_30_days.soft_bounces (integer): the number of emails soft bounced with this tag in the last 30 days
+                       stats.last_30_days.rejects (integer): the number of emails rejected for sending this tag in the last 30 days
+                       stats.last_30_days.complaints (integer): the number of spam complaints with this tag in the last 30 days
+                       stats.last_30_days.unsubs (integer): the number of unsubscribes with this tag in the last 30 days
+                       stats.last_30_days.opens (integer): the number of times emails have been opened with this tag in the last 30 days
+                       stats.last_30_days.unique_opens (integer): the number of unique opens for emails sent with this tag in the last 30 days
+                       stats.last_30_days.clicks (integer): the number of URLs that have been clicked with this tag in the last 30 days
+                       stats.last_30_days.unique_clicks (integer): the number of unique clicks for emails sent with this tag in the last 30 days
+
+                   stats.last_60_days (struct): stats with this tag in the last 60 days::
+                       stats.last_60_days.sent (integer): the number of emails sent with this tag in the last 60 days
+                       stats.last_60_days.hard_bounces (integer): the number of emails hard bounced with this tag in the last 60 days
+                       stats.last_60_days.soft_bounces (integer): the number of emails soft bounced with this tag in the last 60 days
+                       stats.last_60_days.rejects (integer): the number of emails rejected for sending this tag in the last 60 days
+                       stats.last_60_days.complaints (integer): the number of spam complaints with this tag in the last 60 days
+                       stats.last_60_days.unsubs (integer): the number of unsubscribes with this tag in the last 60 days
+                       stats.last_60_days.opens (integer): the number of times emails have been opened with this tag in the last 60 days
+                       stats.last_60_days.unique_opens (integer): the number of unique opens for emails sent with this tag in the last 60 days
+                       stats.last_60_days.clicks (integer): the number of URLs that have been clicked with this tag in the last 60 days
+                       stats.last_60_days.unique_clicks (integer): the number of unique clicks for emails sent with this tag in the last 60 days
+
+                   stats.last_90_days (struct): stats with this tag in the last 90 days::
+                       stats.last_90_days.sent (integer): the number of emails sent with this tag in the last 90 days
+                       stats.last_90_days.hard_bounces (integer): the number of emails hard bounced with this tag in the last 90 days
+                       stats.last_90_days.soft_bounces (integer): the number of emails soft bounced with this tag in the last 90 days
+                       stats.last_90_days.rejects (integer): the number of emails rejected for sending this tag in the last 90 days
+                       stats.last_90_days.complaints (integer): the number of spam complaints with this tag in the last 90 days
+                       stats.last_90_days.unsubs (integer): the number of unsubscribes with this tag in the last 90 days
+                       stats.last_90_days.opens (integer): the number of times emails have been opened with this tag in the last 90 days
+                       stats.last_90_days.unique_opens (integer): the number of unique opens for emails sent with this tag in the last 90 days
+                       stats.last_90_days.clicks (integer): the number of URLs that have been clicked with this tag in the last 90 days
+                       stats.last_90_days.unique_clicks (integer): the number of unique clicks for emails sent with this tag in the last 90 days
+
+
+
+        Raises:
+           InvalidTagNameError: The requested tag does not exist or contains invalid characters
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'tag': tag}
+        return self.master.call('tags/info', _params)
+
+    def time_series(self, tag):
+        """Return the recent history (hourly stats for the last 30 days) for a tag
+
+        Args:
+           tag (string): an existing tag name
+
+        Returns:
+           array.  the array of history information::
+               [] (struct): the stats for a single hour::
+                   [].time (string): the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the number of emails that were sent during the hour
+                   [].hard_bounces (integer): the number of emails that hard bounced during the hour
+                   [].soft_bounces (integer): the number of emails that soft bounced during the hour
+                   [].rejects (integer): the number of emails that were rejected during the hour
+                   [].complaints (integer): the number of spam complaints received during the hour
+                   [].opens (integer): the number of emails opened during the hour
+                   [].unique_opens (integer): the number of unique opens generated by messages sent during the hour
+                   [].clicks (integer): the number of tracked URLs clicked during the hour
+                   [].unique_clicks (integer): the number of unique clicks generated by messages sent during the hour
+
+
+        Raises:
+           InvalidTagNameError: The requested tag does not exist or contains invalid characters
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'tag': tag}
+        return self.master.call('tags/time-series', _params)
+
+    def all_time_series(self, ):
+        """Return the recent history (hourly stats for the last 30 days) for all tags
+
+        Returns:
+           array.  the array of history information::
+               [] (struct): the stats for a single hour::
+                   [].time (string): the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the number of emails that were sent during the hour
+                   [].hard_bounces (integer): the number of emails that hard bounced during the hour
+                   [].soft_bounces (integer): the number of emails that soft bounced during the hour
+                   [].rejects (integer): the number of emails that were rejected during the hour
+                   [].complaints (integer): the number of spam complaints received during the hour
+                   [].opens (integer): the number of emails opened during the hour
+                   [].unique_opens (integer): the number of unique opens generated by messages sent during the hour
+                   [].clicks (integer): the number of tracked URLs clicked during the hour
+                   [].unique_clicks (integer): the number of unique clicks generated by messages sent during the hour
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('tags/all-time-series', _params)
+
+
+class Messages(object):
+    def __init__(self, master):
+        self.master = master
+
+    def send(self, message):
+        """Send a new transactional message through Mandrill
+
+        Args:
+           message (struct): the information on the message to send::
+               message.html (string): the full HTML content to be sent
+               message.text (string): optional full text content to be sent
+               message.subject (string): the message subject
+               message.from_email (string): the sender email address.
+               message.from_name (string): optional from name to be used
+               message.to (array): an array of recipient information.::
+                   message.to[] (struct): a single recipient's information.::
+                       message.to[].email (string): the email address of the recipient
+                       message.to[].name (string): the optional display name to use for the recipient
+
+
+               message.headers (struct): optional extra headers to add to the message (currently only Reply-To and X-* headers are allowed)
+               message.track_opens (boolean): whether or not to turn on open tracking for the message
+               message.track_clicks (boolean): whether or not to turn on click tracking for the message
+               message.auto_text (boolean): whether or not to automatically generate a text part for messages that are not given text
+               message.url_strip_qs (boolean): whether or not to strip the query string from URLs when aggregating tracked URL data
+               message.bcc_address (string): an optional address to receive an exact copy of each recipient's email
+               message.merge (boolean): whether to evaluate merge tags in the message. Will automatically be set to true if either merge_vars or global_merge_vars are provided.
+               message.global_merge_vars (array): global merge variables to use for all recipients. You can override these per recipient.::
+                   message.global_merge_vars[] (struct): a single global merge variable::
+                       message.global_merge_vars[].name (string): the global merge variable's name. Merge variable names are case-insensitive and may not start with _
+                       message.global_merge_vars[].content (string): the global merge variable's content
+
+
+               message.merge_vars (array): per-recipient merge variables, which override global merge variables with the same name.::
+                   message.merge_vars[] (struct): per-recipient merge variables::
+                       message.merge_vars[].rcpt (string): the email address of the recipient that the merge variables should apply to
+                       message.merge_vars[].vars (array): the recipient's merge variables::
+                           message.merge_vars[].vars[] (struct): a single merge variable::
+                               message.merge_vars[].vars[].name (string): the merge variable's name. Merge variable names are case-insensitive and may not start with _
+                               message.merge_vars[].vars[].content (string): the merge variable's content
+
+
+
+
+               message.tags (array): an array of string to tag the message with.  Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently.  Tags should be 50 characters or less.  Any tags starting with an underscore are reserved for internal use and will cause errors.::
+                   message.tags[] (string): a single tag - must not start with an underscore
+
+               message.google_analytics_domains (array): an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
+               message.google_analytics_campaign (array|string): optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
+               message.metadata (array): metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
+               message.attachments (array): an array of supported attachments to add to the message::
+                   message.attachments[] (struct): a single supported attachment::
+                       message.attachments[].type (string): the MIME type of the attachment - allowed types are text/*, image/*, and application/pdf
+                       message.attachments[].name (string): the file name of the attachment
+                       message.attachments[].content (string): the content of the attachment as a base64-encoded string
+
+
+
+        Returns:
+           array.  of structs for each recipient containing the key "email" with the email address and "status" as either "sent", "queued", or "rejected"::
+               [] (struct): the sending results for a single recipient::
+                   [].email (string): the email address of the recipient
+                   [].status (string): the sending status of the recipient - either "sent", "queued", or "rejected"
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'message': message}
+        return self.master.call('messages/send', _params)
+
+    def send_template(self, template_name, template_content, message):
+        """Send a new transactional message through Mandrill using a template
+
+        Args:
+           template_name (string): the name of a template that exists in the user's account
+           template_content (array): an array of template content to send.  Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block::
+               template_content[] (struct): the injection of a single piece of content into a single editable region::
+                   template_content[].name (string): the name of the mc:edit editable region to inject into
+                   template_content[].content (string): the content to inject
+
+           message (struct): the other information on the message to send - same as /messages/send, but without the html content::
+               message.text (string): optional full text content to be sent
+               message.subject (string): the message subject
+               message.from_email (string): the sender email address.
+               message.from_name (string): optional from name to be used
+               message.to (array): an array of recipient information.::
+                   message.to[] (struct): a single recipient's information.::
+                       message.to[].email (string): the email address of the recipient
+                       message.to[].name (string): the optional display name to use for the recipient
+
+
+               message.headers (struct): optional extra headers to add to the message (currently only Reply-To and X-* headers are allowed)
+               message.track_opens (boolean): whether or not to turn on open tracking for the message
+               message.track_clicks (boolean): whether or not to turn on click tracking for the message
+               message.auto_text (boolean): whether or not to automatically generate a text part for messages that are not given text
+               message.url_strip_qs (boolean): whether or not to strip the query string from URLs when aggregating tracked URL data
+               message.bcc_address (string): an optional address to receive an exact copy of each recipient's email
+               message.global_merge_vars (array): global merge variables to use for all recipients. You can override these per recipient.::
+                   message.global_merge_vars[] (struct): a single global merge variable::
+                       message.global_merge_vars[].name (string): the global merge variable's name. Merge variable names are case-insensitive and may not start with _
+                       message.global_merge_vars[].content (string): the global merge variable's content
+
+
+               message.merge_vars (array): per-recipient merge variables, which override global merge variables with the same name.::
+                   message.merge_vars[] (struct): per-recipient merge variables::
+                       message.merge_vars[].rcpt (string): the email address of the recipient that the merge variables should apply to
+                       message.merge_vars[].vars (array): the recipient's merge variables::
+                           message.merge_vars[].vars[] (struct): a single merge variable::
+                               message.merge_vars[].vars[].name (string): the merge variable's name. Merge variable names are case-insensitive and may not start with _
+                               message.merge_vars[].vars[].content (string): the merge variable's content
+
+
+
+
+               message.tags (array): an array of string to tag the message with.  Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently.  Tags should be 50 characters or less.  Any tags starting with an underscore are reserved for internal use and will cause errors.::
+                   message.tags[] (string): a single tag - must not start with an underscore
+
+               message.google_analytics_domains (array): an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
+               message.google_analytics_campaign (array|string): optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
+               message.metadata (array): metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
+               message.attachments (array): an array of supported attachments to add to the message::
+                   message.attachments[] (struct): a single supported attachment::
+                       message.attachments[].type (string): the MIME type of the attachment - allowed types are text/*, image/*, and application/pdf
+                       message.attachments[].name (string): the file name of the attachment
+                       message.attachments[].content (string): the content of the attachment as a base64-encoded string
+
+
+
+        Returns:
+           array.  of structs for each recipient containing the key "email" with the email address and "status" as either "sent", "queued", or "rejected"::
+               [] (struct): the sending results for a single recipient::
+                   [].email (string): the email address of the recipient
+                   [].status (string): the sending status of the recipient - either "sent", "queued", or "rejected"
+
+
+        Raises:
+           UnknownTemplateError: The requested template does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'template_name': template_name, 'template_content': template_content, 'message': message}
+        return self.master.call('messages/send-template', _params)
+
+    def search(self, query='*', date_from=None, date_to=None, tags=None, senders=None, limit=100):
+        """Search the content of recently sent messages and optionally narrow by date range, tags and senders
+
+        Args:
+           query (string): the search terms to find matching messages for
+           date_from (string): start date
+           date_to (string): end date
+           tags (array): an array of tag names to narrow the search to, will return messages that contain ANY of the tags
+           senders (array): an array of sender addresses to narrow the search to, will return messages sent by ANY of the senders
+           limit (integer): the maximum number of results to return, defaults to 100, 1000 is the maximum
+
+        Returns:
+           array.  of structs for each matching message::
+               [] (struct): the information for a single matching message::
+                   [].ts (integer): the Unix timestamp from when this message was sent
+                   [].sender (string): the email address of the sender
+                   [].subject (string): the message's subject link
+                   [].email (string): the recipient email address
+                   [].tags (array): list of tags on this message::
+                       [].tags[] (string): individual tag on this message
+
+                   [].opens (integer): how many times has this message been opened
+                   [].clicks (integer): how many times has a link been clicked in this message
+                   [].state (string): sending status of this message: sent, bounced, rejected
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'query': query, 'date_from': date_from, 'date_to': date_to, 'tags': tags, 'senders': senders, 'limit': limit}
+        return self.master.call('messages/search', _params)
+
+    def parse(self, raw_message):
+        """Parse the full MIME document for an email message, returning the content of the message broken into its constituent pieces
+
+        Args:
+           raw_message (string): the full MIME document of an email message
+
+        Returns:
+           struct.  the parsed message::
+               subject (string): the subject of the message
+               from_email (string): the email address of the sender
+               from_name (string): the alias of the sender (if any)
+               to (array): an array of any recipients in the message::
+                   to[] (struct): the information on a single recipient::
+                       to[].email (string): the email address of the recipient
+                       to[].name (string): the alias of the recipient (if any)
+
+
+               headers (struct): the key-value pairs of the MIME headers for the message's main document
+               text (string): the text part of the message, if any
+               html (string): the HTML part of the message, if any
+               attachments (array): an array of any attachments that can be found in the message::
+                   attachments[] (struct): information about an individual attachment::
+                       attachments[].name (string): the file name of the attachment
+                       attachments[].type (string): the MIME type of the attachment
+                       attachments[].binary (boolean): if this is set to true, the attachment is not pure-text, and the content will be base64 encoded
+                       attachments[].content (string): the content of the attachment as a text string or a base64 encoded string based on the attachment type
+
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'raw_message': raw_message}
+        return self.master.call('messages/parse', _params)
+
+    def send_raw(self, raw_message):
+        """Take a raw MIME document for a message, and send it exactly as if it were sent over the SMTP protocol
+
+        Args:
+           raw_message (string): the full MIME document of an email message
+
+        Returns:
+           array.  of structs for each recipient containing the key "email" with the email address and "status" as either "sent", "queued", or "rejected"::
+               [] (struct): the sending results for a single recipient::
+                   [].email (string): the email address of the recipient
+                   [].status (string): the sending status of the recipient - either "sent", "queued", or "rejected"
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'raw_message': raw_message}
+        return self.master.call('messages/send-raw', _params)
+
+
+class Urls(object):
+    def __init__(self, master):
+        self.master = master
+
+    def list(self, ):
+        """Get the 100 most clicked URLs
+
+        Returns:
+           array.  the 100 most clicked URLs and their stats::
+               [] (struct): the individual URL stats::
+                   [].url (string): the URL to be tracked
+                   [].sent (integer): the number of emails that contained the URL
+                   [].clicks (integer): the number of times the URL has been clicked from a tracked email
+                   [].unique_clicks (integer): the number of unique emails that have benerated clicks for this URL
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('urls/list', _params)
+
+    def search(self, q):
+        """Return the 100 most clicked URLs that match the search query given
+
+        Args:
+           q (string): a search query
+
+        Returns:
+           array.  the 100 most clicked URLs matching the search query::
+               [] (struct): the URL matching the query::
+                   [].url (string): the URL to be tracked
+                   [].sent (integer): the number of emails that contained the URL
+                   [].clicks (integer): the number of times the URL has been clicked from a tracked email
+                   [].unique_clicks (integer): the number of unique emails that have benerated clicks for this URL
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'q': q}
+        return self.master.call('urls/search', _params)
+
+    def time_series(self, url):
+        """Return the recent history (hourly stats for the last 30 days) for a url
+
+        Args:
+           url (string): an existing URL
+
+        Returns:
+           array.  the array of history information::
+               [] (struct): the information for a single hour::
+                   [].time (string): the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the number of emails that were sent with the URL during the hour
+                   [].clicks (integer): the number of times the URL was clicked during the hour
+                   [].unique_clicks (integer): the number of unique clicks generated for emails sent with this URL during the hour
+
+
+        Raises:
+           UnknownUrlError: The requested URL has not been seen in a tracked link
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'url': url}
+        return self.master.call('urls/time-series', _params)
+
+
+class Webhooks(object):
+    def __init__(self, master):
+        self.master = master
+
+    def list(self, ):
+        """Get the list of all webhooks defined on the account
+
+        Returns:
+           array.  the webhooks associated with the account::
+               [] (struct): the inidividual webhook info::
+                   [].id (integer): a unique integer indentifier for the webhook
+                   [].url (string): The URL that the event data will be posted to
+                   [].events (array): The message events that will be posted to the hook::
+                       [].events[] (string): the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
+
+                   [].created_at (string): the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+                   [].last_sent_at (string): the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
+                   [].batches_sent (integer): the number of event batches that have ever been sent to this webhook
+                   [].events_sent (integer): the total number of events that have ever been sent to this webhook
+                   [].last_error (string): if we've ever gotten an error trying to post to this webhook, the last error that we've seen
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('webhooks/list', _params)
+
+    def add(self, url, events=[]):
+        """Add a new webhook
+
+        Args:
+           url (string): the URL to POST batches of events
+           events (array): an optional list of events that will be posted to the webhook::
+               events[] (string): the individual event to listen for
+
+        Returns:
+           struct.  the information saved about the new webhook::
+               id (integer): a unique integer indentifier for the webhook
+               url (string): The URL that the event data will be posted to
+               events (array): The message events that will be posted to the hook::
+                   events[] (string): the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
+
+               created_at (string): the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               last_sent_at (string): the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
+               batches_sent (integer): the number of event batches that have ever been sent to this webhook
+               events_sent (integer): the total number of events that have ever been sent to this webhook
+               last_error (string): if we've ever gotten an error trying to post to this webhook, the last error that we've seen
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'url': url, 'events': events}
+        return self.master.call('webhooks/add', _params)
+
+    def info(self, id):
+        """Given the ID of an existing webhook, return the data about it
+
+        Args:
+           id (integer): the unique identifier of a webhook belonging to this account
+
+        Returns:
+           struct.  the information about the webhook::
+               id (integer): a unique integer indentifier for the webhook
+               url (string): The URL that the event data will be posted to
+               events (array): The message events that will be posted to the hook::
+                   events[] (string): the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
+
+               created_at (string): the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               last_sent_at (string): the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
+               batches_sent (integer): the number of event batches that have ever been sent to this webhook
+               events_sent (integer): the total number of events that have ever been sent to this webhook
+               last_error (string): if we've ever gotten an error trying to post to this webhook, the last error that we've seen
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           UnknownWebhookError: The requested webhook does not exist
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'id': id}
+        return self.master.call('webhooks/info', _params)
+
+    def update(self, id, url, events=[]):
+        """Update an existing webhook
+
+        Args:
+           id (integer): the unique identifier of a webhook belonging to this account
+           url (string): the URL to POST batches of events
+           events (array): an optional list of events that will be posted to the webhook::
+               events[] (string): the individual event to listen for
+
+        Returns:
+           struct.  the information for the updated webhook::
+               id (integer): a unique integer indentifier for the webhook
+               url (string): The URL that the event data will be posted to
+               events (array): The message events that will be posted to the hook::
+                   events[] (string): the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
+
+               created_at (string): the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               last_sent_at (string): the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
+               batches_sent (integer): the number of event batches that have ever been sent to this webhook
+               events_sent (integer): the total number of events that have ever been sent to this webhook
+               last_error (string): if we've ever gotten an error trying to post to this webhook, the last error that we've seen
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           UnknownWebhookError: The requested webhook does not exist
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'id': id, 'url': url, 'events': events}
+        return self.master.call('webhooks/update', _params)
+
+    def delete(self, id):
+        """Delete an existing webhook
+
+        Args:
+           id (integer): the unique identifier of a webhook belonging to this account
+
+        Returns:
+           struct.  the information for the deleted webhook::
+               id (integer): a unique integer indentifier for the webhook
+               url (string): The URL that the event data will be posted to
+               events (array): The message events that will be posted to the hook::
+                   events[] (string): the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
+
+               created_at (string): the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
+               last_sent_at (string): the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
+               batches_sent (integer): the number of event batches that have ever been sent to this webhook
+               events_sent (integer): the total number of events that have ever been sent to this webhook
+               last_error (string): if we've ever gotten an error trying to post to this webhook, the last error that we've seen
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           UnknownWebhookError: The requested webhook does not exist
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'id': id}
+        return self.master.call('webhooks/delete', _params)
+
+
+class Senders(object):
+    def __init__(self, master):
+        self.master = master
+
+    def list(self, ):
+        """Return the senders that have tried to use this account.
+
+        Returns:
+           array.  an array of sender data, one for each sending addresses used by the account::
+               [] (struct): the information on each sending address in the account::
+                   [].address (string): the sender's email address
+                   [].created_at (string): the date and time that the sender was first seen by Mandrill as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the total number of messages sent by this sender
+                   [].hard_bounces (integer): the total number of hard bounces by messages by this sender
+                   [].soft_bounces (integer): the total number of soft bounces by messages by this sender
+                   [].rejects (integer): the total number of rejected messages by this sender
+                   [].complaints (integer): the total number of spam complaints received for messages by this sender
+                   [].unsubs (integer): the total number of unsubscribe requests received for messages by this sender
+                   [].opens (integer): the total number of times messages by this sender have been opened
+                   [].clicks (integer): the total number of times tracked URLs in messages by this sender have been clicked
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('senders/list', _params)
+
+    def domains(self, ):
+        """Returns the sender domains that have been added to this account.
+
+        Returns:
+           array.  an array of sender domain data, one for each sending domain used by the account::
+               [] (struct): the information on each sending domain for the account::
+                   [].domain (string): the sender domain name
+                   [].created_at (string): the date and time that the sending domain was first seen as a UTC string in YYYY-MM-DD HH:MM:SS format
+
+
+        Raises:
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {}
+        return self.master.call('senders/domains', _params)
+
+    def info(self, address):
+        """Return more detailed information about a single sender, including aggregates of recent stats
+
+        Args:
+           address (string): the email address of the sender
+
+        Returns:
+           struct.  the detailed information on the sender::
+               address (string): the sender's email address
+               created_at (string): the date and time that the sender was first seen by Mandrill as a UTC date string in YYYY-MM-DD HH:MM:SS format
+               sent (integer): the total number of messages sent by this sender
+               hard_bounces (integer): the total number of hard bounces by messages by this sender
+               soft_bounces (integer): the total number of soft bounces by messages by this sender
+               rejects (integer): the total number of rejected messages by this sender
+               complaints (integer): the total number of spam complaints received for messages by this sender
+               unsubs (integer): the total number of unsubscribe requests received for messages by this sender
+               opens (integer): the total number of times messages by this sender have been opened
+               clicks (integer): the total number of times tracked URLs in messages by this sender have been clicked
+               stats (struct): an aggregate summary of the sender's sending stats::
+                   stats.today (struct): stats for this sender so far today::
+                       stats.today.sent (integer): the number of emails sent for this sender so far today
+                       stats.today.hard_bounces (integer): the number of emails hard bounced for this sender so far today
+                       stats.today.soft_bounces (integer): the number of emails soft bounced for this sender so far today
+                       stats.today.rejects (integer): the number of emails rejected for sending this sender so far today
+                       stats.today.complaints (integer): the number of spam complaints for this sender so far today
+                       stats.today.unsubs (integer): the number of unsubscribes for this sender so far today
+                       stats.today.opens (integer): the number of times emails have been opened for this sender so far today
+                       stats.today.unique_opens (integer): the number of unique opens for emails sent for this sender so far today
+                       stats.today.clicks (integer): the number of URLs that have been clicked for this sender so far today
+                       stats.today.unique_clicks (integer): the number of unique clicks for emails sent for this sender so far today
+
+                   stats.last_7_days (struct): stats for this sender in the last 7 days::
+                       stats.last_7_days.sent (integer): the number of emails sent for this sender in the last 7 days
+                       stats.last_7_days.hard_bounces (integer): the number of emails hard bounced for this sender in the last 7 days
+                       stats.last_7_days.soft_bounces (integer): the number of emails soft bounced for this sender in the last 7 days
+                       stats.last_7_days.rejects (integer): the number of emails rejected for sending this sender in the last 7 days
+                       stats.last_7_days.complaints (integer): the number of spam complaints for this sender in the last 7 days
+                       stats.last_7_days.unsubs (integer): the number of unsubscribes for this sender in the last 7 days
+                       stats.last_7_days.opens (integer): the number of times emails have been opened for this sender in the last 7 days
+                       stats.last_7_days.unique_opens (integer): the number of unique opens for emails sent for this sender in the last 7 days
+                       stats.last_7_days.clicks (integer): the number of URLs that have been clicked for this sender in the last 7 days
+                       stats.last_7_days.unique_clicks (integer): the number of unique clicks for emails sent for this sender in the last 7 days
+
+                   stats.last_30_days (struct): stats for this sender in the last 30 days::
+                       stats.last_30_days.sent (integer): the number of emails sent for this sender in the last 30 days
+                       stats.last_30_days.hard_bounces (integer): the number of emails hard bounced for this sender in the last 30 days
+                       stats.last_30_days.soft_bounces (integer): the number of emails soft bounced for this sender in the last 30 days
+                       stats.last_30_days.rejects (integer): the number of emails rejected for sending this sender in the last 30 days
+                       stats.last_30_days.complaints (integer): the number of spam complaints for this sender in the last 30 days
+                       stats.last_30_days.unsubs (integer): the number of unsubscribes for this sender in the last 30 days
+                       stats.last_30_days.opens (integer): the number of times emails have been opened for this sender in the last 30 days
+                       stats.last_30_days.unique_opens (integer): the number of unique opens for emails sent for this sender in the last 30 days
+                       stats.last_30_days.clicks (integer): the number of URLs that have been clicked for this sender in the last 30 days
+                       stats.last_30_days.unique_clicks (integer): the number of unique clicks for emails sent for this sender in the last 30 days
+
+                   stats.last_60_days (struct): stats for this sender in the last 60 days::
+                       stats.last_60_days.sent (integer): the number of emails sent for this sender in the last 60 days
+                       stats.last_60_days.hard_bounces (integer): the number of emails hard bounced for this sender in the last 60 days
+                       stats.last_60_days.soft_bounces (integer): the number of emails soft bounced for this sender in the last 60 days
+                       stats.last_60_days.rejects (integer): the number of emails rejected for sending this sender in the last 60 days
+                       stats.last_60_days.complaints (integer): the number of spam complaints for this sender in the last 60 days
+                       stats.last_60_days.unsubs (integer): the number of unsubscribes for this sender in the last 60 days
+                       stats.last_60_days.opens (integer): the number of times emails have been opened for this sender in the last 60 days
+                       stats.last_60_days.unique_opens (integer): the number of unique opens for emails sent for this sender in the last 60 days
+                       stats.last_60_days.clicks (integer): the number of URLs that have been clicked for this sender in the last 60 days
+                       stats.last_60_days.unique_clicks (integer): the number of unique clicks for emails sent for this sender in the last 60 days
+
+                   stats.last_90_days (struct): stats for this sender in the last 90 days::
+                       stats.last_90_days.sent (integer): the number of emails sent for this sender in the last 90 days
+                       stats.last_90_days.hard_bounces (integer): the number of emails hard bounced for this sender in the last 90 days
+                       stats.last_90_days.soft_bounces (integer): the number of emails soft bounced for this sender in the last 90 days
+                       stats.last_90_days.rejects (integer): the number of emails rejected for sending this sender in the last 90 days
+                       stats.last_90_days.complaints (integer): the number of spam complaints for this sender in the last 90 days
+                       stats.last_90_days.unsubs (integer): the number of unsubscribes for this sender in the last 90 days
+                       stats.last_90_days.opens (integer): the number of times emails have been opened for this sender in the last 90 days
+                       stats.last_90_days.unique_opens (integer): the number of unique opens for emails sent for this sender in the last 90 days
+                       stats.last_90_days.clicks (integer): the number of URLs that have been clicked for this sender in the last 90 days
+                       stats.last_90_days.unique_clicks (integer): the number of unique clicks for emails sent for this sender in the last 90 days
+
+
+
+        Raises:
+           UnknownSenderError: The requested sender does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'address': address}
+        return self.master.call('senders/info', _params)
+
+    def time_series(self, address):
+        """Return the recent history (hourly stats for the last 30 days) for a sender
+
+        Args:
+           address (string): the email address of the sender
+
+        Returns:
+           array.  the array of history information::
+               [] (struct): the stats for a single hour::
+                   [].time (string): the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
+                   [].sent (integer): the number of emails that were sent during the hour
+                   [].hard_bounces (integer): the number of emails that hard bounced during the hour
+                   [].soft_bounces (integer): the number of emails that soft bounced during the hour
+                   [].rejects (integer): the number of emails that were rejected during the hour
+                   [].complaints (integer): the number of spam complaints received during the hour
+                   [].opens (integer): the number of emails opened during the hour
+                   [].unique_opens (integer): the number of unique opens generated by messages sent during the hour
+                   [].clicks (integer): the number of tracked URLs clicked during the hour
+                   [].unique_clicks (integer): the number of unique clicks generated by messages sent during the hour
+
+
+        Raises:
+           UnknownSenderError: The requested sender does not exist
+           InvalidKeyError: The provided API key is not a valid Mandrill API key
+           Error: A general Mandrill error has occurred
+        """
+        _params = {'address': address}
+        return self.master.call('senders/time-series', _params)
+
+
+
+#!/usr/bin/env python
+'''Mandrill
+
+Usage:
+    mandrill setup
+    mandrill [-v] ping [--count=<cnt>]
+    mandrill [-v] send [--from=<addr>] [--to=<addr>] [--subject=<subj>] [--text-only]
+    mandrill [-v] search [--json] <query>
+    mandrill --help
+
+Options:
+    -h --help           Show this screen.
+    -v                  Turn on verbose mode - all traffic to the API will be logged to STDERR
+    -V --version        Show version.
+    -c --count=<cnt>    The number of times to ping Mandrill.
+    -f --from=<addr>    The from address of the message to send.
+    -t --to=<addr>      The recipient address of the message to send.
+    -s --subject=<subj> The subject line of the message to send.
+    --text-only         The message will be sent as plain-text.  If this option is not provided, HTML is presumed.
+    -j --json           Print the result as a JSON string
+'''
+import mandrill, docopt, time, sys, os.path, socket, math, re, subprocess, tempfile
+try:
+    import json as json
+except:
+    import simplejson as json
+
+email_re = re.compile(r'^[^\"\s@<>(),]+@[a-z0-9][a-z0-9\.\-_]*\.[a-z]+$', re.I)
+
+def command_setup(args):
+    global m
+    apikey = raw_input('Your Mandrill API Key: ')
+    try:
+        m = mandrill.Mandrill(apikey)
+        m.users.ping()
+    except mandrill.Error, e:
+        print('Got an error trying to use that API key: %s' % e)
+        sys.exit(1)
+    
+    try:
+        f = open('/etc/mandrill.key', 'w')
+        f.write(apikey)
+        f.close()
+        print('Saved Mandrill API Key to /etc/mandrill.key')
+    except:
+        f = open(os.path.expanduser('~/.mandrill.key'), 'w')
+        f.write(apikey)
+        f.close()
+        print('Saved Mandrill API Key to %s' % os.path.expanduser('~/.mandrill.key'))
+
+
+def command_ping(args):
+    print('PING https://mandrillapp.com/api/1.0/users/ping2.json')
+    if args['--count'] is None:
+        args['--count'] = 4
+    else:
+        args['--count'] = int(args['--count'])
+    
+    times = []
+    error_count = 0
+    for i in range(args['--count']):
+        start = time.time()
+        try:
+            m.users.ping2()
+            (remote_addr, remote_port) = m.last_request['remote_addr']
+            reverse_addr = socket.gethostbyaddr(remote_addr)[0]
+            times.append(m.last_request['time'] * 1000)
+
+            print('%d bytes from %s (%s): req=%s port=%s time=%.2fms' % (len(m.last_request['response_body']), reverse_addr, remote_addr, i + 1, remote_port, m.last_request['time'] * 1000))
+        except mandrill.Error, e:
+            error_count += 1
+            (remote_addr, remote_port) = m.last_request['remote_addr']
+            reverse_addr = socket.gethostbyaddr(remote_addr)[0]
+            times.append(m.last_request['time'] * 1000)
+            
+            print('%d bytes from %s (%s): req=%s port=%s time=%.2fms ERROR: %s' % (len(m.last_request['response_body']), reverse_addr, remote_addr, i + 1, remote_port, m.last_request['time'] * 1000, e))
+
+        if i < args['--count'] - 1: time.sleep(1)
+    
+    sq_sum = sum([t * t for t in times])
+    mean = sum(times) / len(times)
+    stdev = math.sqrt((sq_sum / len(times)) - (mean * mean))
+    print('\n--- Mandrill ping statistics ---')
+    print('%d calls transmitted, %d received, %d%% error rate, time %dms' % (args['--count'], args['--count'] - error_count, float(error_count) / args['--count'] * 100, sum(times)))
+    print('rtt min/avg/max/mdev = %.3f/%.3f/%.3f/%.3f ms' % (min(times), mean, max(times), stdev))
+
+
+def command_send(args):
+    if args['--from'] is not None and not email_re.match(args['--from']):
+        args['--from'] = None
+
+    if args['--to'] is not None and not email_re.match(args['--to']):
+        args['--to'] = None
+
+    while args['--from'] is None:
+        from_email = raw_input('From: ').strip()
+        if email_re.match(from_email):
+            args['--from'] = from_email
+        else:
+            print('Invalid email address. Try again.')
+
+    while args['--to'] is None:
+        to_email = raw_input('To: ').strip()
+        if email_re.match(to_email):
+            args['--to'] = to_email
+        else:
+            print('Invalid email address. Try again.')
+
+    while args['--subject'] is None:
+        subject = raw_input('Subject: ').strip()
+        if subject != '':
+            args['--subject'] = subject
+        else:
+            print('Enter a subject line.')
+
+    if sys.stdin.isatty():
+        editor = os.environ.get('EDITOR', 'vim')
+        if args['--text-only']:
+            suffix = '.txt'
+        else:
+            suffix = '.html'
+
+        with tempfile.NamedTemporaryFile(suffix=suffix) as tmp:
+            if args['--text-only']:
+                tmp.write('REMOVE this and replace with your text content.')
+            else:
+                tmp.write('<p>REMOVE this and replace with your HTML content.</p>')
+            tmp.flush()
+
+            subprocess.check_call([editor, tmp.name])
+            tmp.seek(0)
+            content = tmp.read()
+            if 'REMOVE this and replace with your' in content:
+                print('Send canceled')
+                sys.exit(1)
+    else:
+        content = sys.stdin.read()
+
+    msg = {'from_email': args['--from'], 'to': [{'email': args['--to']}], 'subject': args['--subject']}
+    if args['--text-only']:
+        msg['text'] = content
+    else:
+        msg['html'] = content
+
+    m.messages.send(msg)
+
+
+def command_search(args):
+    query = args['<query>']
+    results = m.messages.search(query)
+    if args['--json']:
+        json.dump(results, sys.stdout)
+    else:
+        print('Time\tStatus\tSender\tEmail\tSubject\tOpens\tClicks')
+        for result in results:
+            print('%s\t%s\t%s\t%s\t%s\t%s\t%s' % (time.strftime('%d/%b/%Y %H:%M:%S %Z', time.localtime(result['ts'])), result['state'], result['sender'], result['email'], result['subject'], result['opens'], result['clicks']))
+
+
+if __name__  == '__main__':
+    arguments = docopt.docopt(__doc__, version='Mandrill 1.0')
+    if not arguments['setup']:
+        try:
+            m = mandrill.Mandrill(debug=arguments['-v'])
+        except mandrill.Error:
+            print('This looks like the first time you\'ve run Mandrill, so let\'s get you set up.')
+            command_setup(arguments)
+
+    commands = dict([(k[8:], getattr(sys.modules['__main__'], k)) for k in dir(sys.modules['__main__']) if k.startswith('command_')])
+    for command, func in commands.items():
+        if command in arguments and arguments[command]:
+            try:
+                func(arguments)
+                sys.exit(0)
+            except Exception, e:
+                print(e)
+                sys.exit(1)
+from setuptools import setup
+import os.path
+
+setup(
+    name = 'mandrill',
+    version = '1.0.0',
+    author = 'Mandrill Devs',
+    author_email = 'community@mandrill.com',
+    description = 'A CLI client and Python API library for the Mandrill email as a service platform.',
+    long_description = open(os.path.join(os.path.dirname(__file__), 'README')).read(),
+    license = 'MIT',
+    keywords = 'mandrill email api',
+    url = 'http://mandrillapp.com/api/docs/clients/python/',
+    scripts = ['scripts/mandrill'],
+    py_modules = ['mandrill'],
+    install_requires = ['requests >= 0.13.2', 'docopt == 0.4.0'],
+    classifiers = [
+        'Development Status :: 4 - Beta',
+        'Environment :: Console',
+        'Intended Audience :: Developers',
+        'Intended Audience :: System Administrators',
+        'License :: OSI Approved :: MIT License',
+        'Topic :: Communications :: Email'
+    ]
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.