-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
116 lines (104 loc) · 3.18 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
require 'rubygems'
require 'bundler'
Bundler.require
configure do
set :twilio_account_sid, ENV['ACCOUNT_SID']
set :twilio_auth_token, ENV['AUTH_TOKEN']
set :twilio_app_sid, ENV['APP_SID']
end
helpers do
include Rack::Utils
alias_method :h, :escape
end
get '/' do
@token=generate_token(params[:name])
@browser=full_browser_name
@browser_compatible= compatible_browser? ? "true" : "false"
@lion=lion?
erb :client_test
end
def generate_token(operator_name)
# generate a Twilio Client token that allows inbound calling. Client name will be <operator_name>.
twilio_capability = Twilio::Util::Capability.new(settings.twilio_account_sid, settings.twilio_auth_token)
twilio_capability.allow_client_outgoing(settings.twilio_app_sid, {})
twilio_token = twilio_capability.generate
end
def lion?
request.env['HTTP_USER_AGENT'].index("OS X 10_7") || request.env['HTTP_USER_AGENT'].index("OS X 10.7")
end
def compatible_browser?
# valid browsers:
# Firefox >= 3.6
# IE 7,8,9
# Safari >= 5
# Chrome >= 11
begin
return true if browser_name=="firefox" && browser_version.to_f>=3.6
return true if browser_name.index("ie") && browser_version.to_f>=7
return true if browser_name=="safari" && browser_version.to_f>=5
return true if browser_name=="chrome" && browser_version.to_f>=11
rescue
return false
end
end
def full_browser_name
browser_name + ' ' + browser_version
end
def browser_version
version=''
result = request.env['HTTP_USER_AGENT'] || ""
if result =~ /CriOS/
version = result.split('CriOS/')[1].split(' ').first#.split('.').first
elsif result =~ /Safari/
unless result =~ /Chrome/
version = result.split('Version/')[1].split(' ').first#.split('.').first
else
version = result.split('Chrome/')[1].split(' ').first#.split('.').first
end
elsif result =~ /Firefox/
version = result.split('Firefox/')[1]#.split('.').first
elsif result =~ /Opera/
version = result.split('Version/')[1]#.split('.').first
elsif result =~ /MSIE/
version = result.split('MSIE')[1].split(' ').first.split(";").first
end
return version
end
def browser_name
user_agent = request.env['HTTP_USER_AGENT'].downcase
@users_browser ||= begin
if user_agent.index('msie') && !user_agent.index('opera') && !user_agent.index('webtv')
'ie'+user_agent[user_agent.index('msie')+5].chr
elsif user_agent.index('firefox/')
'firefox'
elsif user_agent.index('gecko/')
'gecko'
elsif user_agent.index('opera')
'opera'
elsif user_agent.index('konqueror')
'konqueror'
elsif user_agent.index('ipod')
'ipod'
elsif user_agent.index('ipad')
'ipad'
elsif user_agent.index('iphone')
'iphone'
elsif user_agent.index('chrome/')
'chrome'
elsif user_agent.index('applewebkit/')
'safari'
elsif user_agent.index('googlebot/')
'googlebot'
elsif user_agent.index('msnbot')
'msnbot'
elsif user_agent.index('yahoo! slurp')
'yahoobot'
#Everything thinks it's mozilla, so this goes last
elsif user_agent.index('mozilla/')
'gecko'
else
'unknown'
end
end
return @users_browser
end