-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwifakes.rb
46 lines (39 loc) · 1.51 KB
/
twifakes.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
require 'rubygems'
require 'sinatra'
require 'yaml'
require 'twitter_oauth'
require 'sinatra/r18n'
set :default_locale, 'en'
set :translations, './locales'
before do
session[:locale] = params[:locale] unless params[:locale].nil?
set :locale, session[:locale]
end
configure do
enable :sessions
end
get "/" do
erb :index
end
get "/connect" do
client = TwitterOAuth::Client.new(:consumer_key => ENV["CONSUMER_KEY"], :consumer_secret => ENV["CONSUMER_SECRET"])
request_token = client.request_token(:oauth_callback => ENV["CALLBACK_URL"])
session[:request_token] = request_token.token
session[:request_token_secret] = request_token.secret
redirect request_token.authorize_url
end
get "/oauth" do
session[:oauth_verifier] = params[:oauth_verifier]
client = TwitterOAuth::Client.new(:consumer_key => ENV["CONSUMER_KEY"], :consumer_secret => ENV["CONSUMER_SECRET"])
session[:access_token] = client.authorize(session[:request_token], session[:request_token_secret], :oauth_verifier => session[:oauth_verifier])
@fakes = (client.info["followers_count"].to_i/12).to_i
erb :show
end
get "/tweet" do
client = TwitterOAuth::Client.new(:consumer_key => ENV["CONSUMER_KEY"], :consumer_secret => ENV["CONSUMER_SECRET"])
session[:access_token] = client.authorize(session[:request_token], session[:request_token_secret], :oauth_verifier => session[:oauth_verifier])
@fakes = (client.info["followers_count"].to_i/12).to_i
status = t.message(@fakes)
client.update(status) if client.authorized?
redirect "/?s=ok"
end