browser 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec8732c321a4cf1e50c785d07a242a87e03d599e
4
- data.tar.gz: 7c2632f4db32249d9b3411b7d8c99c24d3ae2ade
3
+ metadata.gz: fc44c2633f9e5ef71751d4dcc64143b13b69e21a
4
+ data.tar.gz: 825edef676789f295746227c52962c6af234295c
5
5
  SHA512:
6
- metadata.gz: aa5e391f8d1ad5deed626581151df145f55ad6f2509592bb591ccf41f3446c0f4a249aa4e38dcfad53612c8a0caec7aafb94f685b1413bc3697bca8c9fd9777e
7
- data.tar.gz: ce44b976d82b7d8ac431fc5333eaf43b5a7141658308b7c549cf56d13ccd64a20fb35738dd84078f1a83cf277ec6e14621971cc5fa2fc1fc25157768353122bb
6
+ metadata.gz: 5086cdd5c553f0daaa49eb8e7aa70050fcb57dc7ed27406658278bf7b845658495c7ebe685e155ea15e1a1aa9baf9edb430a404d6c6119e395521c56d5aef7a2
7
+ data.tar.gz: 98a3c39a62ad4b09630944d0927fec468478361516187fbb8cd1f75d377f62bf65313de5f8679e5f2f1d7bd8ed0a2ae672778f17ec49b21a2c1f1f23e0fb28af
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.2.0
4
+
5
+ - `Browser::Platform#windows?` can now compare versions.
6
+ - `Browser::Platform#mac?` can now compare versions.
7
+ - Detect QQ Browser.
8
+ - Fix issue with Mac user agents that didn't include the version.
9
+
3
10
  ## v2.1.0
4
11
 
5
12
  - Add PrivacyAwareBot, ltx71, Squider and Traackr to bots.
data/README.md CHANGED
@@ -121,6 +121,12 @@ browser.platform.windows_x64_inclusive?
121
121
  browser.platform.windows_xp?
