kiranmeduri-rmbd 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kiran Meduri
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = rmbd Ruby Mobile Device Detector
2
+
3
+ Library to detect the browser and get detailed information about the browser's capabilities. This is usefull to handle small-screen, mobile devices in a better way
4
+
5
+ = Usage
6
+
7
+ gem sources -a http://gems.github.com
8
+ sudo gem install kiranmeduri-rmbd
9
+
10
+ Then load the gem in your app, in rails add config.gem in environment.rb
11
+
12
+ Now you can get the device/browser information in a controller as below
13
+ class SampleController < ApplicationController
14
+ def index
15
+ device_config = DeviceConfigDetector.detect_capabilities_for_request(request);
16
+ logger.debug("device config = #{device_config.inspect}")
17
+ end
18
+ end
19
+
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2009 Kiran Meduri. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rmbd"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "meduri@gmail.com"
10
+ gem.homepage = "http://github.com/kiranmeduri/rmbd"
11
+ gem.authors = ["Kiran Meduri"]
12
+
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "rmbd #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 0
4
+ :major: 0
data/lib/rmbd.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rmbd/browser_constants'
2
+ require 'rmbd/device_config'
3
+ require 'rmbd/device_config_detector'
@@ -0,0 +1,148 @@
1
+ class BrowserConstants
2
+ UNKNOWN = "unknown"
3
+
4
+ MIME_ANY = "*/*"
5
+ MIME_HTML = "text/html"
6
+ MIME_WML = "text/vnd.wap.wml"
7
+ MIME_WMLSCRIPT = "text/vnd.wap.wmlscript"
8
+ MIME_XHTML = "application/xhtml+xml"
9
+ MIME_XHTML_MP = "application/vnd.wap.xhtml+xml"
10
+ MIME_WBMP = "image/vnd.wap.wbmp"
11
+ MIME_GIF = "image/gif"
12
+ MIME_JPEG = "image/jpeg"
13
+ MIME_BMP = "image/bmp"
14
+ MIME_PNG = "image/png"
15
+ MIME_JAVASCRIPT = "application/x-javascript"
16
+ MIME_PDF = "application/pdf"
17
+ MIME_CSS = "text/css"
18
+
19
+ OS_WINDOWS = "Windows"
20
+ OS_PALM_OD = "PalmOS"
21
+ OS_Symbian = "Symbian"
22
+ OS_WIN_CE = "Windows CE"
23
+
24
+ DEVICE_SMARTPHONE = "Smartphone"
25
+ DEVICE_CELLPHONE_1 = "CellPhone"
26
+ DEVICE_CELLPHONE_2 = "Cellphone"
27
+ PLATFORM_MMP = "MMP"
28
+
29
+ TOOL_REGKING = "RegKing"
30
+
31
+ BROWSER_IE = "MSIE"
32
+ BROWSER_FIREFOX = "Firefox"
33
+ BROWSER_OPERA = "Opera"
34
+ BROWSER_OPERA_NINTEDO = "Nintendo"
35
+ BROWSER_OPERA_NITRO = "Nitro"
36
+ BROWSER_OPENWAVE = "OPWV"
37
+ BROWSER_UP = "UP.Browser"
38
+ BROWSER_UP_LINK = "UP.Link"
39
+ BROWSER_NOKIAMOBILE = "Nokia Mobile Browser"
40
+ BROWSER_NOKIA = "Nokia"
41
+ BROWSER_NOKIA_MAEMO = "Maemo"
42
+ BROWSER_MOZILLA = "Mozilla"
43
+ BROWSER_AVANTGO = "AvantGo"
44
+ BROWSER_DOCOMO = "DoCoMo"
45
+ BROWSER_KDDI = "KDDI"
46
+ BROWSER_EUDORAWEB = "EudoraWeb"
47
+ BROWSER_IPHONE = "iPhone"
48
+ BROWSER_IPAQ = "iPAQ"
49
+ BROWSER_PPC = "PPC"
50
+ BROWSER_NEC_PORTALMMM = "portalmmm"
51
+ BROWSER_SAFARI = "Safari"
52
+ BROWSER_TABLET = "Tablet browser"
53
+ BROWSER_O2 = "O2"
54
+ BROWSER_SPV = "SPV"
55
+ BROWSER_BLAZER = "Blazer"
56
+ BROWSER_PSION = "EPOC"
57
+ BROWSER_AMAYA = "amaya"
58
+ BROWSER_AMIGA_VOYAGER = "AmigaVoyager"
59
+ BROWSER_AMIGA_AWEB = "Amiga-AWeb"
60
+ BROWSER_BLUEFISH = "bluefish"
61
+ BROWSER_BROWSEX = "BrowseX"
62
+ BROWSER_CAMINO = "Camino"
63
+ BROWSER_CHARON = "Charon"
64
+ BROWSER_CHIMERA = "Chimera"
65
+ BROWSER_CURL = "curl"
66
+ BROWSER_DEMOCRACY = "Democracy"
67
+ BROWSER_DILLO = "Dillo"
68
+ BROWSER_OBIGO = "Obigo"
69
+ BROWSER_KBROWSER = "KBrowser"
70
+ BROWSER_CCWAP = "ccWAP-Browser"
71
+ BROWSER_EZWAP = "EzWAP"
72
+ BROWSER_JBROWSER = "jBrowser"
73
+
74
+ BROWSER_MOBILE_UNSORTED_PROXNET = "ProxiNet"
75
+ BROWSER_MOBILE_UNSORTED_ELAINE = "Elaine"
76
+ BROWSER_MOBILE_UNSORTED_PLUCKER = "Plucker"
77
+
78
+ MANUFACTURER_FIREFOX = "Mozilla"
79
+ MANUFACTURER_NOKIA = "Nokia"
80
+ MANUFACTURER_OPENWAVE = "OPWV"
81
+ MANUFACTURER_ALCATEL = "Alcatel"
82
+ MANUFACTURER_ERICSSON = "Ericsson"
83
+ MANUFACTURER_SONY_ERICSSON = "SonyEricsson"
84
+ MANUFACTURER_MOTOROLA = "MOT"
85
+ MANUFACTURER_PANASONIC = "Panasonic"
86
+ MANUFACTURER_PHILIPS = "PHILIPS"
87
+ MANUFACTURER_SHARP = "SHARP"
88
+ MANUFACTURER_SAMSUNG_1 = "SAMSUNG"
89
+ MANUFACTURER_SAMSUNG_2 = "SCH-"
90
+ MANUFACTURER_SAMSUNG_3 = "SEC-"
91
+ MANUFACTURER_SANYO = "Sanyo"
92
+ MANUFACTURER_SIEMENS_1 = "SIEMENS"
93
+ MANUFACTURER_SIEMENS_2 = "SIE-"
94
+ MANUFACTURER_SONY = "Sony"
95
+ MANUFACTURER_SONY_PLAYSTATION = "PLAYSTATION"
96
+ MANUFACTURER_MICROSOFT = "Microsoft"
97
+ MANUFACTURER_RIM_1 = "BlackBerry"
98
+ MANUFACTURER_RIM_2 = "RIM"
99
+ MANUFACTURER_ARIMA = "Arima"
100
+ MANUFACTURER_CECT = "CECT"
101
+ MANUFACTURER_COMPAL = "Compal"
102
+ MANUFACTURER_CTL = "CTL"
103
+ MANUFACTURER_LG = "LG"
104
+ MANUFACTURER_LG_2 = "LG-"
105
+ MANUFACTURER_TCL = "TCL"
106
+ MANUFACTURER_TDG = "TDG"
107
+ MANUFACTURER_BIRD = "BIRD"
108
+ MANUFACTURER_BIRD_2 = "Bird"
109
+ MANUFACTURER_DAXIAN = "DAXIAN"
110
+ MANUFACTURER_DAXIAN_2 = "Daxian"
111
+ MANUFACTURER_DBTEL = "DBTEL"
112
+ MANUFACTURER_EASTCOM = "EASTCOM"
113
+ MANUFACTURER_EASTCOM_2 = "Eastcom"
114
+ MANUFACTURER_PANTECH = "PANTECH"
115
+ MANUFACTURER_DOPOD = "Dopod"
116
+ MANUFACTURER_MITSUBISHI = "Mitsu"
117
+ MANUFACTURER_NTT = "NTT"
118
+ MANUFACTURER_EZWEB = "EzWeb/KDDI"
119
+ MANUFACTURER_VODAFONE_1 = "Vodafone"
120
+ MANUFACTURER_VODAFONE_2 = "J-PHONE"
121
+ MANUFACTURER_PALM = "Palm"
122
+ MANUFACTURER_APPLE = "Apple"
123
+ MANUFACTURER_HP = "HP"
124
+ MANUFACTURER_NEC = "NEC"
125
+ MANUFACTURER_HTC = "HTC Corp."
126
+ MANUFACTURER_TREO = "Treo"
127
+ MANUFACTURER_PSION = "PSION"
128
+ MANUFACTURER_HAIER = "HAIER"
129
+ MANUFACTURER_HAIER_2 = "Haier"
130
+ MANUFACTURER_KONKA = "KONKA"
131
+ MANUFACTURER_KEJIAN = "KEJIAN"
132
+ MANUFACTURER_KEJIAN_2 = "kejian"
133
+ MANUFACTURER_LENOVO = "LENOVO"
134
+ MANUFACTURER_4THPASS = "4thpass"
135
+ MANUFACTURER_ACER = "ACER"
136
+ MANUFACTURER_CHECKCOM = "CheckCom"
137
+ MANUFACTURER_EZOS = "EZOS"
138
+ MANUFACTURER_JATAAYU = "Jataayu"
139
+ MANUFACTURER_SAGEM = "SAGEM"
140
+
141
+ SEARCH_ENGINE_YAHOO_ID = "Yahoo!"
142
+ SEARCH_ENGINE_YAHOO_NAME = "Yahoo"
143
+ SEARCH_ENGINE_BAIDU_ID = "Baiduspider+"
144
+ SEARCH_ENGINE_BAIDU_NAME = "Baidu"
145
+ SEARCH_ENGINE_GOOGLE_ID = "Googlebot"
146
+ SEARCH_ENGINE_GOOGLE_NAME = "Google"
147
+
148
+ end
@@ -0,0 +1,12 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ class DeviceConfig
7
+ attr_accessor :accept, :user_agent, :accept_language, :accept_charset, :midp, :cldc,
8
+ :supported_WML, :supported_HTML, :supported_XHTML, :supported_XHTMLMP,
9
+ :supported_GIF, :supported_WBMP, :supported_JPEG, :supported_PNG,
10
+ :supported_CSS, :supported_JavaScript, :supported_PDF,
11
+ :browser, :manufacturer, :languages, :mobile_browser
12
+ end
@@ -0,0 +1,678 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ class DeviceConfigDetector
7
+ USER_AGENT_LIMIT = 200
8
+ ACCEPT_LIMIT = 1200
9
+ ACCEPT_CHARSET_LIMIT = 200
10
+ ACCEPT_LANGUAGE_LIMIT = 1200
11
+
12
+ def self.detect_capabilities_for_request(request)
13
+ return detect_capabilities(request.user_agent, request.accept, request.accept_charset, request.accept_language)
14
+ end
15
+
16
+ def self.detect_capabilities(user_agent, accept, accept_charset, accept_language)
17
+ if (!user_agent)
18
+ user_agent = ""
19
+ end
20
+
21
+ if (user_agent.length() > USER_AGENT_LIMIT)
22
+ user_agent = user_agent.substring(0, USER_AGENT_LIMIT)
23
+ end
24
+
25
+ if (!accept)
26
+ accept = ""
27
+ end
28
+
29
+ if (accept.length() > ACCEPT_LIMIT)
30
+ accept = accept.substring(0, ACCEPT_LIMIT)
31
+ end
32
+
33
+ if (!accept_charset)
34
+ accept_charset = ""
35
+ end
36
+
37
+ if (accept_charset.length() > ACCEPT_CHARSET_LIMIT)
38
+ accept_charset = accept_charset.substring(0, ACCEPT_CHARSET_LIMIT)
39
+ end
40
+
41
+ if (!accept_language)
42
+ accept_language = ""
43
+ end
44
+
45
+ if (accept_language.length() > ACCEPT_LANGUAGE_LIMIT)
46
+ accept_language = accept_language.substring(0, ACCEPT_LANGUAGE_LIMIT)
47
+ end
48
+
49
+ config = DeviceConfig.new
50
+ # Default, non-mobile browser
51
+ config.user_agent = user_agent
52
+ config.accept = accept
53
+ config.accept_charset = accept_charset
54
+ config.accept_language = accept_language
55
+ config.cldc = get_cldc(user_agent)
56
+ config.midp = get_midp(user_agent)
57
+
58
+ config.supported_XHTMLMP = detect_feature_support(accept, BrowserConstants::MIME_XHTML_MP)
59
+ config.supported_HTML = detect_feature_support(accept, BrowserConstants::MIME_HTML)
60
+ config.supported_XHTML= detect_feature_support(accept, BrowserConstants::MIME_XHTML)
61
+ config.supported_WML= detect_feature_support(accept, BrowserConstants::MIME_WML)
62
+ config.supported_WBMP= detect_feature_support(accept, BrowserConstants::MIME_WBMP)
63
+ config.supported_GIF= detect_feature_support(accept, BrowserConstants::MIME_GIF)
64
+ config.supported_JPEG = detect_feature_support(accept, BrowserConstants::MIME_JPEG)
65
+ config.supported_PNG= detect_feature_support(accept, BrowserConstants::MIME_PNG)
66
+ config.supported_PDF= detect_feature_support(accept, BrowserConstants::MIME_PDF)
67
+ config.supported_CSS= detect_feature_support(accept, BrowserConstants::MIME_CSS)
68
+ config.supported_JavaScript= detect_feature_support(accept, BrowserConstants::MIME_JAVASCRIPT)
69
+ config.browser = get_browser_type(user_agent)
70
+ config.languages = get_languages(accept_language)
71
+ config.manufacturer = get_manufacturer(user_agent, config.browser)
72
+ config.mobile_browser = detect_mobile_browser(config)
73
+ config = special_rule_10_accept_all(accept, config)
74
+ config = special_rule_20_manufacturer_of_msie(config)
75
+ config = special_rule_30_manufacturer_of_firefox(config)
76
+ config = special_rule_40_manufacturer_of_blackberry(config)
77
+ config = special_rule_50_iphone(config)
78
+ config = special_rule_60_opera(config)
79
+ config = special_rule_70_playstation(config)
80
+ config = special_rule_100_special_mobile_browsers(config)
81
+ config = special_rule_200_search_engine_robot(config)
82
+ return config
83
+ end
84
+
85
+ def self.detect_feature_support(config, mime)
86
+ accept = config.accept
87
+ return detect_feature_support(accept, mime)
88
+ end
89
+
90
+ def self.detect_feature_support(accept, mime)
91
+ if (accept.include?(mime))
92
+ return true
93
+ else
94
+ return false
95
+ end
96
+ end
97
+
98
+ def self.detect_mobile_browser(config)
99
+ is_mobile_browser = false
100
+ browser_type = config.browser.downcase
101
+ if (config.supported_XHTMLMP)
102
+ is_mobile_browser = true
103
+ elsif (browser_type == BrowserConstants::BROWSER_UP.downcase)
104
+ is_mobile_browser = true
105
+ elsif (browser_type == BrowserConstants::BROWSER_UP_LINK.downcase)
106
+ is_mobile_browser = true
107
+ elsif (browser_type == BrowserConstants::BROWSER_NOKIAMOBILE.downcase)
108
+ is_mobile_browser = true
109
+ elsif (browser_type == BrowserConstants::BROWSER_NOKIA.downcase)
110
+ is_mobile_browser = true
111
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_MOTOROLA.downcase)
112
+ is_mobile_browser = true
113
+ elsif (browser_type == BrowserConstants::BROWSER_OBIGO.downcase)
114
+ is_mobile_browser = true
115
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_SONY_ERICSSON.downcase)
116
+ is_mobile_browser = true
117
+ elsif (config.browser == BrowserConstants::BROWSER_EZWAP.downcase)
118
+ is_mobile_browser = true
119
+ elsif (config.browser == BrowserConstants::BROWSER_JBROWSER.downcase)
120
+ is_mobile_browser = true
121
+ elsif (config.user_agent.include?(BrowserConstants::DEVICE_CELLPHONE_1))
122
+ is_mobile_browser = true
123
+ elsif (config.user_agent.include?(BrowserConstants::DEVICE_CELLPHONE_2))
124
+ is_mobile_browser = true
125
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_SAGEM.downcase)
126
+ is_mobile_browser = true
127
+ end
128
+ return is_mobile_browser
129
+ end
130
+
131
+
132
+ def self.is_language_supported(config, language)
133
+ accept_language = config.accept_language
134
+ return is_language_supported(accept_language, language)
135
+ end
136
+
137
+ def self.is_language_supported(accept_language, language)
138
+ if (accept_language.include?(language))
139
+ return true
140
+ else
141
+ return false
142
+ end
143
+ end
144
+
145
+ def self.get_browser_type(config)
146
+ user_agent = config.user_agent
147
+ return get_browser_type(user_agent)
148
+ end
149
+
150
+ def self.get_manufacturer(config)
151
+ user_agent = config.user_agent
152
+ return get_manufacturer(user_agent, config.browser)
153
+ end
154
+
155
+ def self.get_browser_type(user_agent)
156
+ if (user_agent.include?(BrowserConstants::BROWSER_UP))
157
+ return BrowserConstants::BROWSER_UP
158
+ elsif (user_agent.include?(BrowserConstants::BROWSER_PSION))
159
+ return BrowserConstants::BROWSER_PSION
160
+ elsif (user_agent.include?(BrowserConstants::BROWSER_UP_LINK))
161
+ return BrowserConstants::BROWSER_UP_LINK
162
+ elsif (user_agent.include?(BrowserConstants::BROWSER_NOKIAMOBILE))
163
+ return BrowserConstants::BROWSER_NOKIAMOBILE
164
+ elsif (user_agent.include?(BrowserConstants::BROWSER_OPERA))
165
+ return BrowserConstants::BROWSER_OPERA
166
+ elsif (user_agent.include?(BrowserConstants::BROWSER_O2))
167
+ return BrowserConstants::BROWSER_O2
168
+ elsif (user_agent.include?(BrowserConstants::BROWSER_OBIGO))
169
+ return BrowserConstants::BROWSER_OBIGO
170
+ elsif (user_agent.include?(BrowserConstants::BROWSER_BLAZER))
171
+ return BrowserConstants::BROWSER_BLAZER
172
+ elsif (user_agent.include?(BrowserConstants::BROWSER_FIREFOX))
173
+ return BrowserConstants::BROWSER_FIREFOX
174
+ elsif (user_agent.include?(BrowserConstants::BROWSER_IE))
175
+ return BrowserConstants::BROWSER_IE
176
+ elsif (user_agent.include?(BrowserConstants::BROWSER_AVANTGO))
177
+ return BrowserConstants::BROWSER_AVANTGO
178
+ elsif (user_agent.include?(BrowserConstants::BROWSER_DOCOMO))
179
+ return BrowserConstants::BROWSER_DOCOMO
180
+ elsif (user_agent.include?(BrowserConstants::BROWSER_KDDI))
181
+ return BrowserConstants::BROWSER_KDDI
182
+ elsif (user_agent.include?(BrowserConstants::BROWSER_IPAQ))
183
+ return BrowserConstants::BROWSER_IPAQ
184
+ elsif (user_agent.include?(BrowserConstants::BROWSER_NOKIA))
185
+ return BrowserConstants::BROWSER_NOKIA
186
+ elsif (user_agent.include?(BrowserConstants::BROWSER_SAFARI))
187
+ return BrowserConstants::BROWSER_SAFARI
188
+ elsif (user_agent.include?(BrowserConstants::OS_Symbian))
189
+ return BrowserConstants::OS_Symbian
190
+ elsif (user_agent.include?(BrowserConstants::BROWSER_AMAYA))
191
+ return BrowserConstants::BROWSER_AMAYA
192
+ elsif (user_agent.include?(BrowserConstants::BROWSER_AMIGA_VOYAGER))
193
+ return BrowserConstants::BROWSER_AMIGA_VOYAGER
194
+ elsif (user_agent.include?(BrowserConstants::BROWSER_AMIGA_AWEB))
195
+ return BrowserConstants::BROWSER_AMIGA_AWEB
196
+ elsif (user_agent.include?(BrowserConstants::BROWSER_BLUEFISH))
197
+ return BrowserConstants::BROWSER_BLUEFISH
198
+ elsif (user_agent.include?(BrowserConstants::BROWSER_BROWSEX))
199
+ return BrowserConstants::BROWSER_BROWSEX
200
+ elsif (user_agent.include?(BrowserConstants::BROWSER_CAMINO))
201
+ return BrowserConstants::BROWSER_CAMINO
202
+ elsif (user_agent.include?(BrowserConstants::BROWSER_CHARON))
203
+ return BrowserConstants::BROWSER_CHARON
204
+ elsif (user_agent.include?(BrowserConstants::BROWSER_CHIMERA))
205
+ return BrowserConstants::BROWSER_CHIMERA
206
+ elsif (user_agent.include?(BrowserConstants::BROWSER_CURL))
207
+ return BrowserConstants::BROWSER_CURL
208
+ elsif (user_agent.include?(BrowserConstants::BROWSER_DEMOCRACY))
209
+ return BrowserConstants::BROWSER_DEMOCRACY
210
+ elsif (user_agent.include?(BrowserConstants::BROWSER_DILLO))
211
+ return BrowserConstants::BROWSER_DILLO
212
+ elsif (user_agent.include?(BrowserConstants::BROWSER_MOZILLA))
213
+ return BrowserConstants::BROWSER_MOZILLA
214
+ elsif (user_agent.include?(BrowserConstants::BROWSER_KBROWSER))
215
+ return BrowserConstants::BROWSER_KBROWSER
216
+ elsif (user_agent.include?(BrowserConstants::BROWSER_CCWAP))
217
+ return BrowserConstants::BROWSER_CCWAP
218
+ elsif (user_agent.include?(BrowserConstants::BROWSER_EZWAP))
219
+ return BrowserConstants::BROWSER_EZWAP
220
+ elsif (user_agent.include?(BrowserConstants::BROWSER_JBROWSER))
221
+ return BrowserConstants::BROWSER_JBROWSER
222
+ else
223
+ return BrowserConstants::UNKNOWN
224
+ end
225
+ end
226
+
227
+ def self.get_manufacturer(user_agent, browser_type)
228
+ if (!user_agent)
229
+ return BrowserConstants::UNKNOWN
230
+ end
231
+
232
+ if (user_agent.include?(BrowserConstants::MANUFACTURER_OPENWAVE))
233
+ return BrowserConstants::MANUFACTURER_OPENWAVE
234
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_NOKIA))
235
+ return BrowserConstants::MANUFACTURER_NOKIA
236
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_MOTOROLA))
237
+ return BrowserConstants::MANUFACTURER_MOTOROLA
238
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SIEMENS_2))
239
+ return BrowserConstants::MANUFACTURER_SIEMENS_1
240
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SONY_ERICSSON))
241
+ return BrowserConstants::MANUFACTURER_SONY_ERICSSON
242
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_ERICSSON))
243
+ return BrowserConstants::MANUFACTURER_ERICSSON
244
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SHARP))
245
+ return BrowserConstants::MANUFACTURER_SHARP
246
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SAMSUNG_1))
247
+ return BrowserConstants::MANUFACTURER_SAMSUNG_1
248
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SAMSUNG_2))
249
+ # still use MANUFACTURER_SAMSUNG_1 name
250
+ return BrowserConstants::MANUFACTURER_SAMSUNG_1
251
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SAMSUNG_3))
252
+ # still use MANUFACTURER_SAMSUNG_1 name
253
+ return BrowserConstants::MANUFACTURER_SAMSUNG_1
254
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SONY))
255
+ return BrowserConstants::MANUFACTURER_SONY
256
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SANYO))
257
+ return BrowserConstants::MANUFACTURER_SANYO
258
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_RIM_1))
259
+ return BrowserConstants::MANUFACTURER_RIM_1
260
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_RIM_2))
261
+ return BrowserConstants::MANUFACTURER_RIM_2
262
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_VODAFONE_1))
263
+ return BrowserConstants::MANUFACTURER_VODAFONE_1
264
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_VODAFONE_2))
265
+ # still use MANUFACTURER_VODAFONE_1 name
266
+ return BrowserConstants::MANUFACTURER_VODAFONE_1
267
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_ALCATEL))
268
+ return BrowserConstants::MANUFACTURER_ALCATEL
269
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_MICROSOFT))
270
+ return BrowserConstants::MANUFACTURER_MICROSOFT
271
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_MITSUBISHI))
272
+ return BrowserConstants::MANUFACTURER_MITSUBISHI
273
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_PANASONIC))
274
+ return BrowserConstants::MANUFACTURER_PANASONIC
275
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_PHILIPS))
276
+ return BrowserConstants::MANUFACTURER_PHILIPS
277
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_PALM))
278
+ return BrowserConstants::MANUFACTURER_PALM
279
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_LG_2))
280
+ return BrowserConstants::MANUFACTURER_LG
281
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_ARIMA))
282
+ return BrowserConstants::MANUFACTURER_ARIMA
283
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_CECT))
284
+ return BrowserConstants::MANUFACTURER_CECT
285
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_COMPAL))
286
+ return BrowserConstants::MANUFACTURER_COMPAL
287
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_CTL))
288
+ return BrowserConstants::MANUFACTURER_CTL
289
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_TCL))
290
+ return BrowserConstants::MANUFACTURER_TCL
291
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_TDG))
292
+ return BrowserConstants::MANUFACTURER_TDG
293
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_BIRD))
294
+ return BrowserConstants::MANUFACTURER_BIRD
295
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_BIRD_2))
296
+ return BrowserConstants::MANUFACTURER_BIRD_2
297
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_DAXIAN))
298
+ return BrowserConstants::MANUFACTURER_DAXIAN
299
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_DAXIAN_2))
300
+ return BrowserConstants::MANUFACTURER_DAXIAN_2
301
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_DBTEL))
302
+ return BrowserConstants::MANUFACTURER_DBTEL
303
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_EASTCOM))
304
+ return BrowserConstants::MANUFACTURER_EASTCOM
305
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_EASTCOM_2))
306
+ return BrowserConstants::MANUFACTURER_EASTCOM_2
307
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_PANTECH))
308
+ return BrowserConstants::MANUFACTURER_PANTECH
309
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_DAXIAN))
310
+ return BrowserConstants::MANUFACTURER_DOPOD
311
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_HAIER))
312
+ return BrowserConstants::MANUFACTURER_HAIER
313
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_HAIER_2))
314
+ return BrowserConstants::MANUFACTURER_HAIER
315
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_KONKA))
316
+ return BrowserConstants::MANUFACTURER_KONKA
317
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_KEJIAN))
318
+ return BrowserConstants::MANUFACTURER_KEJIAN
319
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_KEJIAN_2))
320
+ return BrowserConstants::MANUFACTURER_KEJIAN
321
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_LENOVO))
322
+ return BrowserConstants::MANUFACTURER_LENOVO
323
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_4THPASS))
324
+ return BrowserConstants::MANUFACTURER_4THPASS
325
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_ACER))
326
+ return BrowserConstants::MANUFACTURER_ACER
327
+ elsif (user_agent.include?(BrowserConstants::MANUFACTURER_SAGEM))
328
+ return BrowserConstants::MANUFACTURER_SAGEM
329
+ elsif (browser_type == BrowserConstants::BROWSER_EZWAP)
330
+ return BrowserConstants::MANUFACTURER_EZOS
331
+ elsif (browser_type == BrowserConstants::BROWSER_JBROWSER)
332
+ return BrowserConstants::MANUFACTURER_JATAAYU
333
+ else
334
+ return BrowserConstants::UNKNOWN
335
+ end
336
+ end
337
+
338
+ def self.get_midp(user_agent)
339
+ info = BrowserConstants::UNKNOWN
340
+ index = user_agent.index("MIDP")
341
+ info_str = nil
342
+ if (index)
343
+ if (index + 10 < user_agent.length)
344
+ info_str = user_agent[(index + 4) .. (index + 10)]
345
+ else
346
+ info_str = user_agent[(index + 4) .. user_agent.length]
347
+ end
348
+ if (info_str.include?("1.0"))
349
+ info = "1.0"
350
+ elsif(info_str.include?("2.0"))
351
+ info = "2.0"
352
+ end
353
+ end
354
+ return info
355
+ end
356
+
357
+ def self.get_cldc(user_agent)
358
+ info = BrowserConstants::UNKNOWN
359
+ index = user_agent.index("CLDC")
360
+ info_str = nil
361
+ if (index)
362
+ if (index + 10 < user_agent.length)
363
+ info_str = user_agent[(index + 4) .. (index + 10)]
364
+ else
365
+ info_str = user_agent[(index + 4) .. user_agent.length]
366
+ end
367
+ if (info_str.include?("1.0"))
368
+ info = "1.0"
369
+ elsif (info_str.include?("1.1"))
370
+ info = "1.1"
371
+ end
372
+ end
373
+ return info
374
+ end
375
+
376
+ # currently, only the prefered language will be returned. So the
377
+ # String[] will have at most one element.
378
+ def self.get_languages(accept_language)
379
+ if (accept_language || accept_language.empty?)
380
+ return ""
381
+ end
382
+ index = accept_language.index(",")
383
+ if (index)
384
+ accept_language = accept_language[0 .. index]
385
+ end
386
+ index2 = accept_language.index("-")
387
+ if (index2)
388
+ accept_language = accept_language[0 .. index2]
389
+ end
390
+ # locale = Locale.new(accept_language.strip)
391
+ # preferedLanguage = locale.getDisplayLanguage(Locale.ENGLISH)
392
+ # if (preferedLanguage == nil || preferedLanguage.equals("")) {
393
+ # return new String[0]
394
+ # } else {
395
+ # return new String[] { preferedLanguage }
396
+ # }
397
+ # }
398
+ return ["en"]
399
+ end
400
+
401
+ #special rules must be placed in mumbered sequence
402
+
403
+ # /*
404
+ # * If it is a web browser, set HTMLSupport to true
405
+ # */
406
+ def self.special_rule_10_accept_all(accept, config)
407
+ if (!config.mobile_browser)
408
+ config.supported_HTML = true
409
+ end
410
+ return config
411
+ end
412
+
413
+ # /*
414
+ # * If it is a MSIE browser, set MANUFACTURER to "Microsoft"
415
+ # */
416
+ def self.special_rule_20_manufacturer_of_msie(config)
417
+ if (config.user_agent.include?(BrowserConstants::OS_WIN_CE))
418
+ config.mobile_browser = true
419
+ config.manufacturer = BrowserConstants::MANUFACTURER_MICROSOFT
420
+ if (config.browser == BrowserConstants::UNKNOWN)
421
+ config.browser = BrowserConstants::OS_WIN_CE
422
+ else
423
+ config.browser = config.browser + "/" + BrowserConstants::OS_WIN_CE
424
+ end
425
+ elsif (config.browser == "MSIE")
426
+ config.manufacturer = BrowserConstants::MANUFACTURER_MICROSOFT
427
+ end
428
+ return config
429
+ end
430
+
431
+ # /*
432
+ # * If it is a Firefox browser, set MANUFACTURER to "Mozilla"
433
+ # */
434
+ def self.special_rule_30_manufacturer_of_firefox(config)
435
+ if (config.browser == "Firefox")
436
+ config.manufacturer = BrowserConstants::MANUFACTURER_FIREFOX
437
+ end
438
+ return config
439
+ end
440
+
441
+ # /*
442
+ # * If it is a BlackBerry or RIM browser, it must be a mobile browser
443
+ # */
444
+ def self.special_rule_40_manufacturer_of_blackberry(config)
445
+ if (config.manufacturer.downcase == BrowserConstants::MANUFACTURER_RIM_1.downcase ||
446
+ config.manufacturer.downcase == BrowserConstants::MANUFACTURER_RIM_2.downcase)
447
+ config.mobile_browser = true
448
+ end
449
+ return config
450
+ end
451
+
452
+ # /*
453
+ # * If it is a iPhone, it must be a mobile browser
454
+ # */
455
+ def self.special_rule_50_iphone(config)
456
+ if (config.user_agent.include?(BrowserConstants::BROWSER_IPHONE) && config.user_agent.include?("Mobile"))
457
+ config.mobile_browser = true
458
+ config.browser = BrowserConstants::BROWSER_IPHONE
459
+ config.manufacturer = BrowserConstants::MANUFACTURER_APPLE
460
+ end
461
+ return config
462
+ end
463
+
464
+ # /*
465
+ # * If it is an Opera, it can be a Nintendo or Nitro mobile browser
466
+ # */
467
+ def self.special_rule_60_opera(config)
468
+ if (config.browser == BrowserConstants::BROWSER_OPERA)
469
+ if (config.user_agent.include?(BrowserConstants::BROWSER_OPERA_NINTEDO))
470
+ config.mobile_browser = true
471
+ config.browser = BrowserConstants::BROWSER_OPERA + "/" + BrowserConstants::BROWSER_OPERA_NINTEDO
472
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_OPERA_NITRO))
473
+ config.mobile_browser = true
474
+ config.browser = BrowserConstants::BROWSER_OPERA + "/"+ BrowserConstants::BROWSER_OPERA_NITRO
475
+ end
476
+ end
477
+ return config
478
+ end
479
+
480
+ # /*
481
+ # * If it is an Opera, it can be a Nintendo or Nitro mobile browser
482
+ # */
483
+ def self.special_rule_70_playstation(config)
484
+ u2 = config.user_agent.upcase
485
+ if (u2.include?(BrowserConstants::MANUFACTURER_SONY_PLAYSTATION))
486
+ config.manufacturer = BrowserConstants::MANUFACTURER_SONY
487
+ config.mobile_browser = true
488
+ end
489
+ return config
490
+ end
491
+
492
+ # /*
493
+ # * Special mobile brower detector for AvantGo, DoCoMo, KDDI, Vodafone,
494
+ # * EudoraWeb, iPAQ, NEC, Nokia
495
+ # */
496
+ def self.special_rule_100_special_mobile_browsers(config)
497
+ if (config.browser == BrowserConstants::BROWSER_AVANTGO)
498
+ config.mobile_browser = true
499
+ elsif (config.browser == BrowserConstants::BROWSER_BLAZER)
500
+ config.mobile_browser = true
501
+ if (config.manufacturer == BrowserConstants::UNKNOWN)
502
+ config.manufacturer = BrowserConstants::MANUFACTURER_TREO + "/" + BrowserConstants::MANUFACTURER_PALM
503
+ else
504
+ if (config.manufacturer.include?(BrowserConstants::MANUFACTURER_PALM))
505
+ config.manufacturer = config.get_manufacturer() + "/" + BrowserConstants::MANUFACTURER_TREO
506
+ else
507
+ config.manufacturer = config.get_manufacturer() + "/" + BrowserConstants::MANUFACTURER_TREO + "/" + BrowserConstants::MANUFACTURER_PALM
508
+ end
509
+ end
510
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_SAMSUNG_1)
511
+ config.mobile_browser = true
512
+ elsif (config.browser == BrowserConstants::BROWSER_PSION)
513
+ config.mobile_browser = true
514
+ config.manufacturer = BrowserConstants::MANUFACTURER_PSION
515
+ elsif (config.browser == BrowserConstants::BROWSER_DOCOMO)
516
+ config.mobile_browser = true
517
+ config.manufacturer = BrowserConstants::MANUFACTURER_NTT
518
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_KDDI))
519
+ config.mobile_browser = true
520
+ config.manufacturer = BrowserConstants::MANUFACTURER_EZWEB
521
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_NEC_PORTALMMM))
522
+ config.mobile_browser = true
523
+ config.browser = BrowserConstants::BROWSER_NEC_PORTALMMM
524
+ config.manufacturer = BrowserConstants::MANUFACTURER_NEC
525
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_EUDORAWEB))
526
+ config.mobile_browser = true
527
+ config.browser = BrowserConstants::BROWSER_EUDORAWEB
528
+ if (config.user_agent.include?(BrowserConstants::MANUFACTURER_PALM))
529
+ config.manufacturer = BrowserConstants::MANUFACTURER_PALM
530
+ end
531
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_NOKIA_MAEMO))
532
+ config.mobile_browser = true
533
+ if (config.browser == BrowserConstants::UNKNOWN)
534
+ config.browser = BrowserConstants::BROWSER_NOKIA + "/" + BrowserConstants::BROWSER_NOKIA_MAEMO
535
+ end
536
+ if (config.manufacturer == BrowserConstants::UNKNOWN)
537
+ config.manufacturer = BrowserConstants::MANUFACTURER_NOKIA + "?"
538
+ end
539
+ elsif (config.user_agent.include?(BrowserConstants::BROWSER_IPAQ))
540
+ config.mobile_browser = true
541
+ if (config.user_agent.include?(BrowserConstants::BROWSER_PPC))
542
+ config.browser = BrowserConstants::BROWSER_IPAQ + "/" + BrowserConstants::BROWSER_PPC
543
+ else
544
+ config.browser = BrowserConstants::BROWSER_IPAQ
545
+ end
546
+ config.manufacturer = BrowserConstants::MANUFACTURER_HP
547
+ elsif (config.browser == BrowserConstants::BROWSER_O2)
548
+ config.mobile_browser = true
549
+ if (config.user_agent.include?(BrowserConstants::BROWSER_PPC))
550
+ config.browser = config.browser + "/"+ BrowserConstants::BROWSER_PPC
551
+ end
552
+ config.manufacturer = BrowserConstants::MANUFACTURER_HTC
553
+ elsif (config.browser == BrowserConstants::OS_Symbian)
554
+ config.mobile_browser = true
555
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_NOKIA)
556
+ config.mobile_browser = true
557
+ elsif (config.manufacturer == BrowserConstants::MANUFACTURER_ALCATEL)
558
+ config.mobile_browser = true
559
+ elsif (config.browser == BrowserConstants::BROWSER_KBROWSER)
560
+ config.mobile_browser = true
561
+ elsif(config.browser == BrowserConstants::BROWSER_CCWAP)
562
+ config.mobile_browser = true
563
+ config.manufacturer = BrowserConstants::MANUFACTURER_CHECKCOM
564
+ elsif(config.browser == BrowserConstants::BROWSER_IE)
565
+ if (config.user_agent.include?(BrowserConstants::MANUFACTURER_NOKIA))
566
+ config.manufacturer = BrowserConstants::MANUFACTURER_NOKIA
567
+ config.mobile_browser = true
568
+ end
569
+ elsif(config.user_agent.include?(BrowserConstants::BROWSER_MOBILE_UNSORTED_PROXNET) ||
570
+ config.user_agent.include?(BrowserConstants::BROWSER_MOBILE_UNSORTED_ELAINE) ||
571
+ config.user_agent.include?(BrowserConstants::BROWSER_MOBILE_UNSORTED_PLUCKER))
572
+ config.mobile_browser = true
573
+ end
574
+ if (config.user_agent.include?(BrowserConstants::OS_Symbian))
575
+ config.mobile_browser = true
576
+ end
577
+ if (config.user_agent.include?("J2ME") ||
578
+ config.user_agent.include?("MIDP") ||
579
+ config.user_agent.include?("j2me"))
580
+ config.mobile_browser = true
581
+ end
582
+ if (config.user_agent.include?(BrowserConstants::BROWSER_TABLET) ||
583
+ config.user_agent.include?("MIDP"))
584
+ config.mobile_browser = true
585
+ end
586
+ if (config.user_agent.include?(BrowserConstants::DEVICE_SMARTPHONE))
587
+ config.mobile_browser = true
588
+ if (config.browser == BrowserConstants::UNKNOWN)
589
+ config.browser = BrowserConstants::DEVICE_SMARTPHONE
590
+ else
591
+ config.browser = config.browser + "/" + BrowserConstants::DEVICE_SMARTPHONE
592
+ end
593
+ end
594
+ if (config.user_agent.include?(BrowserConstants::BROWSER_SPV))
595
+ config.mobile_browser = true
596
+ if (config.browser == BrowserConstants::UNKNOWN)
597
+ config.browser = BrowserConstants::BROWSER_SPV
598
+ else
599
+ config.browser = config.browser + "/" + BrowserConstants::BROWSER_SPV
600
+ end
601
+ if (config.manufacturer == BrowserConstants::UNKNOWN)
602
+ config.manufacturer = BrowserConstants::MANUFACTURER_HTC + "?"
603
+ else
604
+ config.manufacturer = config.get_manufacturer() + "/" + BrowserConstants::MANUFACTURER_HTC + "?"
605
+ end
606
+ end
607
+
608
+ if (config.user_agent.include?(BrowserConstants::MANUFACTURER_PALM))
609
+ config.mobile_browser = true
610
+ if (config.browser == BrowserConstants::UNKNOWN)
611
+ config.browser = BrowserConstants::MANUFACTURER_PALM
612
+ else
613
+ config.browser = config.browser + "/" + BrowserConstants::MANUFACTURER_PALM
614
+ end
615
+ if (config.manufacturer == BrowserConstants::UNKNOWN)
616
+ config.manufacturer = BrowserConstants::MANUFACTURER_PALM
617
+ else
618
+ if (!config.manufacturer.include?(BrowserConstants::MANUFACTURER_PALM))
619
+ config.manufacturer = config.manufacturer + "/" + BrowserConstants::MANUFACTURER_PALM
620
+ end
621
+ end
622
+ end
623
+ if (config.user_agent.include?(BrowserConstants::BROWSER_PPC))
624
+ config.mobile_browser = true
625
+ if (config.browser == BrowserConstants::UNKNOWN)
626
+ config.browser = BrowserConstants::BROWSER_PPC
627
+ else
628
+ if (!config.browser.include?(BrowserConstants::BROWSER_PPC))
629
+ config.browser = config.browser + "/" + BrowserConstants::BROWSER_PPC
630
+ end
631
+ end
632
+ end
633
+
634
+ if (config.user_agent.include?(BrowserConstants::TOOL_REGKING))
635
+ config.mobile_browser = true
636
+ if (config.browser == BrowserConstants::UNKNOWN)
637
+ config.browser = BrowserConstants::TOOL_REGKING
638
+ else
639
+ config.browser = config.browser + "/" + BrowserConstants::TOOL_REGKING
640
+ end
641
+ end
642
+ if (!config.mobile_browser)
643
+ if (config.user_agent.include?(BrowserConstants::PLATFORM_MMP))
644
+ config.mobile_browser = true
645
+ elsif (config.user_agent.include?("wireless"))
646
+ config.mobile_browser = true
647
+ elsif (config.user_agent.include?("WAP"))
648
+ config.mobile_browser = true
649
+ elsif (config.user_agent.include?("wap"))
650
+ config.mobile_browser = true
651
+ end
652
+ end
653
+ return config
654
+ end
655
+
656
+ # /*
657
+ # * Identify search engines。 Search engines are web browsers.
658
+ # */
659
+ def self.special_rule_200_search_engine_robot(config)
660
+ robot = false
661
+ if (config.user_agent.include?(BrowserConstants::SEARCH_ENGINE_BAIDU_ID))
662
+ robot = true
663
+ config.manufacturer = BrowserConstants::SEARCH_ENGINE_BAIDU_NAME
664
+ elsif (config.user_agent.include?(BrowserConstants::SEARCH_ENGINE_GOOGLE_ID))
665
+ robot = true
666
+ config.manufacturer = BrowserConstants::SEARCH_ENGINE_GOOGLE_NAME
667
+ elsif (config.user_agent.include?(BrowserConstants::SEARCH_ENGINE_YAHOO_ID))
668
+ robot = true
669
+ config.manufacturer = BrowserConstants::SEARCH_ENGINE_YAHOO_NAME
670
+ end
671
+ if (robot)
672
+ config.mobile_browser = false
673
+ config.supported_HTML = true
674
+ end
675
+ return config
676
+ end
677
+
678
+ end
data/test/rmbd_test.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class RmbdTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rmbd'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiranmeduri-rmbd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kiran Meduri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-23 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: meduri@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - lib/rmbd.rb
31
+ - lib/rmbd/browser_constants.rb
32
+ - lib/rmbd/device_config.rb
33
+ - lib/rmbd/device_config_detector.rb
34
+ - test/rmbd_test.rb
35
+ - test/test_helper.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/kiranmeduri/rmbd
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: TODO
62
+ test_files:
63
+ - test/rmbd_test.rb
64
+ - test/test_helper.rb