Skip to content

Commit ce89baf

Browse files
committed
Update version and docs
1 parent d1e113c commit ce89baf

File tree

5 files changed

+121
-66
lines changed

5 files changed

+121
-66
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.5.0 (2017-7-3)
4+
* Enhancements
5+
* update docs
6+
* upgrade to Elixir 1.4
7+
* add support for Phoenix Views
8+
39
## 1.4.0 (2017-2-15)
410
* Enhancements
511
* update `httpoison` to 0.11.0 and `poison` to 3.0

README.md

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# SendGrid
22

33
A wrapper for SendGrid's API to create composable emails.
4+
Check the [docs](https://hexdocs.pm/sendgrid/) for complete usage.
5+
6+
## Example
7+
8+
```elixir
9+
SendGrid.Email.build()
10+
|> SendGrid.Email.add_to("test@email.com")
11+
|> SendGrid.Email.put_from("test2@email.com")
12+
|> SendGrid.Email.put_subject("Hello from Elixir")
13+
|> SendGrid.Email.put_text("Sent with Elixir")
14+
|> SendGrid.Mailer.send()
15+
```
416

517
## Installation
618

719
Add the following code to your dependencies in your **`mix.exs`** file:
820

921
```elixir
10-
{:sendgrid, "~> 1.4.0"}
22+
{:sendgrid, "~> 1.5.0"}
1123
```
1224

1325
## Configuration
@@ -27,59 +39,46 @@ config :sendgrid,
2739
sandbox_enable: true
2840
```
2941

30-
31-
3242
Add `:sendgrid` to your list of applications
3343
```elixir
3444
defp application do
3545
[applications: [:sendgrid]]
3646
end
3747
```
3848

39-
## Usage
4049

41-
Check the [docs](https://hexdocs.pm/sendgrid/) for complete usage.
42-
43-
### Simple Text Email
50+
## Phoenix Views
4451

45-
```elixir
46-
alias SendGrid.{Mailer, Email}
47-
48-
email =
49-
Email.build()
50-
|> Email.put_from("test@email.com")
51-
|> Email.add_to("test2@email.com")
52-
|> Email.put_subject("Hello From Elixir")
53-
|> Email.put_text("Sent from Elixir!")
54-
55-
Mailer.send(email)
56-
```
52+
You can use Phoenix Views to set your HTML and text content of your emails. You just have
53+
to provide a view module and template name and you're good to go! See `SendGrid.Email.put_phoenix_template/3` for complete usage.
5754

58-
### Simple HTML Email
55+
### Examples
5956

6057
```elixir
61-
alias SendGrid.{Mailer, Email}
62-
63-
email =
64-
Email.build()
65-
|> Email.put_from("test@email.com")
66-
|> Email.add_to("test2@email.com")
67-
|> Email.put_subject("Hello From Elixir")
68-
|> Email.put_html("<html><body><p>Sent from Elixir!</p></body></html>")
69-
70-
Mailer.send(email)
58+
import SendGrid.Email
59+
60+
# Using an HTML template
61+
%SendGrid.Email{}
62+
|> put_phoenix_view(MyApp.Web.EmailView)
63+
|> put_phoenix_template("welcome_email.html", user: user)
64+
65+
# Using a text template
66+
%SendGridEmail{}
67+
|> put_phoenix_view(MyApp.Web.EmailView)
68+
|> put_phoenix_template("welcome_email.txt", user: user)
69+
70+
# Using both an HTML and text template
71+
# Notice that there is no extension.
72+
%SendGrid.Email{}
73+
|> put_phoenix_view(MyApp.Web.EmailView)
74+
|> put_phoenix_template("welcome_email", user: user)
7175
```
7276

73-
### Using a SendGrid Predefined Template
77+
### Using a Default Phoenix View
7478

75-
```elixir
76-
alias SendGrid.{Mailer, Email}
77-
78-
email =
79-
Email.build()
80-
|> Email.put_template("the_template_id")
81-
|> Email.add_substitution("-foo-", "bar")
82-
|> Email.put_html("<span>Some Text</span>")
83-
84-
Mailer.send(email)
79+
You can set a default Phoenix View to use for rendering templates. Just set the `:phoenix_view` config value
80+
81+
```elxir
82+
config :sendgrid,
83+
:phoenix_view: MyApp.Web.EmailView
8584
```

lib/sendgrid/email.ex

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,70 @@ defmodule SendGrid.Email do
22
@moduledoc """
33
Email primitive for composing emails with SendGrid's API.
44
5-
## Examples
5+
You can easily compose on an Email to set the fields of your email.
6+
7+
## Example
8+
9+
Email.build()
10+
|> Email.add_to("test@email.com")
11+
|> Email.put_from("test2@email.com")
12+
|> Email.put_subject("Hello from Elixir")
13+
|> Email.put_text("Sent with Elixir")
14+
|> SendGrid.Mailer.send()
15+
16+
## SendGrid Specific Features
17+
18+
Many common features of SendGrid V3 API for transactional emails are supported.
19+
20+
### Templates
21+
22+
You can use a SendGrid template by providing a template id.
23+
24+
put_template(email, "some_template_id")
25+
26+
### Substitutions
27+
28+
You can provided a key-value pair for subsititions to have text replaced.
29+
30+
add_substitution(email, "-key-", "value")
31+
32+
### Scheduled Sending
33+
34+
You can provide a Unix timestamp to have an email delivered in the future.
35+
36+
send_at(email, 1409348513)
37+
38+
## Phoenix Views
39+
40+
You can use Phoenix Views to set your HTML and text content of your emails. You just have
41+
to provide a view module and template name and you're good to go! See `put_phoenix_template/3`
42+
for complete usage.
43+
44+
### Examples
45+
46+
# Using an HTML template
47+
%Email{}
48+
|> put_phoenix_view(MyApp.Web.EmailView)
49+
|> put_phoenix_template("welcome_email.html", user: user)
50+
51+
# Using a text template
52+
%Email{}
53+
|> put_phoenix_view(MyApp.Web.EmailView)
54+
|> put_phoenix_template("welcome_email.txt", user: user)
55+
56+
# Using both an HTML and text template
57+
# Notice that there is no extension.
58+
%Email{}
59+
|> put_phoenix_view(MyApp.Web.EmailView)
60+
|> put_phoenix_template("welcome_email", user: user)
61+
62+
### Using a Default Phoenix View
63+
64+
You can set a default Phoenix View to use for rendering templates. Just set the `:phoenix_view`
65+
config value
666
7-
iex> Email.build()
8-
...> |> Email.add_to("test@email.com")
9-
...> |> Email.put_from("test2@email.com")
10-
...> |> Email.put_subject("Hello from Elixir")
11-
...> |> Email.put_text("Sent with Elixir")
12-
%Email{
13-
to: %{ email: "test@email.com" },
14-
from %{ email: "test2@email.com" },
15-
subject: "Hello from Elixir",
16-
content: [%{ type: "text/plain", value: "Sent with Elixir" }],
17-
...
18-
}
67+
config :sendgrid,
68+
:phoenix_view: MyApp.Web.EmailView
1969
2070
"""
2171

@@ -51,13 +101,13 @@ defmodule SendGrid.Email do
51101
attachments: nil | [attachment],
52102
__phoenix_view__: nil | atom}
53103

54-
@type recipient :: %{ email: String.t, name: String.t | nil }
55-
@type content :: %{ type: String.t, value: String.t }
56-
@type header :: { String.t, String.t }
104+
@type recipient :: %{email: String.t, name: String.t | nil}
105+
@type content :: %{type: String.t, value: String.t}
106+
@type header :: {String.t, String.t}
57107
@type attachment :: %{content: String.t, type: String.t, filename: String.t, disposition: String.t, content_id: String.t}
58108

59-
@type substitutions :: %{ String.t => String.t }
60-
@type custom_args :: %{ String.t => String.t }
109+
@type substitutions :: %{String.t => String.t}
110+
@type custom_args :: %{String.t => String.t}
61111

62112
@doc """
63113
Builds an an empty email to compose on.
@@ -351,7 +401,7 @@ defmodule SendGrid.Email do
351401
352402
## Examples
353403
354-
Email.put_phoenix_view(email, MyApp.Web.EmailView)
404+
put_phoenix_view(email, MyApp.Web.EmailView)
355405
356406
"""
357407
@spec put_phoenix_view(t, atom) :: t
@@ -383,13 +433,13 @@ defmodule SendGrid.Email do
383433
384434
## Examples
385435
386-
iex> Email.put_phoenix_template(email, "some_template.html")
436+
iex> put_phoenix_template(email, "some_template.html")
387437
%Email{content: [%{type: "text/html", value: ...}], ...}
388438
389-
iex> Email.put_phoenix_template(email, "some_template.txt", name: "John Doe")
439+
iex> put_phoenix_template(email, "some_template.txt", name: "John Doe")
390440
%Email{content: [%{type: "text/plain", value: ...}], ...}
391441
392-
iex> Email.put_phoenix_template(email, "some_template", user: user)
442+
iex> put_phoenix_template(email, "some_template", user: user)
393443
%Email{content: [%{type: "text/plain", value: ...}, %{type: "text/html", value: ...}], ...}
394444
395445
"""

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule SendGrid.Mixfile do
33

44
def project do
55
[app: :sendgrid,
6-
version: "1.4.0",
6+
version: "1.5.0",
77
elixir: "~> 1.4",
88
package: package(),
99
compilers: compilers(Mix.env),
@@ -37,7 +37,7 @@ defmodule SendGrid.Mixfile do
3737
{:earmark, "~> 1.2", only: :dev},
3838
{:ex_doc, "~> 0.16.2", only: :dev},
3939
{:httpoison, "~> 0.11.0"},
40-
{:poison, "~> 3.1", override: true},
40+
{:poison, "~> 2.0"},
4141
{:phoenix, "~> 1.2", only: :test},
4242
{:phoenix_html, "~> 2.9", only: :test}
4343
]

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
1414
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], []},
1515
"plug": {:hex, :plug, "1.3.5", "7503bfcd7091df2a9761ef8cecea666d1f2cc454cbbaf0afa0b6e259203b7031", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
16-
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
16+
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
1717
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
1818
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"}}

0 commit comments

Comments
 (0)