122
122
  ```
123
123
 
124
+ ### What's being detected?
125
+
126
+ - For a list of platform detections, check [lib/browser/platform.rb](https://github.com/fnando/browser/blob/master/lib/browser/platform.rb)
127
+ - For a list of device detections, check [lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
128
+ - For a list of bot detections, check [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
129
+
124
130
  ### What defines a modern browser?
125
131
 
126
132
  The current rules that define a modern browser are pretty loose:
@@ -3,6 +3,7 @@ require "set"
3
3
  require "yaml"
4
4
  require "pathname"
5
5
 
6
+ require "browser/version"
6
7
  require "browser/detect_version"
7
8
  require "browser/accept_language"
8
9
  require "browser/base"
@@ -19,60 +20,15 @@ require "browser/uc_browser"
19
20
  require "browser/nokia"
20
21
  require "browser/micro_messenger"
21
22
  require "browser/weibo"
23
+ require "browser/qq"
22
24
 
23
25
  require "browser/bot"
24
26
  require "browser/middleware"
25
- require "browser/middleware/context"
26
27
  require "browser/rails" if defined?(::Rails)
27
28
 
28
29
  require "browser/platform"
29
- require "browser/platform/base"
30
- require "browser/platform/ios"
31
- require "browser/platform/linux"
32
- require "browser/platform/windows"
33
- require "browser/platform/mac"
34
- require "browser/platform/windows_phone"
35
- require "browser/platform/windows_mobile"
36
- require "browser/platform/firefox_os"
37
- require "browser/platform/blackberry"
38
- require "browser/platform/android"
39
- require "browser/platform/other"
40
- require "browser/platform/chrome_os"
41
- require "browser/platform/adobe_air"
42
-
43
30
  require "browser/device"
44
- require "browser/device/base"
45
- require "browser/device/unknown"
46
- require "browser/device/ipad"
47
- require "browser/device/ipod_touch"
48
- require "browser/device/iphone"
49
- require "browser/device/playstation3"
50
- require "browser/device/playstation4"
51
- require "browser/device/psp"
52
- require "browser/device/psvita"
53
- require "browser/device/kindle"
54
- require "browser/device/kindle_fire"
55
- require "browser/device/wii"
56
- require "browser/device/wiiu"
57
- require "browser/device/blackberry_playbook"
58
- require "browser/device/surface"
59
- require "browser/device/tv"
60
- require "browser/device/xbox_one"
61
- require "browser/device/xbox_360"
62
-
63
- require "browser/meta/base"
64
- require "browser/meta/generic_browser"
65
- require "browser/meta/id"
66
- require "browser/meta/ie"
67
- require "browser/meta/ios"
68
- require "browser/meta/mobile"
69
- require "browser/meta/modern"
70
- require "browser/meta/platform"
71
- require "browser/meta/proxy"
72
- require "browser/meta/safari"
73
- require "browser/meta/webkit"
74
- require "browser/meta/tablet"
75
- require "browser/meta/device"
31
+ require "browser/meta"
76
32
 
77
33
  module Browser
78
34
  EMPTY_STRING = "".freeze
@@ -94,6 +50,7 @@ module Browser
94
50
  InternetExplorer,
95
51
  Firefox,
96
52
  Weibo, # must be placed before Chrome and Safari
53
+ QQ, # must be placed before Chrome and Safari
97
54
  Chrome,
98
55
  Safari,
99
56
  MicroMessenger,
@@ -1,4 +1,23 @@
1
1
  # frozen_string_literal: true
2
+ require "browser/device/base"
3
+ require "browser/device/unknown"
4
+ require "browser/device/ipad"
5
+ require "browser/device/ipod_touch"
6
+ require "browser/device/iphone"
7
+ require "browser/device/playstation3"
8
+ require "browser/device/playstation4"
9
+ require "browser/device/psp"
10
+ require "browser/device/psvita"
11
+ require "browser/device/kindle"
12
+ require "browser/device/kindle_fire"
13
+ require "browser/device/wii"
14
+ require "browser/device/wiiu"
15
+ require "browser/device/blackberry_playbook"
16
+ require "browser/device/surface"
17
+ require "browser/device/tv"
18
+ require "browser/device/xbox_one"
19
+ require "browser/device/xbox_360"
20
+
2
21
  module Browser
3
22
  class Device
4
23
  attr_reader :ua
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require "browser/meta/base"
3
+ require "browser/meta/generic_browser"
4
+ require "browser/meta/id"
5
+ require "browser/meta/ie"
6
+ require "browser/meta/ios"
7
+ require "browser/meta/mobile"
8
+ require "browser/meta/modern"
9
+ require "browser/meta/platform"
10
+ require "browser/meta/proxy"
11
+ require "browser/meta/safari"
12
+ require "browser/meta/webkit"
13
+ require "browser/meta/tablet"
14
+ require "browser/meta/device"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "uri"
3
+ require "browser/middleware/context"
3
4
 
4
5
  module Browser
5
6
  class Middleware
@@ -1,4 +1,18 @@
1
1
  # frozen_string_literal: true
2
+ require "browser/platform/base"
3
+ require "browser/platform/ios"
4
+ require "browser/platform/linux"
5
+ require "browser/platform/windows"
6
+ require "browser/platform/mac"
7
+ require "browser/platform/windows_phone"
8
+ require "browser/platform/windows_mobile"
9
+ require "browser/platform/firefox_os"
10
+ require "browser/platform/blackberry"
11
+ require "browser/platform/android"
12
+ require "browser/platform/other"
13
+ require "browser/platform/chrome_os"
14
+ require "browser/platform/adobe_air"
15
+
2
16
  module Browser
3
17
  class Platform
4
18
  include DetectVersion
@@ -54,12 +68,12 @@ module Browser
54
68
  id == :linux
55
69
  end
56
70
 
57
- def mac?
58
- id == :mac
71
+ def mac?(expected_version = nil)
72
+ id == :mac && detect_version?(version, expected_version)
59
73
  end
60
74
 
61
- def windows?
62
- id == :windows
75
+ def windows?(expected_version = nil)
76
+ id == :windows && detect_version?(version, expected_version)
63
77
  end
64
78
 
65
79
  def firefox_os?
@@ -3,7 +3,7 @@ module Browser
3
3
  class Platform
4
4
  class Mac < Base
5
5
  def version
6
- ua[/Mac OS X\s*([0-9_\.]+)?/, 1].gsub("_", ".")
6
+ (ua[/Mac OS X\s*([0-9_\.]+)?/, 1] || "0").gsub("_", ".")
7
7
  end
8
8
 
9
9
  def name
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module Browser
3
+ class QQ < Base
4
+ def id
5
+ :qq
6
+ end
7
+
8
+ def name
9
+ "QQ Browser"
10
+ end
11
+
12
+ def full_version
13
+ ua[%r[(?:Mobile MQQBrowser)/([\d.]+)]i, 1] ||
14
+ ua[%r[(?:QQ)/([\d.]+)]i, 1] ||
15
+ "0.0"
16
+ end
17
+
18
+ def match?
19
+ ua =~ /QQ/i
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Browser
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
@@ -122,3 +122,5 @@ YANDEX_BROWSER: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537
122
122
  MICRO_MESSENGER: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 MicroMessenger/6.3.15 NetType/3G+ Language/zh_CN'
123
123
  WEIBO_IOS: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H143 Weibo (iPhone7,2__weibo__5.7.1__iphone__os8.4)'
124
124
  WEIBO_ANDROID: 'Mozilla/5.0 (Linux; Android 5.0.2; vivo X5M Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36 Weibo (vivo-vivo X5M__weibo__5.7.1__android__android5.0.2)'
125
+ QQ_BROWSER_IOS: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 QQ/6.3.3.432 V1_IPH_SQ_6.3.3_1_APP_A Pixel/640 Core/UIWebView NetType/WIFI Mem/47'
126
+ QQ_BROWSER_ANDROID: 'Mozilla/5.0 (Linux; Android 5.1.1; SM-N9108V Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036222 Safari/537.36 V1_AND_SQ_6.2.0_320_YYB_D QQ/6.2.0.2655 NetType/WIFI WebP/0.3.0 Pixel/1440'
@@ -22,12 +22,25 @@ class PlatformTest < Minitest::Test
22
22
  assert_equal :other, platform.id
23
23
  end
24
24
 
25
+ test "implements to_s" do
26
+ platform = Browser::Platform.new(Browser["IOS9"])
27
+ assert_equal "ios", platform.to_s
28
+ end
29
+
30
+ test "implements ==" do
31
+ platform = Browser::Platform.new(Browser["IOS9"])
32
+
33
+ assert platform == :ios
34
+ refute platform == :android
35
+ end
36
+
25
37
  test "detect other" do
26
38
  platform = Browser::Platform.new("Other")
27
39
 
28
40
  assert_equal "Other", platform.name
29
41
  assert_equal :other, platform.id
30
42
  assert_equal "0", platform.version
43
+ assert platform.other?
31
44
  end
32
45
 
33
46
  test "detect ios (iPhone)" do
@@ -73,6 +86,12 @@ class PlatformTest < Minitest::Test
73
86
  assert_equal :mac, platform.id
74
87
  assert platform.mac?
75
88
  assert_equal "10.6.4", platform.version
89
+ assert platform.mac?(["=10.6.4"])
90
+ end
91
+
92
+ test "return stub version for Mac user agent without version" do
93
+ platform = Browser::Platform.new("Macintosh")
94
+ assert_equal "0", platform.version
76
95
  end
77
96
 
78
97
  test "detect firefox os" do
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require "test_helper"
3
+
4
+ class QQTest < Minitest::Test
5
+ test "detects QQ browser for iOS" do
6
+ browser = Browser.new(Browser["QQ_BROWSER_IOS"])
7
+
8
+ assert_equal "6.3.3.432", browser.full_version
9
+ assert_equal "QQ Browser", browser.name
10
+ assert_equal :qq, browser.id
11
+ end
12
+
13
+ test "detects QQ browser for Android" do
14
+ browser = Browser.new(Browser["QQ_BROWSER_ANDROID"])
15
+
16
+ assert_equal "6.2", browser.full_version
17
+ assert_equal "QQ Browser", browser.name
18
+ assert_equal :qq, browser.id
19
+ end
20
+ end
@@ -4,6 +4,8 @@ require "test_helper"
4
4
  class MicroMessengerTest < Minitest::Test
5
5
  test "detects weibo iOS" do
6
6
  browser = Browser.new(Browser["WEIBO_IOS"])
7
+
8
+ assert_equal :weibo, browser.id
7
9
  assert browser.weibo?
8
10
  assert_equal "Weibo", browser.name
9
11
  assert_equal "5.7.1", browser.full_version
@@ -11,6 +13,8 @@ class MicroMessengerTest < Minitest::Test
11
13
 
12
14
  test "detects weibo Android" do
13
15
  browser = Browser.new(Browser["WEIBO_ANDROID"])
16
+
17
+ assert_equal :weibo, browser.id
14
18
  assert browser.weibo?
15
19
  assert_equal "Weibo", browser.name
16
20
  assert_equal "5.7.1", browser.full_version
@@ -23,6 +23,7 @@ class WindowsTest < Minitest::Test
23
23
 
24
24
  assert browser.platform.windows?
25
25
  assert_equal browser.platform.version, "5.0"
26
+ assert browser.platform.windows?(["=5.0"])
26
27
  end
27
28
 
28
29
  test "detects windows_2000_sp1" do
@@ -30,6 +31,7 @@ class WindowsTest < Minitest::Test
30
31
 
31
32
  assert browser.platform.windows?
32
33
  assert_equal browser.platform.version, "5.01"
34
+ assert browser.platform.windows?(["=5.01"])
33
35
  end
34
36
 
35
37
  test "detects windows_xp" do
@@ -38,6 +40,7 @@ class WindowsTest < Minitest::Test
38
40
  assert browser.platform.windows?
39
41
  assert browser.platform.windows_xp?
40
42
  assert_equal browser.platform.version, "5.1"
43
+ assert browser.platform.windows?(["=5.1"])
41
44
  end
42
45
 
43
46
  test "detects windows_xp (64-bit)" do
@@ -47,6 +50,7 @@ class WindowsTest < Minitest::Test
47
50
  assert browser.platform.windows_xp?
48
51
  assert browser.platform.windows_x64?
49
52
  assert_equal browser.platform.version, "5.2"
53
+ assert browser.platform.windows?(["=5.2"])
50
54
  end
51
55
 
52
56
  test "detects windows_vista" do
@@ -55,6 +59,7 @@ class WindowsTest < Minitest::Test
55
59
  assert browser.platform.windows?
56
60
  assert browser.platform.windows_vista?
57
61
  assert_equal browser.platform.version, "6.0"
62
+ assert browser.platform.windows?(["=6.0"])
58
63
  end
59
64
 
60
65
  test "detects windows7" do
@@ -63,6 +68,7 @@ class WindowsTest < Minitest::Test
63
68
  assert browser.platform.windows?
64
69
  assert browser.platform.windows7?
65
70
  assert_equal browser.platform.version, "6.1"
71
+ assert browser.platform.windows?(["=6.1"])
66
72
  end
67
73
 
68
74
  test "detects windows8" do
@@ -72,6 +78,7 @@ class WindowsTest < Minitest::Test
72
78
  assert browser.platform.windows8?
73
79
  refute browser.platform.windows8_1?
74
80
  assert_equal browser.platform.version, "6.2"
81
+ assert browser.platform.windows?(["=6.2"])
75
82
  end
76
83
 
77
84
  test "detects windows8.1" do
@@ -81,6 +88,7 @@ class WindowsTest < Minitest::Test
81
88
  assert browser.platform.windows8?
82
89
  assert browser.platform.windows8_1?
83
90
  assert_equal browser.platform.version, "6.3"
91
+ assert browser.platform.windows?(["=6.3"])
84
92
  end
85
93
 
86
94
  test "detects windows10" do
@@ -89,6 +97,7 @@ class WindowsTest < Minitest::Test
89
97
  assert browser.platform.windows?
90
98
  assert browser.platform.windows10?
91
99
  assert_equal browser.platform.version, "10.0"
100
+ assert browser.platform.windows?(["=10.0"])
92
101
  end
93
102
 
94
103
  test "returns name" do
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: 2.1.0
4
+ version: 2.2.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: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,6 +191,7 @@ files:
191
191
  - lib/browser/firefox.rb
192
192
  - lib/browser/generic.rb
193
193
  - lib/browser/internet_explorer.rb
194
+ - lib/browser/meta.rb
194
195
  - lib/browser/meta/base.rb
195
196
  - lib/browser/meta/device.rb
196
197
  - lib/browser/meta/generic_browser.rb
@@ -226,6 +227,7 @@ files:
226
227
  - lib/browser/platform/windows.rb
227
228
  - lib/browser/platform/windows_mobile.rb
228
229
  - lib/browser/platform/windows_phone.rb
230
+ - lib/browser/qq.rb
229
231
  - lib/browser/rails.rb
230
232
  - lib/browser/safari.rb
231
233
  - lib/browser/testing.rb
@@ -261,6 +263,7 @@ files:
261
263
  - test/unit/opera_test.rb
262
264
  - test/unit/platform_test.rb
263
265
  - test/unit/proxy_test.rb
266
+ - test/unit/qq_test.rb
264
267
  - test/unit/safari_test.rb
265
268
  - test/unit/uc_browser_test.rb
266
269
  - test/unit/weibo_test.rb
@@ -319,6 +322,7 @@ test_files:
319
322
  - test/unit/opera_test.rb
320
323
  - test/unit/platform_test.rb
321
324
  - test/unit/proxy_test.rb
325
+ - test/unit/qq_test.rb
322
326
  - test/unit/safari_test.rb
323
327
  - test/unit/uc_browser_test.rb
324
328
  - test/unit/weibo_test.rb