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

feat: Support multiple duplicate queryparams #134

Conversation

mjjs
Copy link
Contributor

@mjjs mjjs commented Nov 30, 2021

The SendGrid API documentation states that the user can supply up to ten
categories, but there is no way to supply them using the Java library.

This commit fixes the problem by interpreting any value that has an
ampersand in it as a list of values, which will be inserted as multiple
query params.

For example, the call request.addQueryParam("categories", "cat1&cat2")
will output categories=cat1&categories=cat2 into the URL.

I also modified the testbuildUri test a bit because I would have had write
out too many permutations of the resulting URL string because the order
of the query params is not deterministic in the current implementation.

Another solution would be to store the query params in Map<String, String[]>
so we wouldn't need to split the string. Then the user could just call

request.addQueryParam("categories", "cat1");
request.addQueryParam("categories", "cat2");
// Or this if we allow variadic arguments
request.addQueryParam("categories", "cat1", "cat2");

This would, however, change the API of the library, so I didn't go for this route now.

Fixes

A short description of what this PR does.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@mjjs mjjs force-pushed the support-multiple-duplicate-query-params branch from bd8105d to ece8a9d Compare November 30, 2021 22:23
@mjjs mjjs marked this pull request as ready for review November 30, 2021 22:23
@shwetha-manvinkurke
Copy link
Contributor

Could you pull in the latest changes from main?

The SendGrid API documentation states that the user can supply up to ten
categories, but there is no way to supply them using the Java library.

This commit fixes the problem by interpreting any value that has an
ampersand in it as a list of values, which will be inserted as multiple
query params.

For example, the call request.addQueryParam("categories", "cat1&cat2")
will output "?categories=cat1&categories=cat2" into the URL.
@mjjs mjjs force-pushed the support-multiple-duplicate-query-params branch from ece8a9d to 02be68f Compare January 14, 2022 22:11
@mjjs
Copy link
Contributor Author

mjjs commented Jan 14, 2022

Rebased and pushed.

@shwetha-manvinkurke shwetha-manvinkurke changed the title Support multiple duplicate queryparams feat: Support multiple duplicate queryparams Feb 2, 2022
@shwetha-manvinkurke shwetha-manvinkurke merged commit a8d5e4d into sendgrid:main Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants