Skip to content

[Feature] Add Template.list/1 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
341b513
Add Template.create, Template.update
begedin Jul 3, 2018
f36c996
Add Template.delete
begedin Jul 3, 2018
fa4e06b
Add test clause for new endpoint behavior
begedin Jul 3, 2018
83cfe7f
Correct error in update function signature
begedin Jul 3, 2018
a1cba2e
Merge pull request #1 from begedin/template-endpoints
begedin Oct 12, 2020
dbe63bc
Add CI infrastructure, update deps
begedin Oct 12, 2020
51e8c33
Merge pull request #2 from begedin/github-action
begedin Oct 12, 2020
6e4f080
Update docs and formatting in transmission module
begedin Oct 14, 2020
65aa30d
Update changelog
begedin Oct 14, 2020
20a52ef
Update mixfile version & information
begedin Oct 14, 2020
5fba93b
Correct plt cache location
begedin Oct 14, 2020
2149f7d
Merge pull request #3 from begedin/maintenance/update-version
begedin Oct 14, 2020
ac5e94f
Support /events/messages endpoint
begedin Dec 14, 2020
e8b94b9
Merge pull request #4 from begedin/feature/events
begedin Dec 14, 2020
1038d0d
Upgrade elixir
begedin Nov 30, 2022
ed40819
Add `SparkPost.Template.list/1`
begedin Nov 30, 2022
e66943b
Add vscode workspace settings, for easier contributing
begedin Nov 30, 2022
843f280
Update CI
begedin Nov 30, 2022
0ee3806
Remove old CI
begedin Nov 30, 2022
6aecf2b
Remove travis badge from readme
begedin Nov 30, 2022
77a66ed
FIX CI
begedin Nov 30, 2022
2c927ae
Use correct otp
begedin Nov 30, 2022
39a5f45
Remove db service
begedin Nov 30, 2022
dd2582d
Use correct action to setup elixir
begedin Nov 30, 2022
797bba6
Upgrade deps
begedin Nov 30, 2022
fada226
Cleanup dialyzer issues
begedin Nov 30, 2022
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
7 changes: 7 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
inputs: [
"{mix, .formatter, .credo}.exs",
"{config,lib,test}/**/*.{ex,exs}"
],
line_length: 100
]
74 changes: 74 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Elixir CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ["1.14.1"]
otp: ["25.1.1"]
cache: [1]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Restore dependencies cache
id: mix-deps-cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.cache }}-mix

- name: Restore build cache
uses: actions/cache@v1
with:
path: _build
key: cache-${{ runner.os }}-dialyzer_build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: cache-${{ runner.os }}-${{ matrix.cache }}-dialyzer_build-

- name: Install Mix Dependencies
if: steps.mix-deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get

- name: Credo
run: mix credo --strict

- name: Check formatting
run: mix format --check-formatted

- name: Restore PLT Cache
uses: actions/cache@v1
id: plt-cache
with:
path: plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles('**/mix.lock') }}
restore-keys: cache-${{ runner.os }}-${{ matrix.cache }}-dialyzer_build-

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p plts
mix dialyzer --plt

- name: Run dialyzer
run: mix dialyzer

- name: Run tests
run: mix test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
erl_crash.dump
*.ez
*.swp
/plts/*.plt
/plts/*.plt.hash
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elixir 1.14.1-otp-25
erlang 25.1.1
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[elixir]": {
"editor.defaultFormatter": "JakeBecker.elixir-ls"
}
}
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
## Change Log

# 0.7 (2022-11-30)

- [FEATURE] Add `SparkPost.Template.list/1`
- Upgrade elixir to 1.14.1
- Upgrade dialyxir to ~>1.2
- Upgrade poison to ~>5.0
- Upgrade excoveralls to ~>0.15
- Upgrade credo to ~>1.6
- Upgrade ex_doc to ~>0.29

# Older releases
## v0.6 (2020-12-14) [unreleased]

- [FEATURE] Add `SparkPost.Event.search_message_events/1`
- [INTERNAL] Add Github Actions Workflow for CI
- [INTERNAL] Add elixir formatter
- [INTERNAL] Add credo
- [INTERNAL] Add dialyzer
- Update mix elixir version 1.2 -> 1.10.4
- Update htttpoison 1.0 -> 1.7
- Update poison 2.0 or 3.0 -> 4.0
- Update mock 0.2 -> 0.3.5
- Update excoveralls 0.5.7 -> 0.13
- Update earmark 1.0.3 -> 1.4
- Update ex_doc 0.14.3 -> 0.20
- [FEATURE] Add `SparkPost.Template.create/1`
- [FEATURE] Add `SparkPost.Template.update/2`
- [FEATURE] Add `SparkPost.Template.delete/1`

## v0.5.2 (2018-05-14)
- Bumped httpoison dep to ~1.0 (thanks @jasongoodwin)

Expand All @@ -22,7 +51,7 @@
- Bumped default connection timeout to 30 secs

## v0.2.1 (2016/11/03)
- Added support for `start_time`, `ip_pool` and `inline_css` transmission options
- Added support for `start_time`, `ip_pool` and `inline_css` transmission options
- Updated deps to latest versions

## v0.2.0 (2016/08/25)
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

# SparkPost Elixir Library

[![Travis CI](https://travis-ci.org/SparkPost/elixir-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/elixir-sparkpost) [![Coverage Status](https://coveralls.io/repos/SparkPost/elixir-sparkpost/badge.svg?branch=master&service=github)](https://coveralls.io/github/SparkPost/elixir-sparkpost?branch=master) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com)

The official [Elixir](http://elixir-lang.org/) package for the [SparkPost API](https://www.sparkpost.com/api).

Capabilities include:
Expand Down Expand Up @@ -67,13 +65,13 @@ end
```elixir
defmodule MyApp.Example do
alias SparkPost.{Content, Recipient, Transmission}

def send_message do
Transmission.send(%Transmission{
recipients: [ "you@example.com" ],
content: %Content.Inline{
subject: "Sending email from Elixir is awesome!",
from: "elixir@sparkpostbox.com",
from: "elixir@sparkpostbox.com",
text: "Hi there!",
html: "<p>Hi there!</p>"
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

config :sparkpost,
api_endpoint: "https://api.sparkpost.com/api/v1/",
Expand Down
2 changes: 1 addition & 1 deletion examples/simplesend.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from = "Elixir SparkPost <elixir@sparkpostbox.com>"
SparkPost.send(
to: to,
from: from,
subject: "My first Elixir email",
subject: "My first Elixir email",
text: "This is the boring version of the email body",
html: "This is the <strong>tasty</strong> <em>rich</em> version of the <a href=\"https://www.sparkpost.com/\">email</a> body."
)
19 changes: 11 additions & 8 deletions lib/address.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ defmodule SparkPost.Address do
- `%{name: ..., email: ...}`
"""
def to_address(email) when is_binary(email) do
parse_address(email)
parse_address(email)
end

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

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

defp parse_address(addr) when is_binary(addr) do
case Regex.run(~r/\s*(.+)\s+<(.+@.+)>\s*$/, addr) do
[_, name, email] -> %__MODULE__{ name: name, email: email }
nil -> case Regex.run(~r/\s*(.+@.+)\s*$/, addr) do
[_, email] -> %__MODULE__{ email: email }
nil -> raise __MODULE__.FormatError, message: "Invalid email address: #{addr}"
end
[_, name, email] ->
%__MODULE__{name: name, email: email}

nil ->
case Regex.run(~r/\s*(.+@.+)\s*$/, addr) do
[_, email] -> %__MODULE__{email: email}
nil -> raise __MODULE__.FormatError, message: "Invalid email address: #{addr}"
end
end
end
end
6 changes: 2 additions & 4 deletions lib/content.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ defmodule SparkPost.Content do
end

def to_content(%SparkPost.Content.Inline{} = content) do
%{ content |
from: SparkPost.Address.to_address(content.from)}
%{content | from: SparkPost.Address.to_address(content.from)}
end

def to_content(content) when is_map(content) do
%{ struct(SparkPost.Content.Inline, content) |
from: SparkPost.Address.to_address(content.from)}
%{struct(SparkPost.Content.Inline, content) | from: SparkPost.Address.to_address(content.from)}
end
end
15 changes: 8 additions & 7 deletions lib/content/inline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ defmodule SparkPost.Content.Inline do
"""

defstruct from: :required,
reply_to: nil,
headers: nil,
subject: :required,
text: nil,
html: nil,
attachments: nil,
inline_images: nil
reply_to: nil,
headers: nil,
subject: :required,
text: nil,
html: nil,
attachments: nil,
inline_images: nil

@doc """
Convert a raw "from" field into a %SparkPost.Address{} object.
"""
def convert_from_field(%SparkPost.Endpoint.Error{} = content), do: content

def convert_from_field(%__MODULE__{} = content) do
%{content | from: SparkPost.Address.to_address(content.from)}
end
Expand Down
Loading