-
Notifications
You must be signed in to change notification settings - Fork 333
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
Add support for Sendgrid unique arguments #609
Changes from all commits
8d9385a
9b07ce1
c5c1b5c
052f15a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ defmodule Bamboo.SendGridHelper do | |
@allowed_google_analytics_utm_params ~w(utm_source utm_medium utm_campaign utm_term utm_content)a | ||
@send_at_field :sendgrid_send_at | ||
@ip_pool_name_field :ip_pool_name | ||
@unique_args :unique_args | ||
|
||
@doc """ | ||
Specify the template for SendGrid to use for the context of the substitution | ||
|
@@ -294,4 +295,25 @@ defmodule Bamboo.SendGridHelper do | |
|> Email.put_private(@ip_pool_name_field, ip_pool_name) | ||
end | ||
|
||
@doc """ | ||
A map of unique arguments for this email. This will override any existing unique arguments. | ||
|
||
## Example | ||
|
||
|> with_unique_args(%{new_arg_1: "new arg 1", new_arg_2: "new arg 2"}) | ||
""" | ||
def with_unique_args(email, unique_args) when is_map(unique_args) do | ||
unique_args = | ||
Map.get(email.private, @unique_args, %{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's my new implementation using
I pattern match and only retrieve the value since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you think |
||
|> Map.merge(unique_args) | ||
|
||
|> Email.put_private(@unique_args, unique_args) | ||
end | ||
|
||
def with_unique_args(_email, _unique_args) do | ||
raise "expected a map of unique arguments" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this function. Could you add a test to ensure this behaves as expected? I know we tested the
with_unique_args
function in the helper, but it would be nice to test this one too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeepers3327 whenever you have time, if we add a test for this, I think the PR is good to go. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@germsvel I've added a test case for
send_grid_adapter
. Let me know if I need to a add more tests.