You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm experiencing a bug that's preventing my Routes in Mailgun from being created with multiple actions. I'm following the examples straight out of the docs (both the API Reference and the User Manual), but to no avail. When I send the POST request to create the route in Mailgun using the gem's post method, I get a 200 response from Mailgun saying that the route has been created, but the actions that I've specified in the request params aren't showing up in the response's route object. I checked the route in Mailgun's web UI and, sure enough, the actions that I specified in the request weren't saved to the route.
According to the examples in the docs, the action param can be set to an array of actions if you want to configure the route to have multiple actions. I was doing just this, but wasn't having any success. As an example of what I was doing, I was setting the action param to ["forward('[email protected]')", "stop()"]. After having tried various other strategies like including just a single action in the array and using escaped double quotes in the forward() action expression, I decided to dig into the gem's code to get a better idea of what might be going on. After poking around for a bit, I came to the conclusion that it has to do with how rest-client URL encodes array parameters. rest-client URL encodes array parameters using "bracket notation", which is specific to rack/rails applications, but it seems that Mailgun's endpoint expects array params to be flattened.
For example, if the action param is set to ["forward('[email protected]')", "stop()"]:
**[BAD]** `rest-client` URL encodes the array like this using bracket notation:
`action[]=forward%28%27foo%40example.com%27%29&action[]=stop%28%29`
**[GOOD]** but Mailgun's endpoint seemingly expects it to be encoded like this:
`action=forward%28%27foo%40example.com%27%29&action=stop%28%29`
When the action param is encoded like the [GOOD] example, the actions are successfully persisted to the route when the route gets created.
This tricks the rest-client into treating the :action and "action" params as separate params and URL encodes them without the bracket notation, which seems to work with Mailgun's endpoint.
I checked the rest-client gem and it looks like there's a solution for this issue through the use of their custom ParamsArray class. In version 2.1.0 of the rest-client gem, you can pass in a ParamsArray object as the request payload and it removes the bracket notation during the URL encoding process for array params. For example:
It looks like rest-client is pegged at 2.0.2. Updating to 2.1.0 and refactoring the the mailgun-ruby gem's methods to make use of the ParamsArray class would solve this issue.
The text was updated successfully, but these errors were encountered:
BUG OVERVIEW
I'm experiencing a bug that's preventing my Routes in Mailgun from being created with multiple actions. I'm following the examples straight out of the docs (both the API Reference and the User Manual), but to no avail. When I send the POST request to create the route in Mailgun using the gem's
post
method, I get a200
response from Mailgun saying that the route has been created, but the actions that I've specified in the request params aren't showing up in the response'sroute
object. I checked the route in Mailgun's web UI and, sure enough, the actions that I specified in the request weren't saved to the route.According to the examples in the docs, the
action
param can be set to an array of actions if you want to configure the route to have multiple actions. I was doing just this, but wasn't having any success. As an example of what I was doing, I was setting theaction
param to["forward('[email protected]')", "stop()"]
. After having tried various other strategies like including just a single action in the array and using escaped double quotes in theforward()
action expression, I decided to dig into the gem's code to get a better idea of what might be going on. After poking around for a bit, I came to the conclusion that it has to do with howrest-client
URL encodes array parameters.rest-client
URL encodes array parameters using "bracket notation", which is specific to rack/rails applications, but it seems that Mailgun's endpoint expects array params to be flattened.For example, if the
action
param is set to["forward('[email protected]')", "stop()"]
:When the action param is encoded like the [GOOD] example, the actions are successfully persisted to the route when the route gets created.
STEPS TO REPRODUCE
Actual response, but with fake id (note the
"actions"
array is totally empty):SOLUTION
As a workaround, I've been leveraging the ability of ruby hashes to have both symbol and string keys that have the same name. For example:
This tricks the
rest-client
into treating the:action
and"action"
params as separate params and URL encodes them without the bracket notation, which seems to work with Mailgun's endpoint.I checked the
rest-client
gem and it looks like there's a solution for this issue through the use of their customParamsArray
class. In version2.1.0
of therest-client
gem, you can pass in aParamsArray
object as the request payload and it removes the bracket notation during the URL encoding process for array params. For example:encodes the params like so in the request:
It looks like
rest-client
is pegged at2.0.2
. Updating to2.1.0
and refactoring the themailgun-ruby
gem's methods to make use of theParamsArray
class would solve this issue.The text was updated successfully, but these errors were encountered: