Created
December 8, 2011 23:01
-
-
Save vanpelt/1449115 to your computer and use it in GitHub Desktop.
sample crowdflower webhook endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './webhook' | |
| run Sinatra::Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source :rubygems | |
| gem "sinatra" | |
| gem "json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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": []
},