From 944d28097054d6607fe3e5c10bd89163af24e44b Mon Sep 17 00:00:00 2001 From: samuelbambu Date: Wed, 18 Oct 2017 16:25:04 -0600 Subject: [PATCH 1/3] some stuff for making the PR --- config/config.exs | 2 +- examples/attachment.exs | 14 ++++---------- lib/transmission.ex | 1 + 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/config/config.exs b/config/config.exs index f6060fc..9b887e5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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 diff --git a/examples/attachment.exs b/examples/attachment.exs index 5336966..d411244 100644 --- a/examples/attachment.exs +++ b/examples/attachment.exs @@ -1,19 +1,13 @@ -from = "elixir@sparkpostbox.com" -to = "ewan.dennis@sparkpost.com" -filename = "test/data/sparky.png" +from = "soporte@eleventa.com" +to = "dev.sam23d@gmail.com" SparkPost.Transmission.send( %SparkPost.Transmission{ - recipients: [to], + recipients: [ %SparkPost.Recipient{ address: %SparkPost.Address{ email: to } } ], content: %SparkPost.Content.Inline{ from: from, subject: "Now with attachments!", - text: "There is an attachment with this message", - attachments: [ - SparkPost.Content.to_attachment( - Path.basename(filename), "image/jpeg", File.read!(filename) - ) - ] + text: "There is an attachment with this message" } } ) diff --git a/lib/transmission.ex b/lib/transmission.ex index 1c94d16..b132ee9 100644 --- a/lib/transmission.ex +++ b/lib/transmission.ex @@ -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 From 4f0b9144eea028821602b019ad51b6e441c9e80a Mon Sep 17 00:00:00 2001 From: samuelbambu Date: Tue, 24 Oct 2017 17:13:33 -0600 Subject: [PATCH 2/3] bcc test, and address update --- lib/address.ex | 9 ++++++++- test/transmission_test.exs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/address.ex b/lib/address.ex index 4af05ce..91d3a69 100644 --- a/lib/address.ex +++ b/lib/address.ex @@ -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: @@ -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 diff --git a/test/transmission_test.exs b/test/transmission_test.exs index 0e3864e..c4b0fcc 100644 --- a/test/transmission_test.exs +++ b/test/transmission_test.exs @@ -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{ @@ -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 @@ -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 " recip1 = "youtoo@theretoo.com" From 451b2786b507b71ef8e616e33907e1591f0d6ec1 Mon Sep 17 00:00:00 2001 From: samuelbambu Date: Tue, 24 Oct 2017 17:16:26 -0600 Subject: [PATCH 3/3] attachments example, back to original --- examples/attachment.exs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/attachment.exs b/examples/attachment.exs index d411244..0585915 100644 --- a/examples/attachment.exs +++ b/examples/attachment.exs @@ -1,13 +1,19 @@ -from = "soporte@eleventa.com" -to = "dev.sam23d@gmail.com" +from = "elixir@sparkpostbox.com" +to = "ewan.dennis@sparkpost.com" +filename = "test/data/sparky.png" SparkPost.Transmission.send( %SparkPost.Transmission{ - recipients: [ %SparkPost.Recipient{ address: %SparkPost.Address{ email: to } } ], + recipients: [ to ], content: %SparkPost.Content.Inline{ from: from, subject: "Now with attachments!", - text: "There is an attachment with this message" + text: "There is an attachment with this message", + attachments: [ + SparkPost.Content.to_attachment( + Path.basename(filename), "image/jpeg", File.read!(filename) + ) + ] } } )