-
Notifications
You must be signed in to change notification settings - Fork 0
/
multifollow.rb
87 lines (74 loc) · 1.89 KB
/
multifollow.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
require 'rubygems'
require 'sinatra'
require "twitter"
require 'erb'
get '/' do
erb :multifollow
end
get '/terms' do
erb :terms
end
get '/about' do
erb :about
end
get '/find/:name' do
user = Twitter.user( params[ :name ] )
if user.has_key?( 'name' )
list_followed_twitters( params[ :name ] )
else
erb "false"
end
end
get '/:id' do
@user = Twitter.user( params[ :id ] )
if @user.has_key?( 'name' )
erb :user
else
erb "false"
end
end
post '/login' do
client = login( params[ :name ], params[ :password ] )
begin
@client_data = client.verify_credentials
erb :client_data
rescue StandardError
erb "false"
end
end
put '/' do
client = login( params[ :name ], params[ :password ] )
params[ :requested_follow_ids ].split( ',' ).each do | request_id |
if !( client.friendship_exists?( params[ :name ], request_id ) )
client.friendship_create( request_id, true )
end
end
erb "Follow requests sucessfully completed."
end
def login( name, login )
httpauth = Twitter::HTTPAuth.new( name, login )
Twitter::Base.new( httpauth )
end
def list_followed_twitters( user )
@users_list = Array.new
Twitter.friend_ids( user ).each do | friend |
@users_list << friend
end
erb :users_list
end
get '/js/multifollow.js' do
headers 'Content-Type' => 'text/javascript; charset=utf-8'
File.read( File.join( File.dirname( __FILE__ ), 'js', 'multifollow.js' ) )
end
get '/js/jquery-1.3.2.min.js' do
headers 'Content-Type' => 'text/javascript; charset=utf-8'
File.read( File.join( File.dirname( __FILE__ ), 'js', 'jquery-1.3.2.min.js' ) )
end
get '/css/multifollow.css' do
headers 'Content-Type' => 'text/css; charset=utf-8'
File.read(File.join(File.dirname(__FILE__), 'css', 'multifollow.css' ) )
end
get '/img/loader.gif' do
headers 'Content-Type' => 'image/jpeg;'
File.read(File.join(File.dirname(__FILE__), 'img', 'loader.gif' ) )
end