Class: ProblemChild::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- ProblemChild::App
- Defined in:
- lib/problem_child.rb
Instance Method Summary collapse
- #anonymous_submissions? ⇒ Boolean
- #auth! ⇒ Object
- #client ⇒ Object
- #create_issue(data = params) ⇒ Object
-
#form_data ⇒ Object
abstraction to allow cached form data to be used in place of default params.
- #issue_body ⇒ Object
- #render_template(template, locals = {}) ⇒ Object
- #repo ⇒ Object
- #token ⇒ Object
- #user ⇒ Object
Instance Method Details
#anonymous_submissions? ⇒ Boolean
58 59 60 |
# File 'lib/problem_child.rb', line 58 def anonymous_submissions? ENV["GITHUB_TOKEN"] && !ENV["GITHUB_TOKEN"].empty? end |
#auth! ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/problem_child.rb', line 91 def auth! if anonymous_submissions? true elsif ENV['GITHUB_TEAM_ID'] github_team_authenticate!(ENV['GITHUB_TEAM_ID']) elsif ENV['GITHUB_ORG_ID'] github_organization_authenticate!(ENV['GITHUB_ORG_ID']) else raise "Must define GITHUB_TEAM_ID, GITHUB_ORG_ID, OR GITHUB_TOKEN" halt 401 end end |
#client ⇒ Object
70 71 72 |
# File 'lib/problem_child.rb', line 70 def client @client ||= Octokit::Client.new :access_token => token end |
#create_issue(data = params) ⇒ Object
87 88 89 |
# File 'lib/problem_child.rb', line 87 def create_issue(data=params) client.create_issue(repo, form_data["title"], issue_body) end |
#form_data ⇒ Object
abstraction to allow cached form data to be used in place of default params
83 84 85 |
# File 'lib/problem_child.rb', line 83 def form_data session["form_data"].nil? ? params : JSON.parse(session["form_data"]) end |
#issue_body ⇒ Object
78 79 80 |
# File 'lib/problem_child.rb', line 78 def issue_body form_data.reject { |key, value| key == "title" }.map { |key,value| "* **#{key.humanize}**: #{value}"}.join("\n") end |
#render_template(template, locals = {}) ⇒ Object
74 75 76 |
# File 'lib/problem_child.rb', line 74 def render_template(template, locals={}) halt erb template, :layout => :layout, :locals => locals.merge({ :template => template }) end |
#repo ⇒ Object
50 51 52 |
# File 'lib/problem_child.rb', line 50 def repo ENV["GITHUB_REPO"] end |
#token ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/problem_child.rb', line 62 def token if anonymous_submissions? ENV["GITHUB_TOKEN"] elsif !user.nil? user.token end end |
#user ⇒ Object
54 55 56 |
# File 'lib/problem_child.rb', line 54 def user env['warden'].user unless env['warden'].nil? end |