browser 0.2.1 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e085e2a4794cd3e1368120c6f574b7c15cb6f3c
4
- data.tar.gz: cb7bc7aea7519f258b72ddf8cca00a35b1e7e58f
3
+ metadata.gz: 9a021a6e70a34b34a47cf016fc88851dec3aaebe
4
+ data.tar.gz: f76665580a4eed8cfeb95fb1a67c8424aeacdeaf
5
5
  SHA512:
6
- metadata.gz: cd8ef682213aa133b315233165f20b6e8ecd6670805c85e4916d62411a78a62cb00a767289de30ee421b2f4f87e7dc10596ff11b55f1b5443c210471e29e0f0e
7
- data.tar.gz: e3007ffbba33bfd98f82190892d1b1ed163c4d97249df9e9d0a640398ebe103e59c08b7b1c43c0b68c573a353f8a640636be1659d9cc0db06e6ba85982dc9d80
6
+ metadata.gz: f2f700870abd8cddd6b9598699eee7547c6c5dc3e18d55bceedf32dc482e537b927136d295204fcc674a04da4c71e5f092c31ee43e08b562ce331336cba1e3b2
7
+ data.tar.gz: ac41b49b5e3ca509a40245bddde88838a2bffde851816f70e2e463ce0793a30b1e232383ae92b3efcc79aaa41db82b616c9cab6ff1c59f5964649acd0ac11f0b
@@ -1,53 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- browser (0.2.1)
4
+ browser (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- actionmailer (4.0.0)
10
- actionpack (= 4.0.0)
11
- mail (~> 2.5.3)
12
- actionpack (4.0.0)
13
- activesupport (= 4.0.0)
9
+ actionmailer (4.0.2)
10
+ actionpack (= 4.0.2)
11
+ mail (~> 2.5.4)
12
+ actionpack (4.0.2)
13
+ activesupport (= 4.0.2)
14
14
  builder (~> 3.1.0)
15
15
  erubis (~> 2.7.0)
16
16
  rack (~> 1.5.2)
17
17
  rack-test (~> 0.6.2)
18
- activemodel (4.0.0)
19
- activesupport (= 4.0.0)
18
+ activemodel (4.0.2)
19
+ activesupport (= 4.0.2)
20
20
  builder (~> 3.1.0)
21
- activerecord (4.0.0)
22
- activemodel (= 4.0.0)
21
+ activerecord (4.0.2)
22
+ activemodel (= 4.0.2)
23
23
  activerecord-deprecated_finders (~> 1.0.2)
24
- activesupport (= 4.0.0)
24
+ activesupport (= 4.0.2)
25
25
  arel (~> 4.0.0)
26
26
  activerecord-deprecated_finders (1.0.3)
27
- activesupport (4.0.0)
27
+ activesupport (4.0.2)
28
28
  i18n (~> 0.6, >= 0.6.4)
29
29
  minitest (~> 4.2)
30
30
  multi_json (~> 1.3)
31
31
  thread_safe (~> 0.1)
32
32
  tzinfo (~> 0.3.37)
33
- arel (4.0.0)
34
- atomic (1.1.10)
35
- awesome_print (1.1.0)
33
+ arel (4.0.1)
34
+ atomic (1.1.14)
35
+ awesome_print (1.2.0)
36
36
  builder (3.1.4)
37
- coderay (1.0.9)
37
+ coderay (1.1.0)
38
38
  erubis (2.7.0)
39
39
  hike (1.2.3)
40
- i18n (0.6.4)
40
+ i18n (0.6.9)
41
41
  mail (2.5.4)
42
42
  mime-types (~> 1.16)
43
43
  treetop (~> 1.4.8)
44
- method_source (0.8.1)
45
- mime-types (1.23)
44
+ method_source (0.8.2)
45
+ mime-types (1.25.1)
46
46
  minitest (4.7.5)
47
- multi_json (1.7.7)
47
+ multi_json (1.8.2)
48
48
  polyglot (0.3.3)
49
- pry (0.9.12.2)
50
- coderay (~> 1.0.5)
49
+ pry (0.9.12.4)
50
+ coderay (~> 1.0)
51
51
  method_source (~> 0.8)
52
52
  slop (~> 3.4)
53
53
  pry-meta (0.0.5)
@@ -63,38 +63,38 @@ GEM
63
63
  rack (1.5.2)
64
64
  rack-test (0.6.2)
65
65
  rack (>= 1.0)
66
- rails (4.0.0)
67
- actionmailer (= 4.0.0)
68
- actionpack (= 4.0.0)
69
- activerecord (= 4.0.0)
70
- activesupport (= 4.0.0)
66
+ rails (4.0.2)
67
+ actionmailer (= 4.0.2)
68
+ actionpack (= 4.0.2)
69
+ activerecord (= 4.0.2)
70
+ activesupport (= 4.0.2)
71
71
  bundler (>= 1.3.0, < 2.0)
72
- railties (= 4.0.0)
72
+ railties (= 4.0.2)
73
73
  sprockets-rails (~> 2.0.0)
74
- railties (4.0.0)
75
- actionpack (= 4.0.0)
76
- activesupport (= 4.0.0)
74
+ railties (4.0.2)
75
+ actionpack (= 4.0.2)
76
+ activesupport (= 4.0.2)
77
77
  rake (>= 0.8.7)
78
78
  thor (>= 0.18.1, < 2.0)
79
79
  rake (10.1.0)
80
- slop (3.4.5)
81
- sprockets (2.10.0)
80
+ slop (3.4.7)
81
+ sprockets (2.10.1)
82
82
  hike (~> 1.2)
83
83
  multi_json (~> 1.0)
84
84
  rack (~> 1.0)
85
85
  tilt (~> 1.1, != 1.3.0)
86
- sprockets-rails (2.0.0)
86
+ sprockets-rails (2.0.1)
87
87
  actionpack (>= 3.0)
88
88
  activesupport (>= 3.0)
89
89
  sprockets (~> 2.8)
90
90
  thor (0.18.1)
91
- thread_safe (0.1.0)
91
+ thread_safe (0.1.3)
92
92
  atomic
93
93
  tilt (1.4.1)
94
- treetop (1.4.14)
94
+ treetop (1.4.15)
95
95
  polyglot
96
96
  polyglot (>= 0.3.1)
97
- tzinfo (0.3.37)
97
+ tzinfo (0.3.38)
98
98
 
99
99
  PLATFORMS
100
100
  ruby
data/README.md CHANGED
@@ -25,15 +25,17 @@ browser.opera?
25
25
  browser.chrome?
26
26
  browser.mobile?
27
27
  browser.tablet?
28
+ browser.console?
28
29
  browser.firefox?
29
30
  browser.ie?
30
- browser.ie6? # this goes up to 10
31
+ browser.ie6? # this goes up to 11
31
32
  browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
32
33
  browser.platform # return :mac, :windows, :linux or :other
33
34
  browser.mac?
34
35
  browser.windows?
35
36
  browser.linux?
36
37
  browser.blackberry?
38
+ browser.bot?
37
39
  browser.meta # an array with several attributes
38
40
  browser.to_s # the meta info joined by space
39
41
  ```
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: /mnt/hgfs/-Projects/github/browser
2
+ remote: ..
3
3
  specs:
4
- browser (0.2.1)
4
+ browser (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,7 +8,9 @@ require "browser/methods/ie"
8
8
  require "browser/methods/platform"
9
9
  require "browser/methods/mobile"
10
10
  require "browser/methods/devices"
11
+ require "browser/methods/consoles"
11
12
  require "browser/methods/language"
13
+ require "browser/methods/bots"
12
14
 
13
15
  require "browser/meta/base"
14
16
  require "browser/meta/generic_browser"
@@ -26,7 +28,9 @@ class Browser
26
28
  include Platform
27
29
  include Mobile
28
30
  include Devices
31
+ include Consoles
29
32
  include Language
33
+ include Bots
30
34
 
31
35
  # Set browser's UA string.
32
36
  attr_accessor :user_agent
@@ -34,20 +38,23 @@ class Browser
34
38
  alias :ua= :user_agent=
35
39
 
36
40
  NAMES = {
37
- :android => "Android",
38
- :blackberry => "BlackBerry",
39
- :chrome => "Chrome",
40
- :core_media => "Apple CoreMedia",
41
- :firefox => "Firefox",
42
- :ie => "Internet Explorer",
43
- :ipad => "iPad",
44
- :iphone => "iPhone",
45
- :ipod => "iPod Touch",
46
- :opera => "Opera",
47
- :phantom_js => "PhantomJS",
48
- :psp => "PlayStation Portable",
49
- :quicktime => "QuickTime",
50
- :safari => "Safari",
41
+ :android => "Android",
42
+ :blackberry => "BlackBerry",
43
+ :chrome => "Chrome",
44
+ :core_media => "Apple CoreMedia",
45
+ :firefox => "Firefox",
46
+ :ie => "Internet Explorer",
47
+ :ipad => "iPad",
48
+ :iphone => "iPhone",
49
+ :ipod => "iPod Touch",
50
+ :nintendo => "Nintendo",
51
+ :opera => "Opera",
52
+ :phantom_js => "PhantomJS",
53
+ :psp => "PlayStation Portable",
54
+ :playstation => "PlayStation",
55
+ :quicktime => "QuickTime",
56
+ :safari => "Safari",
57
+ :xbox => "Xbox",
51
58
 
52
59
  # This must be last item, since Ruby 1.9+ has ordered keys.
53
60
  :other => "Other",
@@ -55,7 +62,8 @@ class Browser
55
62
 
56
63
  VERSIONS = {
57
64
  :default => %r[(?:Version|MSIE|Firefox|Chrome|CriOS|QuickTime|BlackBerry[^/]+|CoreMedia v|PhantomJS)[/ ]?([a-z0-9.]+)]i,
58
- :opera => %r[(?:Opera/.*? Version/([\d.]+)|Chrome/([\d.]+).*?OPR)]
65
+ :opera => %r[(?:Opera/.*? Version/([\d.]+)|Chrome/([\d.]+).*?OPR)],
66
+ :ie => %r[(?:MSIE |Trident/.*?; rv:)([\d.]+)]
59
67
  }
60
68
 
61
69
  # Create a new browser instance and set
@@ -0,0 +1,74 @@
1
+ class Browser
2
+ module Bots
3
+ # This initial list of bots was humbly borrowed from the split (https://github.com/andrew/split)
4
+ # gem.
5
+ BOTS = {
6
+ # Indexers
7
+ "AdsBot-Google" => "Google Adwords",
8
+ "Baidu" => "Chinese search engine",
9
+ "Baiduspider" => "Chinese search engine",
10
+ "bingbot" => "Microsoft bing bot",
11
+ "Butterfly" => "Topsy Labs",
12
+ "Gigabot" => "Gigabot spider",
13
+ "Googlebot" => "Google spider",
14
+ "MJ12bot" => "Majestic-12 spider",
15
+ "msnbot" => "Microsoft bot",
16
+ "rogerbot" => "SeoMoz spider",
17
+ "PaperLiBot" => "PaperLi is another content curation service",
18
+ "Slurp" => "Yahoo spider",
19
+ "Sogou" => "Chinese search engine",
20
+ "spider" => "generic web spider",
21
+ "UnwindFetchor" => "Gnip crawler",
22
+ "WordPress" => "WordPress spider",
23
+ "YandexBot" => "Yandex spider",
24
+ "ZIBB" => "ZIBB spider",
25
+
26
+ # HTTP libraries
27
+ "Apache-HttpClient" => "Java http library",
28
+ "AppEngine-Google" => "Google App Engine",
29
+ "curl" => "curl unix CLI http client",
30
+ "ColdFusion" => "ColdFusion http library",
31
+ "EventMachine HttpClient" => "Ruby http library",
32
+ "Go http package" => "Go http library",
33
+ "Java" => "Generic Java http library",
34
+ "libwww-perl" => "Perl client-server library loved by script kids",
35
+ "lwp-trivial" => "Another Perl library loved by script kids",
36
+ "Python-urllib" => "Python http library",
37
+ "PycURL" => "Python http library",
38
+ "Test Certificate Info" => "C http library?",
39
+ "Wget" => "wget unix CLI http client",
40
+
41
+ # URL expanders / previewers
42
+ "awe.sm" => "Awe.sm URL expander",
43
+ "bitlybot" => "bit.ly bot",
44
+ "bot@linkfluence.net" => "Linkfluence bot",
45
+ "facebookexternalhit" => "facebook bot",
46
+ "Feedfetcher-Google" => "Google Feedfetcher",
47
+ "https://developers.google.com/+/web/snippet" => "Google+ Snippet Fetcher",
48
+ "LongURL" => "URL expander service",
49
+ "NING" => "NING - Yet Another Twitter Swarmer",
50
+ "redditbot" => "Reddit Bot",
51
+ "ShortLinkTranslate" => "Link shortener",
52
+ "TweetmemeBot" => "TweetMeMe Crawler",
53
+ "Twitterbot" => "Twitter URL expander",
54
+ "UnwindFetch" => "Gnip URL expander",
55
+ "vkShare" => "VKontake Sharer",
56
+
57
+ # Uptime monitoring
58
+ "check_http" => "Nagios monitor",
59
+ "NewRelicPinger" => "NewRelic monitor",
60
+ "Panopta" => "Monitoring service",
61
+ "Pingdom" => "Pingdom monitoring",
62
+ "SiteUptime" => "Site monitoring services",
63
+
64
+ # ???
65
+ "DigitalPersona Fingerprint Software" => "HP Fingerprint scanner",
66
+ "ShowyouBot" => "Showyou iOS app spider",
67
+ "ZyBorg" => "Zyborg? Hmmm...."
68
+ }
69
+
70
+ def bot?
71
+ ua.empty? || BOTS.any? {|key, description| ua.include?(key) }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,23 @@
1
+ class Browser
2
+ module Consoles
3
+ # Detect if browser is Xbox.
4
+ def xbox?
5
+ !!(ua =~ /xbox/i)
6
+ end
7
+
8
+ # Detect if browser is PlayStation.
9
+ def playstation?
10
+ !!(ua =~ /playstation/i)
11
+ end
12
+
13
+ # Detect if browser is Nintendo.
14
+ def nintendo?
15
+ !!(ua =~ /nintendo/i)
16
+ end
17
+
18
+ # Detect if browser is console (currently Xbox, PlayStation, or Nintendo).
19
+ def console?
20
+ xbox? || playstation? || nintendo?
21
+ end
22
+ end
23
+ end
@@ -1,10 +1,11 @@
1
1
  class Browser
2
2
  module IE
3
- TRIDENT_VERSION_REGEX = /Trident\/([0-9.]+)/
3
+ TRIDENT_VERSION_REGEX = %r[Trident/([0-9.]+)]
4
+ MODERN_IE = %r[Trident/.*?; rv:(.*?)]
4
5
 
5
6
  # Detect if browser is Internet Explorer.
6
7
  def ie?
7
- !!(ua =~ /MSIE/ && ua !~ /Opera/)
8
+ msie? || modern_ie?
8
9
  end
9
10
 
10
11
  # Detect if browser is Internet Explorer 6.
@@ -32,9 +33,23 @@ class Browser
32
33
  ie? && version == "10"
33
34
  end
34
35
 
36
+ # Detect if browser is Internet Explorer 11.
37
+ def ie11?
38
+ ie? && version == "11"
39
+ end
40
+
35
41
  # Detect if IE is running in compatibility mode.
36
42
  def compatibility_view?
37
43
  ie? && ua.match(TRIDENT_VERSION_REGEX) && version.to_i < ($1.to_i + 4)
38
44
  end
45
+
46
+ private
47
+ def msie?
48
+ !!(ua =~ /MSIE/ && ua !~ /Opera/)
49
+ end
50
+
51
+ def modern_ie?
52
+ !!(ua =~ MODERN_IE)
53
+ end
39
54
  end
40
55
  end
@@ -12,17 +12,22 @@ class Browser
12
12
 
13
13
  # Detect if is iOS5.
14
14
  def ios4?
15
- ios? && !!(ua =~ /OS (4)/)
15
+ ios? && !!(ua =~ /OS 4/)
16
16
  end
17
17
 
18
18
  # Detect if is iOS5.
19
19
  def ios5?
20
- ios? && !!(ua =~ /OS (5)/)
20
+ ios? && !!(ua =~ /OS 5/)
21
21
  end
22
22
 
23
23
  # Detect if is iOS6.
24
24
  def ios6?
25
- ios? && !!(ua =~ /OS (6)/)
25
+ ios? && !!(ua =~ /OS 6/)
26
+ end
27
+
28
+ # Detect if is iOS7.
29
+ def ios7?
30
+ ios? && !!(ua =~ /OS 7/)
26
31
  end
27
32
 
28
33
  # Detect if current platform is Macintosh.
@@ -34,11 +39,11 @@ class Browser
34
39
  def windows?
35
40
  !!(ua =~ /Windows/)
36
41
  end
37
-
42
+
38
43
  def windows8?
39
- windows? && !!(ua =~ /Windows NT 6.2/)
44
+ windows? && !!(ua =~ /Windows NT 6.[2-3]/)
40
45
  end
41
-
46
+
42
47
  def windows_rt?
43
48
  windows8? && !!(ua =~ /ARM/)
44
49
  end
@@ -48,6 +53,16 @@ class Browser
48
53
  !!(ua =~ /Linux/)
49
54
  end
50
55
 
56
+ # Detect if current platform is Windows Mobile.
57
+ def windows_mobile?
58
+ !!(ua =~ /Windows CE/)
59
+ end
60
+
61
+ # Detect if current platform is Windows Phone.
62
+ def windows_phone?
63
+ !!(ua =~ /Windows Phone/)
64
+ end
65
+
51
66
  # Return the platform.
52
67
  def platform
53
68
  case
@@ -2,8 +2,6 @@ require "uri"
2
2
 
3
3
  class Browser
4
4
  class Middleware
5
- attr_reader :env
6
-
7
5
  def initialize(app, &block)
8
6
  raise ArgumentError, "Browser::Middleware requires a block" unless block
9
7
 
@@ -12,31 +10,30 @@ class Browser
12
10
  end
13
11
 
14
12
  def call(env)
15
- @env = env
16
13
  request = Rack::Request.new(env)
17
14
 
18
15
  path = catch(:redirected) do
19
16
  Context.new(request).instance_eval(&@block)
20
17
  end
21
18
 
22
- path ? resolve_redirection(request.path, path) : run_app!
19
+ path ? resolve_redirection(request.path, path) : run_app(env)
23
20
  end
24
21
 
25
22
  def resolve_redirection(current_path, path)
26
23
  uri = URI.parse(path)
27
24
 
28
25
  if uri.path == current_path
29
- run_app!
26
+ run_app(env)
30
27
  else
31
28
  redirect(path)
32
29
  end
33
30
  end
34
31
 
35
32
  def redirect(path)
36
- [301, {"Content-Type" => "text/html", "Location" => path}, []]
33
+ [302, {"Content-Type" => "text/html", "Location" => path}, []]
37
34
  end
38
35
 
39
- def run_app!
36
+ def run_app(env)
40
37
  @app.call(env)
41
38
  end
42
39
  end
@@ -1,8 +1,8 @@
1
1
  class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -14,6 +14,7 @@ class BrowserTest < Test::Unit::TestCase
14
14
  IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
15
15
  IE10 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)"
16
16
  IE10_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; EIE10;ENUSMSN)"
17
+ IE11 = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"
17
18
  OPERA = "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64"
18
19
  OPERA_NEXT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.37 Safari/537.36 OPR/15.0.1147.44 (Edition Next)"
19
20
  FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
@@ -35,6 +36,9 @@ class BrowserTest < Test::Unit::TestCase
35
36
  OPERA_MOBI = "Opera/9.8 (Android 2.3.5; Linux; Opera Mobi/ADR-1205181138; U; en) Presto/2.10.254 Version/12.00"
36
37
  WINDOWS_PHONE = "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)"
37
38
  WINDOWS_PHONE8 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"
39
+ WINDOWS_MOBILE = "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12)"
40
+ WINDOWS8 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"
41
+ WINDOWS81 = "Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko"
38
42
  SURFACE = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)"
39
43
  KINDLE = "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)"
40
44
  KINDLE_FIRE = "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
@@ -44,7 +48,17 @@ class BrowserTest < Test::Unit::TestCase
44
48
  IOS4 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"
45
49
  IOS5 = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
46
50
  IOS6 = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
51
+ IOS7 = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"
47
52
  PLAYBOOK = "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+"
53
+ NINTENDO_WII = "Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)"
54
+ NINTENDO_WIIU = "Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Gecko) NX/2.1.0.8.23 NintendoBrowser/1.1.0.7579.EU"
55
+ PLAYSTATION3 = "Mozilla/5.0 (PLAYSTATION 3; 3.55)"
56
+ PLAYSTATION4 = "Mozilla/5.0 (PlayStation 4 1.020) AppleWebKit/536.26 (KHTML, like Gecko)"
57
+ XBOX360 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox), or Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Xbox)"
58
+ XBOXONE = "Mozilla/5.0 (Compatible; MSIE 10.0; Windows NT 6.2; Trident /6.0; Xbox; Xbox One)"
59
+ GOOGLE_BOT = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
60
+ MSN_BOT = "msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)"
61
+ FACEBOOK_BOT = "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
48
62
 
49
63
  def setup
50
64
  @browser = Browser.new
@@ -157,6 +171,12 @@ class BrowserTest < Test::Unit::TestCase
157
171
  assert @browser.ios6?
158
172
  end
159
173
 
174
+ def test_detect_ios7
175
+ @browser.ua = IOS7
176
+ assert @browser.ios?
177
+ assert @browser.ios7?
178
+ end
179
+
160
180
  def test_detect_ie6
161
181
  @browser.ua = IE6
162
182
 
@@ -254,6 +274,18 @@ class BrowserTest < Test::Unit::TestCase
254
274
  assert_equal "7", @browser.version
255
275
  end
256
276
 
277
+ def test_detect_ie11
278
+ @browser.ua = IE11
279
+
280
+ assert_equal "Internet Explorer", @browser.name
281
+ assert @browser.ie?
282
+ assert @browser.ie11?
283
+ assert @browser.modern?
284
+ assert ! @browser.compatibility_view?
285
+ assert_equal "11.0", @browser.full_version
286
+ assert_equal "11", @browser.version
287
+ end
288
+
257
289
  def test_detect_opera
258
290
  @browser.ua = OPERA
259
291
 
@@ -432,9 +464,15 @@ class BrowserTest < Test::Unit::TestCase
432
464
  @browser.ua = "MIDP-2.0"
433
465
  assert @browser.mobile?
434
466
  assert ! @browser.tablet?
467
+ end
468
+
469
+ def test_detect_windows_mobile
470
+ @browser.ua = WINDOWS_MOBILE
435
471
 
436
- @browser.ua = "Windows CE"
437
472
  assert @browser.mobile?
473
+ assert @browser.windows?
474
+ assert @browser.windows_mobile?
475
+ assert ! @browser.windows_phone?
438
476
  assert ! @browser.tablet?
439
477
  end
440
478
 
@@ -530,16 +568,33 @@ class BrowserTest < Test::Unit::TestCase
530
568
  def test_detect_mac_platform
531
569
  @browser.ua = "Mac OS X"
532
570
  assert_equal :mac, @browser.platform
571
+ assert @browser.mac?
533
572
  end
534
573
 
535
574
  def test_detect_windows_platform
536
575
  @browser.ua = "Windows"
537
576
  assert_equal :windows, @browser.platform
577
+ assert @browser.windows?
578
+ end
579
+
580
+ def test_detect_windows8
581
+ @browser.ua = WINDOWS8
582
+
583
+ assert @browser.windows?
584
+ assert @browser.windows8?
585
+ end
586
+
587
+ def test_detect_windows8_1
588
+ @browser.ua = WINDOWS81
589
+
590
+ assert @browser.windows?
591
+ assert @browser.windows8?
538
592
  end
539
593
 
540
594
  def test_detect_linux_platform
541
595
  @browser.ua = "Linux"
542
596
  assert_equal :linux, @browser.platform
597
+ assert @browser.linux?
543
598
  end
544
599
 
545
600
  def test_detect_unknown_platform
@@ -601,6 +656,8 @@ class BrowserTest < Test::Unit::TestCase
601
656
  assert @browser.ie?
602
657
  assert_equal "7", @browser.version
603
658
  assert @browser.mobile?
659
+ assert @browser.windows_phone?
660
+ assert ! @browser.windows_mobile?
604
661
  assert ! @browser.tablet?
605
662
  end
606
663
 
@@ -610,6 +667,19 @@ class BrowserTest < Test::Unit::TestCase
610
667
  assert @browser.ie?
611
668
  assert_equal "10", @browser.version
612
669
  assert @browser.mobile?
670
+ assert @browser.windows_phone?
671
+ assert ! @browser.windows_mobile?
672
+ assert ! @browser.tablet?
673
+ end
674
+
675
+ def test_windows_mobile
676
+ @browser.ua = WINDOWS_PHONE8
677
+
678
+ assert @browser.ie?
679
+ assert_equal "10", @browser.version
680
+ assert @browser.mobile?
681
+ assert @browser.windows_phone?
682
+ assert ! @browser.windows_mobile?
613
683
  assert ! @browser.tablet?
614
684
  end
615
685
 
@@ -661,6 +731,48 @@ class BrowserTest < Test::Unit::TestCase
661
731
  assert ! @browser.mobile?
662
732
  end
663
733
 
734
+ def test_nintendo_wii
735
+ @browser.ua = NINTENDO_WII
736
+
737
+ assert @browser.console?
738
+ assert @browser.nintendo?
739
+ end
740
+
741
+ def test_nintendo_wii_u
742
+ @browser.ua = NINTENDO_WIIU
743
+
744
+ assert @browser.console?
745
+ assert @browser.nintendo?
746
+ end
747
+
748
+ def test_playstation_3
749
+ @browser.ua = PLAYSTATION3
750
+
751
+ assert @browser.console?
752
+ assert @browser.playstation?
753
+ end
754
+
755
+ def test_playstation_4
756
+ @browser.ua = PLAYSTATION4
757
+
758
+ assert @browser.console?
759
+ assert @browser.playstation?
760
+ end
761
+
762
+ def test_xbox_360
763
+ @browser.ua = XBOX360
764
+
765
+ assert @browser.console?
766
+ assert @browser.xbox?
767
+ end
768
+
769
+ def test_xbox_one
770
+ @browser.ua = XBOXONE
771
+
772
+ assert @browser.console?
773
+ assert @browser.xbox?
774
+ end
775
+
664
776
  def test_remove_duplicate_items
665
777
  @browser.ua = SAFARI
666
778
  assert_equal ["safari"], @browser.meta.select {|item| item == "safari" }
@@ -670,4 +782,22 @@ class BrowserTest < Test::Unit::TestCase
670
782
  @browser.ua = SAFARI
671
783
  assert_equal @browser.meta, @browser.to_a
672
784
  end
785
+
786
+ def test_bots
787
+ @browser.ua = GOOGLE_BOT
788
+ assert @browser.bot?
789
+
790
+ @browser.ua = MSN_BOT
791
+ assert @browser.bot?
792
+
793
+ @browser.ua = FACEBOOK_BOT
794
+ assert @browser.bot?
795
+
796
+ # Many bots actually report empty ua strings.
797
+ @browser.ua = ''
798
+ assert @browser.bot?
799
+
800
+ @browser.ua = CHROME
801
+ assert ! @browser.bot?
802
+ end
673
803
  end
@@ -9,6 +9,11 @@ class MiddlewareTest < Test::Unit::TestCase
9
9
  Rails.application
10
10
  end
11
11
 
12
+ def test_redirect_uses_302
13
+ get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6"}
14
+ assert_equal 302, last_response.status
15
+ end
16
+
12
17
  def test_redirect_ie6_to_upgrade_path
13
18
  get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6"}
14
19
  follow_redirect!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2013-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-meta
@@ -81,6 +81,8 @@ files:
81
81
  - lib/browser/meta/platform.rb
82
82
  - lib/browser/meta/safari.rb
83
83
  - lib/browser/meta/webkit.rb
84
+ - lib/browser/methods/bots.rb
85
+ - lib/browser/methods/consoles.rb
84
86
  - lib/browser/methods/devices.rb
85
87
  - lib/browser/methods/ie.rb
86
88
  - lib/browser/methods/language.rb
@@ -115,8 +117,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  version: '0'
116
118
  requirements: []
117
119
  rubyforge_project:
118
- rubygems_version: 2.1.0
120
+ rubygems_version: 2.0.3
119
121
  signing_key:
120
122
  specification_version: 4
121
123
  summary: Do some browser detection with Ruby.
122
124
  test_files: []
125
+ has_rdoc: