Skip to content

Instantly share code, notes, and snippets.

@vanpelt
Created December 8, 2011 23:01
Show Gist options
  • Save vanpelt/1449115 to your computer and use it in GitHub Desktop.
Save vanpelt/1449115 to your computer and use it in GitHub Desktop.
sample crowdflower webhook endpoint
require './webhook'
run Sinatra::Application
source :rubygems
gem "sinatra"
gem "json"
#To test, run the following to ensure the puts statements are being logged
heroku config:add LOG_LEVEL=DEBUG
heroku logs
#Then hit the following url to test the webhook directly (replace your webhook and job_id):
https://crowdflower.com/jobs/67977/webhook?job[webhook_uri]=http://furious-dusk-7697.heroku.com/endpoint
require 'rubygems'
require 'sinatra'
require 'json'
post "/endpoint" do
success = true
if params[:signal] == "unit_complete"
payload = JSON.parse(params[:payload])
puts payload["results"].inspect
#answer = payload["results"]["name_of_field"]["agg"]
#do something with answer
end
success ? 200 : 500
end
@ialex
Copy link

ialex commented Nov 21, 2013

Great i was looking for the actual response you crowdflowder sends but this helps, in their docs they dont show how the results json look like they just show array below, it seems that they have changed the json format.
{
"results": {
"judgments": []
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment