-
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
Add support for Sendgrid unique arguments #609
Conversation
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.
Hi @jeepers3327 thanks for opening this PR.
I see that you added the with_unique_args/2
function to the SendGridHelper
that puts the args under the private map. That's one side of the equation.
For this to work, we also need to grab those unique args and put them in the correct place when sending the email. For example, with categories, we put them in the email's body in https://github.com/thoughtbot/bamboo/blob/6aa74c3ff16604aeba853c34cd525c6b7f46b33f/lib/bamboo/adapters/send_grid_adapter.ex#L126 which calls https://github.com/thoughtbot/bamboo/blob/6aa74c3ff16604aeba853c34cd525c6b7f46b33f/lib/bamboo/adapters/send_grid_adapter.ex#L305-L311
Do you mind including that in this PR?
Apologies, I only thought of the SendgridHelper module. I've added Thank you. |
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.
Looking good. Two really minor comments. I think once those are done we can merge this in.
""" | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using Map.update/4
here instead of getting the values and then updating them? I think it reveals intention slightly more clearly.
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.
Here's my new implementation using Map.update
%{unique_args: unique_args} =
Map.update(
email.private,
@unique_args,
unique_args,
&Map.merge(&1, unique_args)
)
email
|> Email.put_private(@unique_args, unique_args)
I pattern match and only retrieve the value since Map.update/4
also returns the map key. I think its not good, can I ask for your suggestion for improvement?
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.
If you think Map.update/4
makes it more confusing. I'm okay leaving things as they are. No need to change this. Thanks for looking into it!
@@ -440,4 +441,12 @@ defmodule Bamboo.SendGridAdapter do | |||
do: Map.put(body, :ip_pool_name, ip_pool_name) | |||
|
|||
defp put_ip_pool_name(body, _), do: body | |||
|
|||
defp put_unique_args(body, %Email{private: %{unique_args: unique_args}}) |
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.
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 all the work! 🎉
This PR add support for Sendgrid unique_arguments (#592 )