wurfl_device 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +2 -2
- data/README.md +31 -7
- data/config/unicorn.conf.rb +13 -7
- data/lib/wurfl_device/cache.rb +215 -0
- data/lib/wurfl_device/capability.rb +5 -1
- data/lib/wurfl_device/cli.rb +59 -67
- data/lib/wurfl_device/settings.rb +595 -0
- data/lib/wurfl_device/ui.rb +1 -0
- data/lib/wurfl_device/user_agent.rb +75 -8
- data/lib/wurfl_device/user_agent_matcher.rb +153 -191
- data/lib/wurfl_device/version.rb +1 -1
- data/lib/wurfl_device/web_service.rb +10 -44
- data/lib/wurfl_device/xml_loader.rb +44 -37
- data/lib/wurfl_device.rb +41 -236
- data/spec/cache/device_spec.rb +7 -31
- data/spec/cache/user_agents_spec.rb +27 -0
- data/spec/spec_helper.rb +6 -1
- data/wurfl_device.gemspec +6 -3
- metadata +52 -38
- data/lib/wurfl_device/constants.rb +0 -43
- data/lib/wurfl_device/device.rb +0 -83
@@ -1,8 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module WurflDevice
|
2
3
|
class UserAgent < String
|
4
|
+
def initialize(str='')
|
5
|
+
super(str)
|
6
|
+
unless self.valid_encoding?
|
7
|
+
# TODO need to convert this String#encode, depreciated in ruby 1.9.3
|
8
|
+
require 'iconv'
|
9
|
+
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
10
|
+
self.replace ic.iconv(self << ' ')[0..-2]
|
11
|
+
end
|
12
|
+
self.strip!
|
13
|
+
end
|
14
|
+
|
3
15
|
def is_desktop_browser?
|
4
16
|
ua = self.downcase
|
5
|
-
WurflDevice::
|
17
|
+
WurflDevice::Settings::DESKTOP_BROWSERS.each do |sig|
|
6
18
|
return true if ua.index(sig)
|
7
19
|
end
|
8
20
|
return false
|
@@ -12,7 +24,7 @@ module WurflDevice
|
|
12
24
|
ua = self.downcase
|
13
25
|
return false if self.is_desktop_browser?
|
14
26
|
return true if ua =~ /[^\d]\d{3}x\d{3}/
|
15
|
-
WurflDevice::
|
27
|
+
WurflDevice::Settings::DESKTOP_BROWSERS.each do |sig|
|
16
28
|
return true if ua.index(sig)
|
17
29
|
end
|
18
30
|
return false
|
@@ -20,7 +32,7 @@ module WurflDevice
|
|
20
32
|
|
21
33
|
def is_robot?
|
22
34
|
ua = self.downcase
|
23
|
-
WurflDevice::
|
35
|
+
WurflDevice::Settings::ROBOTS.each do |sig|
|
24
36
|
return true if ua.index(sig)
|
25
37
|
end
|
26
38
|
return false
|
@@ -119,7 +131,7 @@ module WurflDevice
|
|
119
131
|
end
|
120
132
|
|
121
133
|
def cleaned
|
122
|
-
user_agent = self.dup
|
134
|
+
user_agent = self.strip.dup
|
123
135
|
user_agent.sub!('UP.Link', '')
|
124
136
|
user_agent.replace($1) if user_agent =~ /^(.+)NOKIA-MSISDN\:\ (.+)$/i
|
125
137
|
user_agent.sub!("'M', 'Y' 'P', 'H', 'O', 'N', 'E'", "MyPhone")
|
@@ -132,12 +144,67 @@ module WurflDevice
|
|
132
144
|
# remove locale identifiers
|
133
145
|
user_agent.sub!(/([ ;])[a-zA-Z]{2}-[a-zA-Z]{2}([ ;\)])/, '\1xx-xx\2')
|
134
146
|
|
135
|
-
pos =
|
136
|
-
user_agent.replace(
|
147
|
+
pos = user_agent.index('BlackBerry')
|
148
|
+
user_agent.replace(user_agent.slice(pos, user_agent.length-pos)) unless pos.nil?
|
137
149
|
|
138
150
|
user_agent.sub!(/(Android \d\.\d)([^; \/\)]+)/, '\1')
|
139
|
-
user_agent
|
140
|
-
|
151
|
+
return user_agent
|
152
|
+
end
|
153
|
+
|
154
|
+
def manufacturer
|
155
|
+
# Process MOBILE user agents
|
156
|
+
unless self.is_desktop_browser?
|
157
|
+
return 'Nokia' if self.contains('Nokia')
|
158
|
+
return 'Samsung' if self.contains(['Samsung/SGH', 'SAMSUNG-SGH']) || self.starts_with(['SEC-', 'Samsung', 'SAMSUNG', 'SPH', 'SGH', 'SCH']) || self.starts_with('samsung', true)
|
159
|
+
return 'BlackBerry' if self.contains('blackberry', true)
|
160
|
+
return 'SonyEricsson' if self.contains('Sony')
|
161
|
+
return 'Motorola' if self.starts_with(['Mot-', 'MOT-', 'MOTO', 'moto']) || self.contains('Motorola')
|
162
|
+
|
163
|
+
return 'Alcatel' if self.starts_with('alcatel', true)
|
164
|
+
return 'Apple' if self.contains(['iPhone', 'iPod', 'iPad', '(iphone'])
|
165
|
+
return 'BenQ' if self.starts_with('benq', true)
|
166
|
+
return 'DoCoMo' if self.starts_with('DoCoMo')
|
167
|
+
return 'Grundig' if self.starts_with('grundig', true)
|
168
|
+
return 'HTC' if self.contains(['HTC', 'XV6875'])
|
169
|
+
return 'Kddi' if self.contains('KDDI-')
|
170
|
+
return 'Kyocera' if self.starts_with(['kyocera', 'QC-', 'KWC-'])
|
171
|
+
return 'LG' if self.starts_with('lg', true)
|
172
|
+
return 'Mitsubishi' if self.starts_with('Mitsu')
|
173
|
+
return 'Nec' if self.starts_with(['NEC-', 'KGT'])
|
174
|
+
return 'Nintendo' if self.contains('Nintendo') || (self.starts_with('Mozilla/') && self.starts_with('Nitro') && self.starts_with('Opera'))
|
175
|
+
return 'Panasonic' if self.contains('Panasonic')
|
176
|
+
return 'Pantech' if self.starts_with(['Pantech', 'PT-', 'PANTECH', 'PG-'])
|
177
|
+
return 'Philips' if self.starts_with('philips', true)
|
178
|
+
return 'Portalmmm' if self.starts_with('portalmmm')
|
179
|
+
return 'Qtek' if self.starts_with('Qtek')
|
180
|
+
return 'Sagem' if self.starts_with('sagem', true)
|
181
|
+
return 'Sharp' if self.starts_with('sharp', true)
|
182
|
+
return 'Siemens' if self.starts_with('SIE-')
|
183
|
+
return 'SPV' if self.starts_with('SPV')
|
184
|
+
return 'Toshiba' if self.starts_with('Toshiba')
|
185
|
+
return 'Vodafone' if self.starts_with('Vodafone')
|
186
|
+
|
187
|
+
# mobile browsers
|
188
|
+
return 'Android' if self.contains('Android')
|
189
|
+
return 'OperaMini' if self.contains(['Opera Mini', 'Opera Mobi'])
|
190
|
+
return 'WindowsCE' if self.contains('Mozilla/') && self.contains('Windows CE')
|
191
|
+
end
|
192
|
+
|
193
|
+
# Process Robots (Web Crawlers and the like)
|
194
|
+
return 'Bot' if self.is_robot?
|
195
|
+
|
196
|
+
# Process NON-MOBILE user agents
|
197
|
+
unless self.is_mobile_browser?
|
198
|
+
return 'MSIE' if self.starts_with('Mozilla') && self.contains('MSIE') && !self.contains(['Opera', 'armv', 'MOTO', 'BREW'])
|
199
|
+
return 'Firefox' if self.contains('Firefox') && !self.contains(['Sony', 'Novarra', 'Opera'])
|
200
|
+
return 'Chrome' if self.contains('Chrome')
|
201
|
+
return 'Konqueror' if self.contains('Konqueror')
|
202
|
+
return 'Opera' if self.contains('Opera')
|
203
|
+
return 'Safari' if self.starts_with('Mozilla') && self.contains('Safari')
|
204
|
+
return 'AOL' if self.contains(['AOL', 'America Online']) || self.contains('aol 9', true)
|
205
|
+
end
|
206
|
+
|
207
|
+
return 'CatchAll'
|
141
208
|
end
|
142
209
|
end
|
143
210
|
end
|