Permalink
Browse files

add new browsers and platforms

opera, lotus notes, thunderbird, netscape, seamonkey, outlook, evolution, ie-mobile, and symbian os
  • Loading branch information...
1 parent c3015d9 commit 5f136b36dd3cafe2c7d38bf7f07cb870f20f433d @dburt dburt committed Sep 26, 2011
Showing with 60 additions and 22 deletions.
  1. +49 −22 lib/user_agent.rb
  2. +11 −0 spec/user_agents_spec.rb
View
@@ -17,6 +17,7 @@ module Versions
Safari = /version\/([\d\w\.\-]+)/i
Ps3 = /([\d\w\.\-]+)\)\s*$/i
Psp = /([\d\w\.\-]+)\)?\s*$/i
+ Lotus = /Lotus-Notes\/([\w.]+)/i
end
module Browsers
@@ -28,6 +29,13 @@ module Browsers
PS3 = /playstation 3/i
PSP = /playstation portable/i
Firefox = /firefox/i
+ Lotus = /lotus.notes/i
+ Netscape = /netscape/i
+ SeaMonkey = /seamonkey/i
+ Thunderbird = /thunderbird/i
+ Outlook = /microsoft.outlook/i
+ Evolution = /evolution/i
+ IEMobile = /iemobile|windows phone/i
end
module OS
@@ -36,13 +44,16 @@ module OS
Windows2003 = /windows nt 5\.2/i
WindowsXP = /windows nt 5\.1/i
Windows2000 = /windows nt 5\.0/i
+ WindowsPhone = /windows (ce|phone|mobile)( os)?/i
+ Windows = /windows/i
OSX = /os x (\d+)[._](\d+)/i
Linux = /linux/i
Wii = /wii/i
PS3 = /playstation 3/i
PSP = /playstation portable/i
Ipad = /\(iPad.*os (\d+)[._](\d+)/i
Iphone = /\(iPhone.*os (\d+)[._](\d+)/i
+ Symbian = /symbian(os)?/i
end
module Platform
@@ -56,6 +67,8 @@ module Platform
Iphone = /iphone/i
Android = /android/i
Blackberry = /blackberry/i
+ WindowsPhone = /windows (ce|phone|mobile)( os)?/i
+ Symbian = /symbian(os)?/i
end
def self.engine(string)
@@ -66,6 +79,7 @@ def self.engine(string)
when Engines::Chrome then :chrome
when Engines::Presto then :presto
when Engines::Gecko then :gecko
+ when /opera/i then :unknown
when Engines::Msie then :msie
else
:unknown
@@ -80,14 +94,21 @@ def self.engine_version(string)
def self.browser_name(string)
case string
- when Browsers::Konqueror then :konqueror
- when Browsers::Chrome then :chrome
- when Browsers::Safari then :safari
- when Browsers::IE then :ie
- when Browsers::Opera then :opera
- when Browsers::PS3 then :ps3
- when Browsers::PSP then :psp
- when Browsers::Firefox then :firefox
+ when Browsers::Konqueror then :konqueror
+ when Browsers::Chrome then :chrome
+ when Browsers::Safari then :safari
+ when Browsers::Opera then :opera
+ when Browsers::PS3 then :ps3
+ when Browsers::PSP then :psp
+ when Browsers::Firefox then :firefox
+ when Browsers::Lotus then :lotus
+ when Browsers::Netscape then :netscape
+ when Browsers::SeaMonkey then :seamonkey
+ when Browsers::Thunderbird then :thunderbird
+ when Browsers::Outlook then :outlook
+ when Browsers::Evolution then :evolution
+ when Browsers::IEMobile then :iemobile
+ when Browsers::IE then :ie
else
:unknown
end
@@ -103,32 +124,38 @@ def self.browser_version(string)
$1 if string =~ Versions::Ps3
when :psp
$1 if string =~ Versions::Psp
+ when :lotus
+ $1 if string =~ Versions::Lotus
else
$1 if string =~ /#{name}[\/ ]([\d\w\.\-]+)/i
end
end
def self.os(string)
case string
- when OS::WindowsVista then 'Windows Vista'
- when OS::Windows7 then 'Windows 7'
- when OS::Windows2003 then 'Windows 2003'
- when OS::WindowsXP then 'Windows XP'
- when OS::Windows2000 then 'Windows 2000'
- when OS::OSX then "OS X #{$1}.#{$2}"
- when OS::Linux then 'Linux'
- when OS::Wii then 'Wii'
- when OS::PS3 then 'Playstation'
- when OS::PSP then 'Playstation'
- when OS::Ipad then "iPad OS #{$1}.#{$2}"
- when OS::Iphone then "iPhone OS #{$1}.#{$2}"
+ when OS::WindowsPhone then 'Windows Phone'
+ when OS::WindowsVista then 'Windows Vista'
+ when OS::Windows7 then 'Windows 7'
+ when OS::Windows2003 then 'Windows 2003'
+ when OS::WindowsXP then 'Windows XP'
+ when OS::Windows2000 then 'Windows 2000'
+ when OS::Windows then 'Windows'
+ when OS::OSX then "OS X #{$1}.#{$2}"
+ when OS::Linux then 'Linux'
+ when OS::Wii then 'Wii'
+ when OS::PS3 then 'Playstation'
+ when OS::PSP then 'Playstation'
+ when OS::Ipad then "iPad OS #{$1}.#{$2}"
+ when OS::Iphone then "iPhone OS #{$1}.#{$2}"
+ when Platform::Symbian then "Symbian OS"
else
'Unknown'
end
end
def self.platform(string)
case string
+ when Platform::WindowsPhone then :windows_phone
when Platform::Windows then :windows
when Platform::Mac then :macintosh
when Platform::Android then :android
@@ -139,6 +166,7 @@ def self.platform(string)
when Platform::Ipad then :ipad
when Platform::Ipod then :ipod
when Platform::Iphone then :iphone
+ when Platform::Symbian then :symbian
else
:unknown
end
@@ -175,8 +203,7 @@ def platform
end
def mobile?
- [:android, :blackberry, :ipad, :ipod, :iphone].include? platform or
- name == :psp
+ [:android, :blackberry, :ipad, :ipod, :iphone, :symbian, :windows_phone].include? platform or name == :psp
end
def to_s
View
@@ -56,5 +56,16 @@ def test(mobile, name, version, platform, os, engine, engine_version, source)
test false, :firefox, '3.6.8', :linux, 'Linux', :gecko, '20100723', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/9.10 (karmic) Firefox/3.6.8'
test false, :firefox, '3.6.9', :linux, 'Linux', :gecko, '20100824', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9'
test false, :firefox, '3.6.9', :linux, 'Linux', :gecko, '20100825', 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100825 Ubuntu/10.04 (lucid) Firefox/3.6.9'
+ test false, :opera, '7.21', :windows, 'Windows', :unknown, nil, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98) Opera 7.21 [pt-BR]'
+ test false, :lotus, '6.0', :windows, 'Windows', :unknown, nil, 'Mozilla/4.0 (compatible; Lotus-Notes/6.0; Windows-NT)'
+ test false, :thunderbird, '2.0.0.23', :windows, 'Windows XP', :gecko, '20090812', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23'
+ test false, :netscape, '7.1', :windows, 'Windows XP', :gecko, '20030624', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)'
+ test false, :seamonkey, '2.0.13', :windows, 'Windows Vista', :gecko, '20110320', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.18) Gecko/20110320 SeaMonkey/2.0.13'
+ test false, :outlook, '14.0.6025', :windows, 'Windows 7', :msie, '7.0', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET4.0C; .NET4.0E; InfoPath.3; Microsoft Outlook 14.0.6025; ms-office; MSOffice 14)'
+ test false, :evolution, '2.32.2', :unknown, 'Unknown', :unknown, nil, 'CamelHttpStream/1.0 Evolution/2.32.2'
+ test true, :iemobile, '7.6', :windows_phone, 'Windows Phone', :msie, '6.0', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.6)'
+ test true, :iemobile, nil, :windows_phone, 'Windows Phone', :msie, '6.0', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Windows Phone 6.5.3.5)'
+ test true, :iemobile, '7.0', :windows_phone, 'Windows Phone', :msie, '7.0', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; HTC; 7 Mozart; Orange)'
+ test true, :safari, nil, :symbian, 'Symbian OS', :webkit, '413', 'Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE71-3/300.21.012; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413'
end

0 comments on commit 5f136b3

Please sign in to comment.