Skip to content

Instantly share code, notes, and snippets.

@sophiebits
Created July 28, 2011 00:14
Show Gist options
  • Save sophiebits/1110649 to your computer and use it in GitHub Desktop.
Save sophiebits/1110649 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'json'
require 'net/https'
USER = "KhanBugz"
PASS = ""
def gh_http
http = Net::HTTP.new("api.github.com", 443)
http.use_ssl = true
http
end
def gh_post(path, data)
req = Net::HTTP::Post.new(path)
req.basic_auth USER, PASS
req.content_type = "application/json"
req.body = data
gh_http.request req
end
get "/file_exercise_tester_bug" do
issue = {
:title => params[:title],
:body => params[:body],
:labels => [params[:label]],
}
callback = params[:callback].gsub(/[^a-z0-9_-]/i, "")
resp = gh_post("/repos/Khan/khan-exercises/issues?callback=#{callback}", issue.to_json)
status resp.code
content_type "application/javascript"
resp.body
end
get "/file_exercise_tester_bug_comment" do
issue = {
:body => params[:body]
}
id = params[:id].to_i
callback = params[:callback].gsub(/[^a-z0-9_-]/i, "")
resp = gh_post("/repos/Khan/khan-exercises/issues/#{id}/comments?callback=#{callback}", issue.to_json)
status resp.code
content_type "application/javascript"
resp.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment