Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Mix.Config

config :sparkpost,
api_endpoint: "https://api.sparkpost.com/api/v1/",
api_key: "YOUR API KEY HERE",
api_key: "--",
http_timeout: 5000,
http_conn_timeout: 8000

Expand Down
2 changes: 1 addition & 1 deletion examples/attachment.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ filename = "test/data/sparky.png"

SparkPost.Transmission.send(
%SparkPost.Transmission{
recipients: [to],
recipients: [ to ],
content: %SparkPost.Content.Inline{
from: from,
subject: "Now with attachments!",
Expand Down
9 changes: 8 additions & 1 deletion lib/address.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule SparkPost.Address do
- `%SparkPost.Recipient.address{from: ...}`
"""

defstruct name: nil, email: :required
defstruct name: nil, email: :required, header_to: nil

@doc """
Convenience conversions to `%SparkPost.Address{}` from:
Expand All @@ -24,6 +24,13 @@ defmodule SparkPost.Address do
%__MODULE__{name: name, email: email}
end

def to_address(%{name: name, email: email, header_to: header_to})do
%__MODULE__{name: name, email: email, header_to: header_to}
end
def to_address(%{ email: email, header_to: header_to})do
%__MODULE__{email: email, header_to: header_to}
end

def to_address(%{email: email})do
%__MODULE__{email: email}
end
Expand Down
1 change: 1 addition & 0 deletions lib/transmission.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ defmodule SparkPost.Transmission do
recipients: Recipient.to_recipient_list(body.recipients),
content: Content.to_content(body.content)
}
IO.inspect body
response = Endpoint.request(:post, "transmissions", body)
Endpoint.marshal_response(response, Transmission.Response)
end
Expand Down
30 changes: 30 additions & 0 deletions test/transmission_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ defmodule SparkPost.TransmissionTest do
%Recipient{ address: %Address{ name: name, email: email} }
end

def addr_spec_recipient( %Recipient{ address: %Address{ email: email, header_to: header_to } }) do
%Recipient{ address: %Address{ email: email, header_to: header_to } }
end

def addr_spec_recipient(email\\"you@there.com") do
%Recipient{ address: %Address{ email: email } }
end


def inline_content do
%Content.Inline{
Expand Down Expand Up @@ -85,6 +90,14 @@ defmodule SparkPost.TransmissionTest do
%{recip | address: parse_address(addr)}
end

defp parse_address(%{name: name, email: email, header_to: header_to}) do
%Address{name: name, email: email, header_to: header_to}
end

defp parse_address(%{email: email, header_to: header_to}) do
%Address{email: email, header_to: header_to}
end

defp parse_address(%{name: name, email: email}) do
%Address{name: name, email: email}
end
Expand Down Expand Up @@ -167,6 +180,23 @@ defmodule SparkPost.TransmissionTest do
)
end

test "Transmission.send accepts a 2 recipents with CC as SparkPost.Address structs" do
# RFC2822 3.4.1: Addr-spec specification
email0 = "to@thisperson.com"
email1 = "bcc@thatperson.com"
recip0 = %SparkPost.Recipient{ address: %SparkPost.Address{ email: email0 } }
recip1 = %SparkPost.Recipient{ address: %SparkPost.Address{ email: email1, header_to: email0 } }

recipients = [ recip0, recip1]
expected = Enum.map recipients, fn recip ->
TestStructs.addr_spec_recipient(recip)
end
TestRequests.test_send(
%{TestStructs.basic_transmission | recipients: recipients},
&(assert &1.recipients == expected)
)
end

test "Transmission.send accepts a mixed list recipient addresses" do
recip0 = "You There <you@there.com>"
recip1 = "youtoo@theretoo.com"
Expand Down