sparkpost / elixir-sparkpost Goto Github PK
View Code? Open in Web Editor NEWSparkPost client library for Elixir https://developers.sparkpost.com
License: Apache License 2.0
SparkPost client library for Elixir https://developers.sparkpost.com
License: Apache License 2.0
The example for sending using the API doesn't work as-is. Specifically:
defmodule MyApp.Example do
alias SparkPost.Transmission
alias SparkPost.Recipient
alias SparkPost.Template
def send_message do
Transmission.create(%Transmission{
recipients: [ %Recipient{ address: %Sparkpost.Address{ email: "[email protected]" }} ],
return_path: "[email protected]",
content: %Template.Inline{
subject: "Sending email from Elixir is awesome!",
from: %Sparkpost.Address{ email: "[email protected]" },
text: "Hi there!",
html: "<p>Hi there!</p>"
}
})
end
end
Sparkpost.Address
should be SparkPost.Address
SparkPost.Template
We should also use the new Elixir 1.2 syntax for aliases to change this:
alias SparkPost.Transmission
alias SparkPost.Recipient
alias SparkPost.Template
To this:
alias SparkPost.{Transmission, Recipient, Template}
A few other things:
recipients: ["[email protected]", "Friendly Person <[email protected]"]
and just handle the splitting/converting to structs for the userdefmodule
s in the filesreturn_path
is completely ignored for SparkPost.com so we should set a default like we do in other libs.
Discussed with @ewandennis on Slack, but filing this ticket for reference/
What probably want is the function Application.spec(:sparkpost, :vsn)
…which will query the VM for the application version number. The problem currently is that it’s not going to be in the env
for the app as far as I know. Although, I’m having problems getting any specs locally for it anyways. From our corporate app:
iex(1)> Application.spec(:sparkpost, :vsn)
nil
iex(2)> Application.spec(:poison, :vsn)
'3.0.0'
iex(3)> Application.spec(:hackney, :vsn)
'1.6.3'
iex(4)> Application.spec(:phoenix, :vsn)
'1.2.1'
This may be because the release was built on an older version of Elixir, so it didn't package the necessary metadata for this.
One of the nice things about Swoosh is the Test adapter which causes emails to be sent to the calling process. We end up with very nice tests that look like:
// do_something_that_causes_an_email_to_be_sent()
token = receive do
{:email, msg} ->
assert msg.subject == "Password Reset"
%{"token" => token} = Regex.named_captures(~r/token=(?<token>[^"]+)/, msg.html_body)
token
after
500 -> assert false
end
// assert that token was stored in the DB
Need to have css inlined for templates to render properly. Seems this can be grouped in a PR with issue #19
Seems the url is built incorrectly in the case of Template.preview. The url is generated as
"https://api.sparkpost.com/api/v1//templates/#{id}/preview"
Note the double dash. Should be a quick fix, so I'll submit a PR.
I need to define a custom ip pool, but I see this option is not implemented yet.
I'll open a pull request to add the "ip_pool" option to the module SparkPost.Transmission.Options
...
when running mix deps.get
mix throws an error
phoenix (version 1.2.4) requires ~> 1.5 or ~> 2.0
sparkpost (version 0.5.0) requires ~> 3.0
because sparkpost requires poison of version 3.0 and phoenix requires somewere between 1.5 to 2.2
I forked and lwoered poison version to 2.2.0 and it works
https://github.com/programisti/elixir-sparkpost
Our SparkPost server is sitting behind an OAuth 1.0 gateway on our internal network. While adding OAuth support would probably be a heavyweight approach--I wonder if there would be some way to decouple the specific HTTP client being used, for a more bring-your-own approach?
Creating this ticket so I can remove a TODO from code.
Poison.encode(keys: :atoms)
is potentially unsafe for open ended structures such as metadata
and substitution_data
, as atoms are not garbage collected and are a definite (albeit often slow) memory leak. Substitution data and metadata should be decoded into a string keys map.
Version: using 0.5.1 from hex.
Actual:
iex(103)> SparkPost.Transmission.get("156823913470671414")
%SparkPost.Endpoint.Error{errors: [%{message: "You may use the Message Events API to retrieve event data for your transmission. For example https://api.sparkpost.com/api/v1/message-events?from=2018-01-05T03:00&transmission_ids=156823913470671414"}],
results: nil, status_code: 404}
Expected:
Results like the following:
elixir-sparkpost/lib/transmission.ex
Lines 140 to 150 in 5f43828
Might want to update your readme to include the latest version, changing:
{:sparkpost, "~> 0.1.0"}
to
{:sparkpost, "~> 0.2.1"}
We should test against 1.2, 1.3 and 1.4.
I'm still using this library on a project or two, but over the time, I was forced to add compatibility wrappers for a lot of stuff missing here.
My PR which adds support for transmissions endpoints has been open for two years.
The upcoming changes to the transmissions API will likely end up breaking a fair chunk of what's currently still working.
Is there a way to get contributor privileges here, so I can do some maintenance myself, at least? I already tried contacting Sparkpost via the support infrastructure.
I would really like to revive this.
The latest version of Poison is 3.0.0
@richleland As I was going through the requirements for change implementation for #12 I realized that the tests depend significantly on mocking the behaviour of HTTPotion. Moving forward, would you be open to preferring a dependency injection model over mocking? This is the style preferred for Elixir core components (see "Mocks and explicit contracts" – José Valim on Plataformatec Blog).
My thoughts would be to do this once #12 is complete but prior to further development.
I'm experiencing timeout issues while sending mails (with attachment) and I'd like to increase the request timeout value.
HTTPotion accepts option "timeout" but looking at SparkPost.Endpoint.request it looks like it's not configurable yet. Is it something you're going to implement?
The code blocks under each bullet need indented to continue the numbered list properly.
The readme has some formatting/indentation errors, but more importantly, it instructs the developer to install an old version of the package.
The user should be instructed to install the latest, 0.4.0.
It'd be nice if functions returned {:error, X}
and {:ok, Y}
. It results in more elegant client code that doesn't have to match against specific structures.
def(%Transmission.Response{id: id), do: ...
vs
def({:ok, %{id: id}}), do: ...
Same same with case
and with
After the migration from HTTPotion to HTTPoison, I started to get timeout errors.
It seems the meaning of (sparkpost) http_timeout
slightly changed. HTTPoison handles two different timeout options:
:timeout - timeout to establish a connection, in milliseconds. Default is 8000
:recv_timeout - timeout used when receiving a connection. Default is 5000
http_timeout
should be used to populate recv_timeout
, but it is currently tied to timeout
.
I fixed it and I'm testing it right now. No errors so far, tomorrow I'll send a PR.
are there any plans to add support for the template API anytime soon? Noticed that the python library does - specifically looking for the "preview template" endpoint.
Would be happy to contribute if necessary!
Is there a specific reason why the body is being decoded with keys as atoms?
# lib/endpoint.ex:85-89@30402ea
defp decode_response_body(body) do
# TODO: [key: :atoms] is unsafe for open-ended structures such as
# metadata and substitution_data
body |> Poison.decode!([keys: :atoms])
end
While this can be convenient, and definitely draws in Ruby's preference of symbols over strings, I feel that it unnecessarily grows the atom-space in BEAM which should be left to the determination of the end-programmer if the atom itself is not declared in-code.
Because it's fly - https://github.com/edgurgel/httpoison
I gathered that the library has migrated from HTTPotion to HTTPoison (#12), which relies on hackney rather than ibrowse.
I would be great if the README is updated accordingly to avoid confusing newcomers like me.
currently uses an older version of httpoison
There's no Hex release that includes the HTTPoison switch
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.