Skip to content
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

Merged

Conversation

jeepers3327
Copy link
Contributor

This PR add support for Sendgrid unique_arguments (#592 )

Copy link
Collaborator

@germsvel germsvel left a 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?

@jeepers3327
Copy link
Contributor Author

Apologies, I only thought of the SendgridHelper module.

I've added with_unique_args to SendgridAdapter module. Please kindly review.

Thank you.

Copy link
Collaborator

@germsvel germsvel left a 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, %{})
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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}})
Copy link
Collaborator

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.

Copy link
Collaborator

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. 👍

Copy link
Contributor Author

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.

Copy link
Collaborator

@germsvel germsvel left a 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! 🎉

@germsvel germsvel merged commit 2fe49ad into beam-community:master Jun 11, 2021
@jeepers3327 jeepers3327 deleted the add-unique-arguments-support branch June 11, 2021 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants