Guest User

Untitled

a guest
Aug 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. require 'sinatra'
  2. require 'json'
  3. require 'net/https'
  4.  
  5. USER = "KhanBugz"
  6. PASS = ""
  7.  
  8. def gh_http
  9. http = Net::HTTP.new("api.github.com", 443)
  10. http.use_ssl = true
  11. http
  12. end
  13.  
  14. def gh_post(path, data)
  15. req = Net::HTTP::Post.new(path)
  16. req.basic_auth USER, PASS
  17. req.content_type = "application/json"
  18. req.body = data
  19.  
  20. gh_http.request req
  21. end
  22.  
  23. get "/file_exercise_tester_bug" do
  24. issue = {
  25. :title => params[:title],
  26. :body => params[:body],
  27. :labels => [params[:label]],
  28. }
  29.  
  30. callback = params[:callback].gsub(/[^a-z0-9_-]/i, "")
  31. resp = gh_post("/repos/Khan/khan-exercises/issues?callback=#{callback}", issue.to_json)
  32.  
  33. status resp.code
  34. content_type "application/javascript"
  35. resp.body
  36. end
  37.  
  38. get "/file_exercise_tester_bug_comment" do
  39. issue = {
  40. :body => params[:body]
  41. }
  42.  
  43. id = params[:id].to_i
  44. callback = params[:callback].gsub(/[^a-z0-9_-]/i, "")
  45. resp = gh_post("/repos/Khan/khan-exercises/issues/#{id}/comments?callback=#{callback}", issue.to_json)
  46.  
  47. status resp.code
  48. content_type "application/javascript"
  49. resp.body
  50. end
Add Comment
Please, Sign In to add comment