├── .gitignore ├── LICENSE ├── README.md ├── lib ├── mandrill.ex └── mandrill │ ├── exports.ex │ ├── inbound.ex │ ├── ips.ex │ ├── messages.ex │ ├── rejects.ex │ ├── senders.ex │ ├── subaccounts.ex │ ├── supervisor.ex │ ├── tags.ex │ ├── templates.ex │ ├── urls.ex │ ├── users.ex │ ├── webhooks.ex │ └── whitelists.ex ├── mix.exs ├── mix.lock └── test ├── mandrill_test.exs └── test_helper.exs /.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | erl_crash.dump 4 | *.ez 5 | docs/ 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Shane Logsdon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mandrill [![Hex.pm](https://img.shields.io/hexpm/v/mandrill.svg)](https://hex.pm/packages/mandrill) [![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://hexdocs.pm/mandrill/0.4.1/) 2 | 3 | A Mandrill wrapper for Elixir. 4 | 5 | ## Installation 6 | 7 | Add ``mandrill`` to your dependencies in your ``mix.exs``. 8 | 9 | ```Elixir 10 | defp deps do 11 | [... 12 | {:mandrill, "~> 0.4"}] 13 | end 14 | ``` 15 | 16 | ## Usage 17 | 18 | > ##### Note 19 | > You must provide a valid api key, either through the mix config value 20 | > `:mandrill, :key`, or the `MANDRILL_KEY` environment variable. 21 | 22 | ```elixir 23 | iex> Mandrill.start 24 | :ok 25 | 26 | iex> Mandrill.key 27 | "your_key" 28 | 29 | iex> Mandrill.Users.info 30 | [username: "your_username", created_at: "2013-12-05 00:24:19.47554", 31 | public_id: "your_public_id", reputation: 0, hourly_quota: 25, 32 | backlog: 0, 33 | stats: [today: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 34 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 35 | unique_clicks: 0], 36 | last_7_days: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 37 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 38 | unique_clicks: 0], 39 | last_30_days: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 40 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 41 | unique_clicks: 0], 42 | last_60_days: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 43 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 44 | unique_clicks: 0], 45 | last_90_days: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 46 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 47 | unique_clicks: 0], 48 | all_time: [sent: 0, hard_bounces: 0, soft_bounces: 0, rejects: 0, 49 | complaints: 0, unsubs: 0, opens: 0, unique_opens: 0, clicks: 0, 50 | unique_clicks: 0]]] 51 | 52 | iex> Mandrill.Users.info[:username] 53 | "your_username" 54 | ``` 55 | 56 | ## Reference 57 | 58 | See [Mandrill's API docs](https://mandrillapp.com/api/docs/). 59 | 60 | ## Dependencies 61 | 62 | - [HTTPoison](https://github.com/edgurgel/httpoison) 63 | - [JSEX](https://github.com/talentdeficit/jsex) 64 | 65 | ## License 66 | 67 | See [LICENSE](https://github.com/slogsdon/mandrill/blob/master/LICENSE) 68 | 69 | [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/949f7db1a2574d19a36cf9a21a760a6a "githalytics.com")](http://githalytics.com/slogsdon/mandrill) 70 | -------------------------------------------------------------------------------- /lib/mandrill.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill do 2 | @moduledoc """ 3 | An HTTP client for Mandrill. 4 | """ 5 | 6 | # Let's build on top of HTTPoison 7 | use Application 8 | use HTTPoison.Base 9 | 10 | def start(_type, _args) do 11 | Mandrill.Supervisor.start_link 12 | end 13 | 14 | @doc """ 15 | Creates the URL for our endpoint. 16 | Args: 17 | * endpoint - part of the API we're hitting 18 | Returns string 19 | """ 20 | def process_url(endpoint) do 21 | "https://mandrillapp.com/api/1.0/" <> endpoint <> ".json" 22 | end 23 | 24 | @doc """ 25 | Converts the binary keys in our response to strings. 26 | Args: 27 | * body - string binary response 28 | Returns Record or ArgumentError 29 | """ 30 | def process_response_body(body) do 31 | JSX.decode!(body) 32 | end 33 | 34 | @doc """ 35 | Boilerplate code to make requests. 36 | Args: 37 | * endpoint - string requested API endpoint 38 | * body - request body 39 | Returns dict 40 | """ 41 | def request(endpoint, body) do 42 | Mandrill.post!(endpoint, JSX.encode! body).body 43 | end 44 | 45 | @doc """ 46 | Gets the api key from :mandrill, :key application env or 47 | MANDRILL_KEY from system ENV 48 | Returns binary 49 | """ 50 | def key do 51 | Application.get_env(:mandrill, :key) || 52 | System.get_env("MANDRILL_KEY") 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /lib/mandrill/exports.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Exports do 2 | @moduledoc """ 3 | Exports calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Returns information about an export job. 8 | If the export job's state is 'complete', 9 | the returned data will include a URL you 10 | can use to fetch the results. Every export 11 | job produces a zip archive, but the format 12 | of the archive is distinct for each job 13 | type. The api calls that initiate exports 14 | include more details about the output 15 | format for that job type. 16 | """ 17 | def info(params) when is_list(params) do 18 | Mandrill.request("exports/info", Enum.concat([key: Mandrill.key], params)) 19 | end 20 | def info(id) do 21 | params = [ 22 | key: Mandrill.key, 23 | id: id 24 | ] 25 | Mandrill.request("exports/info", params) 26 | end 27 | 28 | @doc """ 29 | Returns a list of your exports. 30 | """ 31 | def list do 32 | params = [ key: Mandrill.key ] 33 | Mandrill.request("exports/list", params) 34 | end 35 | 36 | @doc """ 37 | Begins an export of your rejection 38 | blacklist. The blacklist will be exported 39 | to a zip archive containing a single file 40 | named rejects.csv that includes the 41 | following fields: email, reason, detail, 42 | created_at, expires_at, last_event_at, 43 | expires_at. 44 | """ 45 | def rejects(params) when is_list(params) do 46 | Mandrill.request("exports/rejects", Enum.concat([key: Mandrill.key], params)) 47 | end 48 | def rejects(notify_email) do 49 | params = [ 50 | key: Mandrill.key, 51 | notify_email: notify_email 52 | ] 53 | Mandrill.request("exports/rejects", params) 54 | end 55 | 56 | @doc """ 57 | Begins an export of your rejection 58 | whitelist. The whitelist will be exported 59 | to a zip archive containing a single file 60 | named whitelist.csv that includes the 61 | following fields: email, detail, 62 | created_at. 63 | """ 64 | def whitelist(params) when is_list(params) do 65 | Mandrill.request("exports/whitelist", Enum.concat([key: Mandrill.key], params)) 66 | end 67 | def whitelist(notify_email) do 68 | params = [ 69 | key: Mandrill.key, 70 | notify_email: notify_email 71 | ] 72 | Mandrill.request("exports/whitelist", params) 73 | end 74 | 75 | @doc """ 76 | Begins an export of your activity history. 77 | The activity will be exported to a zip 78 | archive containing a single file named 79 | activity.csv in the same format as you 80 | would be able to export from your account's 81 | activity view. It includes the following 82 | fields: Date, Email Address, Sender, 83 | Subject, Status, Tags, Opens, Clicks, 84 | Bounce Detail. If you have configured any 85 | custom metadata fields, they will be 86 | included in the exported data. 87 | """ 88 | def activity(params) when is_list(params) do 89 | Mandrill.request("exports/activity", Enum.concat([key: Mandrill.key], params)) 90 | end 91 | def activity(notify_email, date_from, date_to, tags, senders, states, api_keys) do 92 | params = [ 93 | key: Mandrill.key, 94 | notify_email: notify_email, 95 | date_from: date_from, 96 | date_to: date_to, 97 | tags: tags, 98 | senders: senders, 99 | states: states, 100 | api_keys: api_keys 101 | ] 102 | Mandrill.request("exports/activity", params) 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /lib/mandrill/inbound.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Inbound do 2 | @moduledoc """ 3 | Inbound calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | List the domains that have been configured 8 | for inbound delivery 9 | """ 10 | def domains do 11 | params = [ key: Mandrill.key ] 12 | Mandrill.request("inbound/domains", params) 13 | end 14 | 15 | @doc """ 16 | Add an inbound domain to your account 17 | """ 18 | def add_domain(params) when is_list(params) do 19 | Mandrill.request("inbound/add_domain", Enum.concat([key: Mandrill.key], params)) 20 | end 21 | def add_domain(domain) do 22 | params = [ 23 | key: Mandrill.key, 24 | domain: domain 25 | ] 26 | Mandrill.request("inbound/add-domain", params) 27 | end 28 | 29 | @doc """ 30 | Check the MX settings for an inbound domain. 31 | The domain must have already been added 32 | with the add-domain call 33 | """ 34 | def check_domain(params) when is_list(params) do 35 | Mandrill.request("inbound/check-domain", Enum.concat([key: Mandrill.key], params)) 36 | end 37 | def check_domain(domain) do 38 | params = [ 39 | key: Mandrill.key, 40 | domain: domain 41 | ] 42 | Mandrill.request("inbound/check-domain", params) 43 | end 44 | 45 | @doc """ 46 | Delete an inbound domain from the account. 47 | All mail will stop routing for this domain 48 | immediately. 49 | """ 50 | def delete_domain(params) when is_list(params) do 51 | Mandrill.request("inbound/delete-domain", Enum.concat([key: Mandrill.key], params)) 52 | end 53 | def delete_domain(domain) do 54 | params = [ 55 | key: Mandrill.key, 56 | domain: domain 57 | ] 58 | Mandrill.request("inbound/delete-domain", params) 59 | end 60 | 61 | @doc """ 62 | List the mailbox routes defined for an 63 | inbound domain 64 | """ 65 | def routes(params) when is_list(params) do 66 | Mandrill.request("inbound/routes", Enum.concat([key: Mandrill.key], params)) 67 | end 68 | def routes(domain) do 69 | params = [ 70 | key: Mandrill.key, 71 | domain: domain 72 | ] 73 | Mandrill.request("inbound/routes", params) 74 | end 75 | 76 | @doc """ 77 | Add a new mailbox route to an inbound domain 78 | """ 79 | def add_route(params) when is_list(params) do 80 | Mandrill.request("inbound/add-route", Enum.concat([key: Mandrill.key], params)) 81 | end 82 | def add_route(domain, pattern, url) do 83 | params = [ 84 | key: Mandrill.key, 85 | domain: domain, 86 | pattern: pattern, 87 | url: url 88 | ] 89 | Mandrill.request("inbound/add-route", params) 90 | end 91 | 92 | @doc """ 93 | Update the pattern or webhook of an existing 94 | inbound mailbox route. If null is provided 95 | for any fields, the values will remain 96 | unchanged. 97 | """ 98 | def update_route(params) when is_list(params) do 99 | Mandrill.request("inbound/update-route", Enum.concat([key: Mandrill.key], params)) 100 | end 101 | def update_route(id, pattern, url) do 102 | params = [ 103 | key: Mandrill.key, 104 | id: id, 105 | pattern: pattern, 106 | url: url 107 | ] 108 | Mandrill.request("inbound/update-route", params) 109 | end 110 | 111 | @doc """ 112 | Delete an existing inbound mailbox route 113 | """ 114 | def delete_route(params) when is_list(params) do 115 | Mandrill.request("inbound/delete-route", Enum.concat([key: Mandrill.key], params)) 116 | end 117 | def delete_route(id) do 118 | params = [ 119 | key: Mandrill.key, 120 | id: id 121 | ] 122 | Mandrill.request("inbound/delete-route", params) 123 | end 124 | 125 | @doc """ 126 | Take a raw MIME document destined for a 127 | domain with inbound domains set up, and send 128 | it to the inbound hook exactly as if it had 129 | been sent over SMTP 130 | """ 131 | def send_raw(params) when is_list(params) do 132 | Mandrill.request("inbound/send-raw", Enum.concat([key: Mandrill.key], params)) 133 | end 134 | def send_raw(raw_message, to \\ nil, mail_from, helo, client_address) do 135 | params = [ 136 | key: Mandrill.key, 137 | raw_message: raw_message, 138 | to: to, 139 | mail_from: mail_from, 140 | helo: helo, 141 | client_address: client_address 142 | ] 143 | Mandrill.request("inbound/send-raw", params) 144 | end 145 | end 146 | -------------------------------------------------------------------------------- /lib/mandrill/ips.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Ips do 2 | @moduledoc """ 3 | Ips calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Lists your dedicated IPs. 8 | """ 9 | def list do 10 | params = [ key: Mandrill.key ] 11 | Mandrill.request("ips/list", params) 12 | end 13 | 14 | @doc """ 15 | Retrieves information about a single 16 | dedicated ip. 17 | """ 18 | def info(params) when is_list(params) do 19 | Mandrill.request("ips/info", Enum.concat([key: Mandrill.key], params)) 20 | end 21 | def info(ip) do 22 | params = [ 23 | key: Mandrill.key, 24 | ip: ip 25 | ] 26 | Mandrill.request("ips/info", params) 27 | end 28 | 29 | @doc """ 30 | Requests an additional dedicated IP for your 31 | account. Accounts may have one outstanding 32 | request at any time, and provisioning 33 | requests are processed within 24 hours. 34 | """ 35 | def provision(params) when is_list(params) do 36 | Mandrill.request("ips/provision", Enum.concat([key: Mandrill.key], params)) 37 | end 38 | def provision(warmup, pool) do 39 | params = [ 40 | key: Mandrill.key, 41 | warmup: warmup, 42 | pool: pool 43 | ] 44 | Mandrill.request("ips/provision", params) 45 | end 46 | 47 | @doc """ 48 | Begins the warmup process for a dedicated IP. 49 | During the warmup process, Mandrill will 50 | gradually increase the percentage of your 51 | mail that is sent over the warming-up IP, 52 | over a period of roughly 30 days. The rest of 53 | your mail will be sent over shared IPs or 54 | other dedicated IPs in the same pool. 55 | """ 56 | def start_warmup(params) when is_list(params) do 57 | Mandrill.request("ips/start-warmup", Enum.concat([key: Mandrill.key], params)) 58 | end 59 | def start_warmup(ip) do 60 | params = [ 61 | key: Mandrill.key, 62 | ip: ip 63 | ] 64 | Mandrill.request("ips/start-warmup", params) 65 | end 66 | 67 | @doc """ 68 | Cancels the warmup process for a dedicated IP. 69 | """ 70 | def cancel_warmup(params) when is_list(params) do 71 | Mandrill.request("ips/cancel-warmup", Enum.concat([key: Mandrill.key], params)) 72 | end 73 | def cancel_warmup(ip) do 74 | params = [ 75 | key: Mandrill.key, 76 | ip: ip 77 | ] 78 | Mandrill.request("ips/cancel-warmup", params) 79 | end 80 | 81 | @doc """ 82 | Moves a dedicated IP to a different pool. 83 | """ 84 | def set_pool(params) when is_list(params) do 85 | Mandrill.request("ips/set-pool", Enum.concat([key: Mandrill.key], params)) 86 | end 87 | def set_pool(ip, pool, create_pool) do 88 | params = [ 89 | key: Mandrill.key, 90 | ip: ip, 91 | pool: pool, 92 | create_pool: create_pool 93 | ] 94 | Mandrill.request("ips/set-pool", params) 95 | end 96 | 97 | @doc """ 98 | Deletes a dedicated IP. This is permanent and 99 | cannot be undone. 100 | """ 101 | def delete(params) when is_list(params) do 102 | Mandrill.request("ips/delete", Enum.concat([key: Mandrill.key], params)) 103 | end 104 | def delete(ip) do 105 | params = [ 106 | key: Mandrill.key, 107 | ip: ip 108 | ] 109 | Mandrill.request("ips/delete", params) 110 | end 111 | 112 | @doc """ 113 | Lists your dedicated IP pools. 114 | """ 115 | def list_pools do 116 | params = [ key: Mandrill.key ] 117 | Mandrill.request("ips/list-pools", params) 118 | end 119 | 120 | @doc """ 121 | Describes a single dedicated IP pool. 122 | """ 123 | def pool_info(params) when is_list(params) do 124 | Mandrill.request("ips/pool-info", Enum.concat([key: Mandrill.key], params)) 125 | end 126 | def pool_info(pool) do 127 | params = [ 128 | key: Mandrill.key, 129 | pool: pool 130 | ] 131 | Mandrill.request("ips/pool-info", params) 132 | end 133 | 134 | @doc """ 135 | Creates a pool and returns it. If a pool 136 | already exists with this name, no action will 137 | be performed. 138 | """ 139 | def create_pool(params) when is_list(params) do 140 | Mandrill.request("ips/create-pool", Enum.concat([key: Mandrill.key], params)) 141 | end 142 | def create_pool(pool) do 143 | params = [ 144 | key: Mandrill.key, 145 | pool: pool 146 | ] 147 | Mandrill.request("ips/create-pool", params) 148 | end 149 | 150 | @doc """ 151 | Deletes a pool. A pool must be empty before 152 | you can delete it, and you cannot delete your 153 | default pool. 154 | """ 155 | def delete_pool(params) when is_list(params) do 156 | Mandrill.request("ips/delete-pool", Enum.concat([key: Mandrill.key], params)) 157 | end 158 | def delete_pool(pool) do 159 | params = [ 160 | key: Mandrill.key, 161 | pool: pool 162 | ] 163 | Mandrill.request("ips/delete-pool", params) 164 | end 165 | 166 | @doc """ 167 | Tests whether a domain name is valip for use as 168 | the custom reverse DNS for a dedicated IP. 169 | """ 170 | def check_custom_dns(params) when is_list(params) do 171 | Mandrill.request("ips/check-custom-dns", Enum.concat([key: Mandrill.key], params)) 172 | end 173 | def check_custom_dns(ip, domain) do 174 | params = [ 175 | key: Mandrill.key, 176 | ip: ip , 177 | domain: domain 178 | ] 179 | Mandrill.request("ips/check-custom-dns", params) 180 | end 181 | 182 | @doc """ 183 | Configures the custom DNS name for a dedicated 184 | IP. 185 | """ 186 | def set_custom_dns(params) when is_list(params) do 187 | Mandrill.request("ips/set-custom-dns", Enum.concat([key: Mandrill.key], params)) 188 | end 189 | def set_custom_dns(ip, domain) do 190 | params = [ 191 | key: Mandrill.key, 192 | ip: ip, 193 | domain: domain 194 | ] 195 | Mandrill.request("ips/set-custom-dns", params) 196 | end 197 | end -------------------------------------------------------------------------------- /lib/mandrill/messages.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Messages do 2 | @moduledoc """ 3 | Messages calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Send a new transactional message through 8 | Mandrill 9 | """ 10 | def send(params) when is_list(params) do 11 | Mandrill.request("messages/send", Enum.concat([key: Mandrill.key], params)) 12 | end 13 | def send(message, async, ip_pool, send_at) do 14 | params = [ 15 | key: Mandrill.key, 16 | message: message, 17 | async: async, 18 | ip_pool: ip_pool, 19 | send_at: send_at 20 | ] 21 | Mandrill.request("messages/send", params) 22 | end 23 | 24 | @doc """ 25 | Send a new transactional message through 26 | Mandrill using a template 27 | """ 28 | def send_template(params) when is_list(params) do 29 | Mandrill.request("messages/send-template", Enum.concat([key: Mandrill.key], params)) 30 | end 31 | def send_template(template_name, template_content, message, async, ip_pool, send_at) do 32 | params = [ 33 | key: Mandrill.key, 34 | template_name: template_name, 35 | template_content: template_content, 36 | message: message, 37 | async: async, 38 | ip_pool: ip_pool, 39 | send_at: send_at 40 | ] 41 | Mandrill.request("messages/send-template", params) 42 | end 43 | 44 | @doc """ 45 | Search the content of recently sent messages 46 | and optionally narrow by date range, tags 47 | and senders 48 | """ 49 | def search(params) when is_list(params) do 50 | Mandrill.request("messages/search", Enum.concat([key: Mandrill.key], params)) 51 | end 52 | def search(query, date_from, date_to, tags, senders, api_keys, limit) do 53 | params = [ 54 | key: Mandrill.key, 55 | query: query, 56 | date_from: date_from, 57 | date_to: date_to, 58 | tags: tags, 59 | senders: senders, 60 | api_keys: api_keys, 61 | limit: limit 62 | ] 63 | Mandrill.request("messages/search", params) 64 | end 65 | 66 | @doc """ 67 | Search the content of recently sent messages 68 | and return the aggregated hourly stats for 69 | matching messages 70 | """ 71 | def search_time_series(params) when is_list(params) do 72 | Mandrill.request("messages/search-time-series", Enum.concat([key: Mandrill.key], params)) 73 | end 74 | def search_time_series(query, date_from, date_to, tags, senders) do 75 | params = [ 76 | key: Mandrill.key, 77 | query: query, 78 | date_from: date_from, 79 | date_to: date_to, 80 | tags: tags, 81 | senders: senders 82 | ] 83 | Mandrill.request("messages/search-time-series", params) 84 | end 85 | 86 | @doc """ 87 | Get the information for a single recently 88 | sent message 89 | """ 90 | def info(params) when is_list(params) do 91 | Mandrill.request("messages/info", Enum.concat([key: Mandrill.key], params)) 92 | end 93 | def info(id) do 94 | params = [ 95 | key: Mandrill.key, 96 | id: id 97 | ] 98 | Mandrill.request("messages/info", params) 99 | end 100 | 101 | @doc """ 102 | Get the full content of a recently sent 103 | message 104 | """ 105 | def content(params) when is_list(params) do 106 | Mandrill.request("messages/content", Enum.concat([key: Mandrill.key], params)) 107 | end 108 | def content(id) do 109 | params = [ 110 | key: Mandrill.key, 111 | id: id 112 | ] 113 | Mandrill.request("messages/content", params) 114 | end 115 | 116 | @doc """ 117 | Parse the full MIME document for an email 118 | message, returning the content of the 119 | message broken into its constituent pieces 120 | """ 121 | def parse(params) when is_list(params) do 122 | Mandrill.request("messages/parse", Enum.concat([key: Mandrill.key], params)) 123 | end 124 | def parse(raw_message) do 125 | params = [ 126 | key: Mandrill.key, 127 | raw_message: raw_message 128 | ] 129 | Mandrill.request("messages/parse", params) 130 | end 131 | 132 | @doc """ 133 | Take a raw MIME document for a message, and 134 | send it exactly as if it were sent through 135 | Mandrill's SMTP servers 136 | """ 137 | def send_raw(params) when is_list(params) do 138 | Mandrill.request("messages/send-raw", Enum.concat([key: Mandrill.key], params)) 139 | end 140 | def send_raw(raw_message, from_email \\ nil, from_name \\ nil, to \\ nil, async, ip_pool, send_at, return_path_domain) do 141 | params = [ 142 | key: Mandrill.key, 143 | raw_message: raw_message, 144 | from_email: from_email, 145 | from_name: from_name, 146 | to: to, 147 | async: async, 148 | ip_pool: ip_pool, 149 | send_at: send_at, 150 | return_path_domain: return_path_domain 151 | ] 152 | Mandrill.request("messages/send-raw", params) 153 | end 154 | 155 | @doc """ 156 | Queries your scheduled emails by sender or 157 | recipient, or both. 158 | """ 159 | def list_scheduled(params) when is_list(params) do 160 | Mandrill.request("messages/list-scheduled", Enum.concat([key: Mandrill.key], params)) 161 | end 162 | def list_scheduled(to) do 163 | params = [ 164 | key: Mandrill.key, 165 | to: to 166 | ] 167 | Mandrill.request("messages/list-scheduled", params) 168 | end 169 | 170 | @doc """ 171 | Cancels a scheduled email. 172 | """ 173 | def cancel_scheduled(params) when is_list(params) do 174 | Mandrill.request("messages/cancel-scheduled", Enum.concat([key: Mandrill.key], params)) 175 | end 176 | def cancel_scheduled(id) do 177 | params = [ 178 | key: Mandrill.key, 179 | id: id 180 | ] 181 | Mandrill.request("messages/cancel-scheduled", params) 182 | end 183 | 184 | @doc """ 185 | Reschedules a scheduled email. 186 | """ 187 | def reschedule(params) when is_list(params) do 188 | Mandrill.request("messages/reschedule", Enum.concat([key: Mandrill.key], params)) 189 | end 190 | def reschedule(id, send_at) do 191 | params = [ 192 | key: Mandrill.key, 193 | id: id, 194 | send_At: send_at 195 | ] 196 | Mandrill.request("messages/reschedule", params) 197 | end 198 | end 199 | -------------------------------------------------------------------------------- /lib/mandrill/rejects.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Rejects do 2 | @moduledoc """ 3 | Rejects calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Adds an email to your email rejection 8 | blacklist. Addresses that you add manually 9 | will never expire and there is no 10 | reputation penalty for removing them from 11 | your blacklist. Attempting to blacklist an 12 | address that has been whitelisted will 13 | have no effect. 14 | """ 15 | def add(params) when is_list(params) do 16 | Mandrill.request("rejects/add", Enum.concat([key: Mandrill.key], params)) 17 | end 18 | def add(email, comment, subaccount) do 19 | params = [ 20 | key: Mandrill.key, 21 | email: email, 22 | comment: comment, 23 | subaccount: subaccount 24 | ] 25 | Mandrill.request("rejects/add", params) 26 | end 27 | 28 | @doc """ 29 | Retrieves your email rejection blacklist. 30 | You can provide an email address to limit 31 | the results. Returns up to 1000 results. 32 | By default, entries that have expired are 33 | excluded from the results; set 34 | include_expired to true to include them. 35 | """ 36 | def list(params) when is_list(params) do 37 | Mandrill.request("rejects/list", Enum.concat([key: Mandrill.key], params)) 38 | end 39 | def list(email, include_expired, subaccount) do 40 | params = [ 41 | key: Mandrill.key, 42 | email: email, 43 | include_expired: include_expired, 44 | subaccount: subaccount 45 | ] 46 | Mandrill.request("rejects/list", params) 47 | end 48 | 49 | @doc """ 50 | Deletes an email rejection. There is no 51 | limit to how many rejections you can 52 | remove from your blacklist, but keep in 53 | mind that each deletion has an affect on 54 | your reputation. 55 | """ 56 | def delete(params) when is_list(params) do 57 | Mandrill.request("rejects/delete", Enum.concat([key: Mandrill.key], params)) 58 | end 59 | def delete(email, subaccount) do 60 | params = [ 61 | key: Mandrill.key, 62 | email: email, 63 | subaccount: subaccount 64 | ] 65 | Mandrill.request("rejects/delete", params) 66 | end 67 | end -------------------------------------------------------------------------------- /lib/mandrill/senders.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Senders do 2 | @moduledoc """ 3 | Senders calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Return the senders that have tried to 8 | use this account. 9 | """ 10 | def list do 11 | params = [ key: Mandrill.key ] 12 | Mandrill.request("senders/list", params) 13 | end 14 | 15 | @doc """ 16 | Returns the sender domains that have 17 | been added to this account. 18 | """ 19 | def domains do 20 | params = [ key: Mandrill.key ] 21 | Mandrill.request("senders/domains", params) 22 | end 23 | 24 | @doc """ 25 | Adds a sender domain to your account. 26 | Sender domains are added automatically 27 | as you send, but you can use this call 28 | to add them ahead of time. 29 | """ 30 | def add_domain(params) when is_list(params) do 31 | Mandrill.request("senders/add-domain", Enum.concat([key: Mandrill.key], params)) 32 | end 33 | def add_domain(domain) do 34 | params = [ 35 | key: Mandrill.key, 36 | domain: domain 37 | ] 38 | Mandrill.request("senders/add-domain", params) 39 | end 40 | 41 | @doc """ 42 | Checks the SPF and DKIM settings for a 43 | domain. If you haven't already added 44 | this domain to your account, it will be 45 | added automatically. 46 | """ 47 | def check_domain(params) when is_list(params) do 48 | Mandrill.request("senders/check-domain", Enum.concat([key: Mandrill.key], params)) 49 | end 50 | def check_domain(domain) do 51 | params = [ 52 | key: Mandrill.key, 53 | domain: domain 54 | ] 55 | Mandrill.request("senders/check-domain", params) 56 | end 57 | 58 | @doc """ 59 | Sends a verification email in order to 60 | verify ownership of a domain. Domain 61 | verification is an optional step to 62 | confirm ownership of a domain. Once a 63 | domain has been verified in a Mandrill 64 | account, other accounts may not have 65 | their messages signed by that domain 66 | unless they also verify the domain. 67 | This prevents other Mandrill accounts 68 | from sending mail signed by your domain. 69 | """ 70 | def verify_domain(params) when is_list(params) do 71 | Mandrill.request("senders/verify-domain", Enum.concat([key: Mandrill.key], params)) 72 | end 73 | def verify_domain(domain, mailbox) do 74 | params = [ 75 | key: Mandrill.key, 76 | domain: domain, 77 | mailbox: mailbox 78 | ] 79 | Mandrill.request("senders/verify-domain", params) 80 | end 81 | 82 | @doc """ 83 | Return more detailed information about a 84 | single sender, including aggregates of 85 | recent stats 86 | """ 87 | def info(params) when is_list(params) do 88 | Mandrill.request("senders/info", Enum.concat([key: Mandrill.key], params)) 89 | end 90 | def info(address) do 91 | params = [ 92 | key: Mandrill.key, 93 | address: address 94 | ] 95 | Mandrill.request("senders/info", params) 96 | end 97 | 98 | @doc """ 99 | Return the recent history (hourly stats 100 | for the last 30 days) for a sender 101 | """ 102 | def time_series(params) when is_list(params) do 103 | Mandrill.request("senders/time-series", Enum.concat([key: Mandrill.key], params)) 104 | end 105 | def time_series(address) do 106 | params = [ 107 | key: Mandrill.key, 108 | address: address 109 | ] 110 | Mandrill.request("senders/time-series", params) 111 | end 112 | end -------------------------------------------------------------------------------- /lib/mandrill/subaccounts.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Subaccounts do 2 | @moduledoc """ 3 | Subaccounts calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Get the list of subaccounts defined for 8 | the account, optionally filtered by a 9 | prefix 10 | """ 11 | def list(params) when is_list(params) do 12 | Mandrill.request("subaccounts/list", Enum.concat([key: Mandrill.key], params)) 13 | end 14 | def list(q) do 15 | params = [ 16 | key: Mandrill.key, 17 | q: q 18 | ] 19 | Mandrill.request("subaccounts/list", params) 20 | end 21 | 22 | @doc """ 23 | Add a new subaccount 24 | """ 25 | def add(params) when is_list(params) do 26 | Mandrill.request("subaccounts/add", Enum.concat([key: Mandrill.key], params)) 27 | end 28 | def add(id, name, notes, custom_quota) do 29 | params = [ 30 | key: Mandrill.key, 31 | id: id, 32 | name: name, 33 | notes: notes, 34 | custom_quota: custom_quota 35 | ] 36 | Mandrill.request("subaccounts/add", params) 37 | end 38 | 39 | @doc """ 40 | Given the ID of an existing subaccount, 41 | return the data about it 42 | """ 43 | def info(params) when is_list(params) do 44 | Mandrill.request("subaccounts/info", Enum.concat([key: Mandrill.key], params)) 45 | end 46 | def info(id) do 47 | params = [ 48 | key: Mandrill.key, 49 | id: id 50 | ] 51 | Mandrill.request("subaccounts/info", params) 52 | end 53 | 54 | @doc """ 55 | Update an existing subaccount 56 | """ 57 | def update(params) when is_list(params) do 58 | Mandrill.request("subaccounts/update", Enum.concat([key: Mandrill.key], params)) 59 | end 60 | def update(id, name, notes, custom_quota) do 61 | params = [ 62 | key: Mandrill.key, 63 | id: id, 64 | name: name, 65 | notes: notes, 66 | custom_quota: custom_quota 67 | ] 68 | Mandrill.request("subaccounts/update", params) 69 | end 70 | 71 | @doc """ 72 | Delete an existing subaccount. Any email 73 | related to the subaccount will be saved, 74 | but stats will be removed and any future 75 | sending calls to this subaccount will fail. 76 | """ 77 | def delete(params) when is_list(params) do 78 | Mandrill.request("subaccounts/delete", Enum.concat([key: Mandrill.key], params)) 79 | end 80 | def delete(id) do 81 | params = [ 82 | key: Mandrill.key, 83 | id: id 84 | ] 85 | Mandrill.request("subaccounts/delete", params) 86 | end 87 | 88 | @doc """ 89 | Pause a subaccount's sending. Any future 90 | emails delivered to this subaccount will be 91 | queued for a maximum of 3 days until the 92 | subaccount is resumed. 93 | """ 94 | def pause(params) when is_list(params) do 95 | Mandrill.request("subaccounts/pause", Enum.concat([key: Mandrill.key], params)) 96 | end 97 | def pause(id) do 98 | params = [ 99 | key: Mandrill.key, 100 | id: id 101 | ] 102 | Mandrill.request("subaccounts/pause", params) 103 | end 104 | 105 | @doc """ 106 | Resume a paused subaccount's sending 107 | """ 108 | def resume(params) when is_list(params) do 109 | Mandrill.request("subaccounts/resume", Enum.concat([key: Mandrill.key], params)) 110 | end 111 | def resume(id) do 112 | params = [ 113 | key: Mandrill.key, 114 | id: id 115 | ] 116 | Mandrill.request("subaccounts/resume", params) 117 | end 118 | end -------------------------------------------------------------------------------- /lib/mandrill/supervisor.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Supervisor do 2 | use Supervisor 3 | 4 | def start_link do 5 | :supervisor.start_link(__MODULE__, []) 6 | end 7 | 8 | def init([]) do 9 | children = [ 10 | # Define workers and child supervisors to be supervised 11 | # worker(Mandrill.Worker, []) 12 | ] 13 | 14 | # See http://elixir-lang.org/docs/stable/Supervisor.Behaviour.html 15 | # for other strategies and supported options 16 | supervise(children, strategy: :one_for_one) 17 | end 18 | end -------------------------------------------------------------------------------- /lib/mandrill/tags.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Tags do 2 | @moduledoc """ 3 | Tags calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Return all of the user-defined tag 8 | information 9 | """ 10 | def list do 11 | params = [ key: Mandrill.key ] 12 | Mandrill.request("tags/list", params) 13 | end 14 | 15 | @doc """ 16 | Deletes a tag permanently. Deleting a tag 17 | removes the tag from any messages that 18 | have been sent, and also deletes the tag's 19 | stats. There is no way to undo this 20 | operation, so use it carefully. 21 | """ 22 | def delete(params) when is_list(params) do 23 | Mandrill.request("tags/delete", Enum.concat([key: Mandrill.key], params)) 24 | end 25 | def delete(tag) do 26 | params = [ 27 | key: Mandrill.key, 28 | tag: tag 29 | ] 30 | Mandrill.request("tags/delete", params) 31 | end 32 | 33 | @doc """ 34 | Return more detailed information about a 35 | single tag, including aggregates of recent 36 | stats 37 | """ 38 | def info(params) when is_list(params) do 39 | Mandrill.request("tags/info", Enum.concat([key: Mandrill.key], params)) 40 | end 41 | def info(tag) do 42 | params = [ 43 | key: Mandrill.key, 44 | tag: tag 45 | ] 46 | Mandrill.request("tags/info", params) 47 | end 48 | 49 | @doc """ 50 | Return the recent history (hourly stats 51 | for the last 30 days) for a tag 52 | """ 53 | def time_series(params) when is_list(params) do 54 | Mandrill.request("tags/time-series", Enum.concat([key: Mandrill.key], params)) 55 | end 56 | def time_series(tag) do 57 | params = [ 58 | key: Mandrill.key, 59 | tag: tag 60 | ] 61 | Mandrill.request("tags/time-series", params) 62 | end 63 | 64 | @doc """ 65 | Return the recent history (hourly stats 66 | for the last 30 days) for all tags 67 | """ 68 | def all_time_series do 69 | params = [ key: Mandrill.key ] 70 | Mandrill.request("tags/all-time-series", params) 71 | end 72 | end -------------------------------------------------------------------------------- /lib/mandrill/templates.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Templates do 2 | @moduledoc """ 3 | Templates calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Add a new template 8 | """ 9 | def add(params) when is_list(params) do 10 | Mandrill.request("templates/add", Enum.concat([key: Mandrill.key], params)) 11 | end 12 | def add(name, from_email, from_name, subject, code, text, publish, labels) do 13 | params = [ 14 | key: Mandrill.key, 15 | name: name, 16 | from_email: from_email, 17 | from_name: from_name, 18 | subject: subject, 19 | code: code, 20 | text: text, 21 | publish: publish, 22 | labels: labels 23 | ] 24 | Mandrill.request("templates/add", params) 25 | end 26 | 27 | @doc """ 28 | Get the information for an existing 29 | template 30 | """ 31 | def info(params) when is_list(params) do 32 | Mandrill.request("templates/info", Enum.concat([key: Mandrill.key], params)) 33 | end 34 | def info(name) do 35 | params = [ 36 | key: Mandrill.key, 37 | name: name 38 | ] 39 | Mandrill.request("templates/info", params) 40 | end 41 | 42 | @doc """ 43 | Update the code for an existing template. 44 | If null is provided for any fields, the 45 | values will remain unchanged. 46 | """ 47 | def update(params) when is_list(params) do 48 | Mandrill.request("templates/update", Enum.concat([key: Mandrill.key], params)) 49 | end 50 | def update(name, from_email, from_name, subject, code, text, publish, labels) do 51 | params = [ 52 | key: Mandrill.key, 53 | name: name, 54 | from_email: from_email, 55 | from_name: from_name, 56 | subject: subject, 57 | code: code, 58 | text: text, 59 | publish: publish, 60 | labels: labels 61 | ] 62 | Mandrill.request("templates/update", params) 63 | end 64 | 65 | @doc """ 66 | Publish the content for the template. Any 67 | new messages sent using this template will 68 | start using the content that was 69 | previously in draft. 70 | """ 71 | def publish(params) when is_list(params) do 72 | Mandrill.request("templates/publish", Enum.concat([key: Mandrill.key], params)) 73 | end 74 | def publish(name) do 75 | params = [ 76 | key: Mandrill.key, 77 | name: name 78 | ] 79 | Mandrill.request("templates/publish", params) 80 | end 81 | 82 | @doc """ 83 | Delete a template 84 | """ 85 | def delete(params) when is_list(params) do 86 | Mandrill.request("templates/delete", Enum.concat([key: Mandrill.key], params)) 87 | end 88 | def delete(name) do 89 | params = [ 90 | key: Mandrill.key, 91 | name: name 92 | ] 93 | Mandrill.request("templates/delete", params) 94 | end 95 | 96 | @doc """ 97 | Return a list of all the templates 98 | available to this user 99 | """ 100 | def list(params) when is_list(params) do 101 | Mandrill.request("templates/list", Enum.concat([key: Mandrill.key], params)) 102 | end 103 | def list(label) do 104 | params = [ 105 | key: Mandrill.key, 106 | label: label 107 | ] 108 | Mandrill.request("templates/list", params) 109 | end 110 | 111 | @doc """ 112 | Return the recent history (hourly stats for 113 | the last 30 days) for a template 114 | """ 115 | def time_series(params) when is_list(params) do 116 | Mandrill.request("templates/time-series", Enum.concat([key: Mandrill.key], params)) 117 | end 118 | def time_series(name) do 119 | params = [ 120 | key: Mandrill.key, 121 | name: name 122 | ] 123 | Mandrill.request("templates/time-series", params) 124 | end 125 | 126 | @doc """ 127 | Inject content and optionally merge fields 128 | into a template, returning the HTML that results 129 | """ 130 | def render(params) when is_list(params) do 131 | Mandrill.request("templates/render", Enum.concat([key: Mandrill.key], params)) 132 | end 133 | def render(template_name, template_content, merge_vars) do 134 | params = [ 135 | key: Mandrill.key, 136 | template_name: template_name, 137 | template_content: template_content, 138 | merge_vars: merge_vars 139 | ] 140 | Mandrill.request("templates/render", params) 141 | end 142 | end -------------------------------------------------------------------------------- /lib/mandrill/urls.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Urls do 2 | @moduledoc """ 3 | Urls calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Get the 100 most clicked URLs 8 | """ 9 | def list do 10 | params = [ key: Mandrill.key ] 11 | Mandrill.request("urls/list", params) 12 | end 13 | 14 | @doc """ 15 | Return the 100 most clicked URLs that 16 | match the search query given 17 | """ 18 | def search(params) when is_list(params) do 19 | Mandrill.request("urls/search", Enum.concat([key: Mandrill.key], params)) 20 | end 21 | def search(q) do 22 | params = [ 23 | key: Mandrill.key, 24 | q: q 25 | ] 26 | Mandrill.request("urls/search", params) 27 | end 28 | 29 | @doc """ 30 | Return the recent history (hourly stats 31 | for the last 30 days) for a url 32 | """ 33 | def time_series(params) when is_list(params) do 34 | Mandrill.request("urls/time-series", Enum.concat([key: Mandrill.key], params)) 35 | end 36 | def time_series(url) do 37 | params = [ 38 | key: Mandrill.key, 39 | url: url 40 | ] 41 | Mandrill.request("urls/time-series", params) 42 | end 43 | 44 | @doc """ 45 | Get the list of tracking domains set up 46 | for this account 47 | """ 48 | def tracking_domains do 49 | params = [ key: Mandrill.key ] 50 | Mandrill.request("urls/tracking-domain", params) 51 | end 52 | 53 | @doc """ 54 | Add a tracking domain to your account 55 | """ 56 | def add_tracking_domain(params) when is_list(params) do 57 | Mandrill.request("urls/add-tracking-domain", Enum.concat([key: Mandrill.key], params)) 58 | end 59 | def add_tracking_domain(domain) do 60 | params = [ 61 | key: Mandrill.key, 62 | domain: domain 63 | ] 64 | Mandrill.request("urls/add-tracking-domain", params) 65 | end 66 | 67 | @doc """ 68 | Checks the CNAME settings for a tracking 69 | domain. The domain must have been added 70 | already with the add-tracking-domain call 71 | """ 72 | def check_tracking_domain(params) when is_list(params) do 73 | Mandrill.request("urls/check-tracking-domain", Enum.concat([key: Mandrill.key], params)) 74 | end 75 | def check_tracking_domain(domain) do 76 | params = [ 77 | key: Mandrill.key, 78 | domain: domain 79 | ] 80 | Mandrill.request("urls/check-tracking-domain", params) 81 | end 82 | end -------------------------------------------------------------------------------- /lib/mandrill/users.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Users do 2 | @moduledoc """ 3 | Users calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Return the information about the 8 | API-connected user 9 | """ 10 | def info do 11 | params = [ key: Mandrill.key ] 12 | Mandrill.request("users/info", params) 13 | end 14 | 15 | @doc """ 16 | Validate an API key and respond to 17 | a ping 18 | """ 19 | def ping do 20 | params = [ key: Mandrill.key ] 21 | Mandrill.request("users/ping", params) 22 | end 23 | 24 | @doc """ 25 | Validate an API key and respond to a 26 | ping (anal JSON parser version) 27 | """ 28 | def ping2 do 29 | params = [ key: Mandrill.key ] 30 | Mandrill.request("users/ping2", params) 31 | end 32 | 33 | @doc """ 34 | Return the senders that have tried to 35 | use this account, both verified and 36 | unverified 37 | """ 38 | def senders do 39 | params = [ key: Mandrill.key ] 40 | Mandrill.request("users/senders", params) 41 | end 42 | end -------------------------------------------------------------------------------- /lib/mandrill/webhooks.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Webhooks do 2 | @moduledoc """ 3 | Webhooks calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Get the list of all webhooks 8 | defined on the account 9 | """ 10 | def list do 11 | params = [ key: Mandrill.key ] 12 | Mandrill.request("webhooks/list", params) 13 | end 14 | 15 | @doc """ 16 | Add a new webhook 17 | """ 18 | def add(params) when is_list(params) do 19 | Mandrill.request("webhooks/add", Enum.concat([key: Mandrill.key], params)) 20 | end 21 | def add(url, description, events) do 22 | params = [ 23 | key: Mandrill.key, 24 | url: url, 25 | description: description, 26 | events: events 27 | ] 28 | Mandrill.request("webhooks/add", params) 29 | end 30 | 31 | @doc """ 32 | Given the ID of an existing 33 | webhook, return the data about it 34 | """ 35 | def info(params) when is_list(params) do 36 | Mandrill.request("webhooks/info", Enum.concat([key: Mandrill.key], params)) 37 | end 38 | def info(id) do 39 | params = [ 40 | key: Mandrill.key, 41 | id: id 42 | ] 43 | Mandrill.request("webhooks/info", params) 44 | end 45 | 46 | @doc """ 47 | Update an existing webhook 48 | """ 49 | def update(params) when is_list(params) do 50 | Mandrill.request("webhooks/update", Enum.concat([key: Mandrill.key], params)) 51 | end 52 | def update(id, url, description, events) do 53 | params = [ 54 | key: Mandrill.key, 55 | id: id, 56 | url: url, 57 | description: description, 58 | events: events 59 | ] 60 | Mandrill.request("webhooks/update", params) 61 | end 62 | 63 | @doc """ 64 | Delete an existing webhook 65 | """ 66 | def delete(params) when is_list(params) do 67 | Mandrill.request("webhooks/delete", Enum.concat([key: Mandrill.key], params)) 68 | end 69 | def delete(id) do 70 | params = [ 71 | key: Mandrill.key, 72 | id: id 73 | ] 74 | Mandrill.request("webhooks/delete", params) 75 | end 76 | end -------------------------------------------------------------------------------- /lib/mandrill/whitelists.ex: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Whitelists do 2 | @moduledoc """ 3 | Whitelists calls for Mandrill. 4 | """ 5 | 6 | @doc """ 7 | Adds an email to your email rejection 8 | whitelist. If the address is currently 9 | on your blacklist, that blacklist entry 10 | will be removed automatically. 11 | """ 12 | def add(params) when is_list(params) do 13 | Mandrill.request("whitelists/add", Enum.concat([key: Mandrill.key], params)) 14 | end 15 | def add(email) do 16 | params = [ 17 | key: Mandrill.key, 18 | email: email 19 | ] 20 | Mandrill.request("whitelists/add", params) 21 | end 22 | 23 | @doc """ 24 | Retrieves your email rejection whitelist. 25 | You can provide an email address or 26 | search prefix to limit the results. 27 | Returns up to 1000 results. 28 | """ 29 | def list(params) when is_list(params) do 30 | Mandrill.request("whitelists/list", Enum.concat([key: Mandrill.key], params)) 31 | end 32 | def list(email) do 33 | params = [ 34 | key: Mandrill.key, 35 | email: email 36 | ] 37 | Mandrill.request("whitelists/list", params) 38 | end 39 | 40 | @doc """ 41 | Removes an email address from the 42 | whitelist. 43 | """ 44 | def delete(params) when is_list(params) do 45 | Mandrill.request("whitelists/delete", Enum.concat([key: Mandrill.key], params)) 46 | end 47 | def delete(email) do 48 | params = [ 49 | key: Mandrill.key, 50 | email: email 51 | ] 52 | Mandrill.request("whitelists/delete", params) 53 | end 54 | end -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Mandrill.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [ app: :mandrill, 6 | version: "0.5.0", 7 | elixir: "~> 1.0", 8 | description: description, 9 | package: package, 10 | deps: deps ] 11 | end 12 | 13 | def application do 14 | [ mod: { Mandrill, [] }, 15 | applications: [:httpoison, :exjsx] ] 16 | end 17 | 18 | defp deps do 19 | [ 20 | { :httpoison, "~> 0.6" }, 21 | { :exjsx, "~> 3.2.0", app: false }, 22 | { :ex_doc, "~> 0.6.1", only: :docs }, 23 | { :earmark, "~> 0.1.12", only: :docs } 24 | ] 25 | end 26 | 27 | defp description do 28 | """ 29 | A Mandrill wrapper for Elixir 30 | 31 | Requires an active account with Mandrill (http://mandrill.com). 32 | """ 33 | end 34 | 35 | defp package do 36 | [ files: [ "lib", "mix.exs", "README.md", "LICENSE" ], 37 | maintainers: [ "Shane Logsdon" ], 38 | licenses: [ "MIT" ], 39 | links: %{ "GitHub" => "https://github.com/slogsdon/mandrill-elixir" } ] 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{"earmark": {:hex, :earmark, "0.1.13"}, 2 | "ex_doc": {:hex, :ex_doc, "0.6.2"}, 3 | "exjsx": {:hex, :exjsx, "3.2.0"}, 4 | "hackney": {:hex, :hackney, "1.0.6"}, 5 | "httpoison": {:hex, :httpoison, "0.6.2"}, 6 | "idna": {:hex, :idna, "1.0.2"}, 7 | "jsx": {:hex, :jsx, "2.6.2"}, 8 | "ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.1"}} 9 | -------------------------------------------------------------------------------- /test/mandrill_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MandrillTest do 2 | use ExUnit.Case 3 | 4 | test "the truth" do 5 | assert(true) 6 | end 7 | 8 | test "ping returns pong" do 9 | Mandrill.start 10 | assert Mandrill.Users.ping == "PONG!" 11 | end 12 | 13 | test "process_response_body returns a map with string keys" do 14 | assert Mandrill.process_response_body("{\"language\": \"elixir\", \"awesome\": true}") == %{"awesome" => true, "language" => "elixir"} 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start 2 | --------------------------------------------------------------------------------