Reputation: 3665
I'm trying to up receive updates on my Trello model when a change occurs, which I'm using their webhooks for. The problem is that one of the parameter's name is "action", which seems to be overwritten by Rails depending on the value in the Routes.rb. Is there any way to avoid this or do I just have to live with it?
Routes.rb
match "/trello" => "trello_updates#index", via: [:get,:post]
Webhook reponse
Parameters: {"model"=>{...},"action"=>"index"}
Upvotes: 2
Views: 240
Reputation: 3665
I had to modify the code from Vishnu, which is the accepted answer to make it work with a post request, so if you have a post request, you need to fetch the params out from the body of the response instead:
class TrelloWebhooks
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
body = JSON.parse(request.body.string)
trello_action = body["action"]
request.update_param('trello_action', trello_action)
status, headers, response = @app.call(env)
[status, headers, response]
end
end
Rails.application.config.middleware.use 'TrelloWebhooks'
Upvotes: 1
Reputation: 2368
You can write a middleware in initializers and update the params coming from trello webhooks. like below -
class TrelloWebhooks
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
trello_action = request.params['action']
request.update_param('trello_action', trello_action)
status, headers, response = @app.call(env)
[status, headers, response]
end
end
Rails.application.config.middleware.use 'TrelloWebhooks'
Upvotes: 2