This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
138 lines (111 loc) · 3.47 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'sinatra'
require 'sinatra/activerecord'
require './environments'
require 'json'
require 'omniauth'
require 'omniauth-twitter'
require 'twitter'
class Result < ActiveRecord::Base
end
configure do
set :sessions, true
set :inline_templates, true
end
use OmniAuth::Builder do
provider :twitter, $twitter_consumer_key, $twitter_consumer_secret
end
client = Twitter::REST::Client.new do |config|
config.consumer_key = $twitter_consumer_key
config.consumer_secret = $twitter_consumer_secret
config.access_token = $twitter_access_token
config.access_token_secret = $twitter_access_token_secret
end
get '/' do
@title = "Meet Your Maker"
erb :index
end
post '/results' do
load 'lib/death_calc.rb'
@title = "Death Results"
puts params
@name = params[:name]
@gender = params[:gender]
@current_age = params[:current_age]
@location = params[:location]
@diet = params[:diet]
@outlook = params[:outlook]
@sleep = params[:sleep]
@handed = params[:handed]
@sport_vid = params[:sport_vid]
@beer_liq = params[:beer_liq]
@rep_dem = params[:rep_dem]
@dirty_rainey = params[:dirty_rainey]
@sega_nin = params[:sega_nin]
@ruby_js = params[:ruby_js]
@death_age = 90
calc_death_age
@result = Result.create(name: @name, gender: @gender, current_age: @current_age,
location: @location, diet: @diet, outlook: @outlook, sleep: @sleep,
handed: @handed, sport_vid: @sport_vid, beer_liq: @beer_liq,
rep_dem: @rep_dem, dirty_rainey: @dirty_rainey, sega_nin: @sega_nin,
ruby_js: @ruby_js, death_age: @death_age)
@results = Result.order("created_at DESC")
@new_result = @results[0]
erb :results
end
get '/results' do
@results = Result.order("created_at DESC")
@title = "Meet Your Maker - Results"
erb :results
end
get '/auth/:provider/callback' do
# response = JSON.pretty_generate(request.env['omniauth.auth'])
response = request.env['omniauth.auth']
puts response['credentials']['token']
$twitter_access_token = response['credentials']['token']
$twitter_access_token_secret = response['credentials']['secret']
puts $twitter_access_token
puts $twitter_access_token_secret
client_new = Twitter::REST::Client.new do |config|
config.consumer_key = $twitter_consumer_key
config.consumer_secret = $twitter_consumer_secret
config.access_token = $twitter_access_token
config.access_token_secret = $twitter_access_token_secret
end
puts client_new
@results = Result.order("created_at DESC").first
if @results
# client_new.update_with_media("I'm gonna die!", File.new("http://imgur.com/75Jr3.jpg"))
client_new.update("I'm going to live to age #{@results.death_age}! When will you Meet Your Maker? http://meetyourmaker.herokuapp.com/ #MKS")
end
# erb "<h1>#{params[:provider]}</h1>
# <pre>#{JSON.pretty_generate(request.env['omniauth.auth'])}</pre>"
redirect '/results'
end
get '/auth/failure' do
erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>"
end
get '/auth/:provider/deauthorized' do
erb "#{params[:provider]} has deauthorized this app."
end
get '/protected' do
throw(:halt, [401, "Not authorized\n"]) unless session[:authenticated]
erb "<pre>#{request.env['omniauth.auth'].to_json}</pre><hr>
<a href='/logout'>Logout</a>"
end
get '/logout' do
session[:authenticated] = false
redirect '/'
end
get '/graph' do
erb :graph
end
helpers do
def title
if @title
"#{@title}"
else
"Welcome."
end
end
end