browser 1.1.0 → 2.0.0.rc1

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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +2 -0
  3. data/.hound.yml +26 -6
  4. data/.rubocop.yml +26 -6
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +177 -41
  7. data/Rakefile +1 -1
  8. data/bin/rake +16 -0
  9. data/bot_exceptions.yml +1 -0
  10. data/bots.yml +188 -192
  11. data/browser.gemspec +14 -28
  12. data/languages.yml +54 -54
  13. data/lib/browser.rb +82 -202
  14. data/lib/browser/accept_language.rb +47 -0
  15. data/lib/browser/action_controller.rb +1 -1
  16. data/lib/browser/base.rb +159 -0
  17. data/lib/browser/blackberry.rb +21 -0
  18. data/lib/browser/bot.rb +63 -0
  19. data/lib/browser/chrome.rb +23 -0
  20. data/lib/browser/detect_version.rb +19 -0
  21. data/lib/browser/device.rb +175 -0
  22. data/lib/browser/device/base.rb +11 -0
  23. data/lib/browser/device/blackberry_playbook.rb +17 -0
  24. data/lib/browser/device/ipad.rb +17 -0
  25. data/lib/browser/device/iphone.rb +17 -0
  26. data/lib/browser/device/ipod_touch.rb +17 -0
  27. data/lib/browser/device/kindle.rb +17 -0
  28. data/lib/browser/device/kindle_fire.rb +17 -0
  29. data/lib/browser/device/playstation3.rb +17 -0
  30. data/lib/browser/device/playstation4.rb +17 -0
  31. data/lib/browser/device/psp.rb +17 -0
  32. data/lib/browser/device/psvita.rb +17 -0
  33. data/lib/browser/device/surface.rb +23 -0
  34. data/lib/browser/device/tv.rb +17 -0
  35. data/lib/browser/device/unknown.rb +17 -0
  36. data/lib/browser/device/wii.rb +17 -0
  37. data/lib/browser/device/wiiu.rb +17 -0
  38. data/lib/browser/device/xbox_360.rb +17 -0
  39. data/lib/browser/device/xbox_one.rb +17 -0
  40. data/lib/browser/edge.rb +19 -0
  41. data/lib/browser/firefox.rb +19 -0
  42. data/lib/browser/generic.rb +32 -0
  43. data/lib/browser/internet_explorer.rb +61 -0
  44. data/lib/browser/meta/base.rb +1 -1
  45. data/lib/browser/meta/device.rb +9 -0
  46. data/lib/browser/meta/generic_browser.rb +1 -1
  47. data/lib/browser/meta/id.rb +1 -1
  48. data/lib/browser/meta/ie.rb +1 -1
  49. data/lib/browser/meta/ios.rb +2 -2
  50. data/lib/browser/meta/mobile.rb +2 -2
  51. data/lib/browser/meta/modern.rb +1 -1
  52. data/lib/browser/meta/platform.rb +2 -2
  53. data/lib/browser/meta/proxy.rb +1 -1
  54. data/lib/browser/meta/safari.rb +1 -1
  55. data/lib/browser/meta/tablet.rb +9 -0
  56. data/lib/browser/meta/webkit.rb +1 -1
  57. data/lib/browser/middleware.rb +1 -1
  58. data/lib/browser/middleware/context.rb +2 -2
  59. data/lib/browser/middleware/context/additions.rb +1 -1
  60. data/lib/browser/middleware/context/url_methods.rb +3 -3
  61. data/lib/browser/nokia.rb +19 -0
  62. data/lib/browser/opera.rb +19 -0
  63. data/lib/browser/phantom_js.rb +19 -0
  64. data/lib/browser/platform.rb +152 -0
  65. data/lib/browser/platform/adobe_air.rb +21 -0
  66. data/lib/browser/platform/android.rb +21 -0
  67. data/lib/browser/platform/base.rb +15 -0
  68. data/lib/browser/platform/blackberry.rb +21 -0
  69. data/lib/browser/platform/chrome_os.rb +21 -0
  70. data/lib/browser/platform/firefox_os.rb +21 -0
  71. data/lib/browser/platform/ios.rb +28 -0
  72. data/lib/browser/platform/linux.rb +21 -0
  73. data/lib/browser/platform/mac.rb +21 -0
  74. data/lib/browser/platform/other.rb +21 -0
  75. data/lib/browser/platform/windows.rb +21 -0
  76. data/lib/browser/platform/windows_mobile.rb +21 -0
  77. data/lib/browser/platform/windows_phone.rb +21 -0
  78. data/lib/browser/rails.rb +3 -2
  79. data/lib/browser/safari.rb +22 -0
  80. data/lib/browser/testing.rb +23 -0
  81. data/lib/browser/uc_browser.rb +19 -0
  82. data/lib/browser/version.rb +2 -7
  83. data/search_engines.yml +5 -5
  84. data/test/browser_test.rb +71 -172
  85. data/test/middleware_test.rb +7 -7
  86. data/test/sample_app.rb +3 -3
  87. data/test/test_helper.rb +11 -10
  88. data/test/ua.yml +15 -26
  89. data/test/ua_bots.yml +27 -0
  90. data/test/ua_search_engines.yml +6 -0
  91. data/test/unit/accept_language_test.rb +92 -0
  92. data/test/unit/adobe_air_test.rb +5 -10
  93. data/test/unit/android_test.rb +44 -49
  94. data/test/unit/blackberry_test.rb +55 -77
  95. data/test/unit/bots_test.rb +52 -84
  96. data/test/unit/chrome_test.rb +48 -42
  97. data/test/unit/console_test.rb +4 -62
  98. data/test/unit/device_test.rb +193 -0
  99. data/test/unit/firefox_test.rb +32 -27
  100. data/test/unit/ie_test.rb +223 -238
  101. data/test/unit/ios_app_test.rb +3 -3
  102. data/test/unit/ios_test.rb +87 -94
  103. data/test/unit/kindle_test.rb +10 -24
  104. data/test/unit/nokia_test.rb +3 -7
  105. data/test/unit/opera_test.rb +20 -30
  106. data/test/unit/platform_test.rb +161 -0
  107. data/test/unit/proxy_test.rb +3 -3
  108. data/test/unit/safari_test.rb +66 -0
  109. data/test/unit/uc_browser_test.rb +3 -7
  110. data/test/unit/windows_phone_test.rb +19 -40
  111. data/test/unit/windows_test.rb +32 -34
  112. metadata +73 -28
  113. data/lib/browser/methods/blackberry.rb +0 -51
  114. data/lib/browser/methods/bots.rb +0 -35
  115. data/lib/browser/methods/consoles.rb +0 -43
  116. data/lib/browser/methods/devices.rb +0 -41
  117. data/lib/browser/methods/ie.rb +0 -99
  118. data/lib/browser/methods/language.rb +0 -16
  119. data/lib/browser/methods/mobile.rb +0 -35
  120. data/lib/browser/methods/platform.rb +0 -152
  121. data/lib/browser/methods/proxy.rb +0 -8
  122. data/lib/browser/methods/tv.rb +0 -8
@@ -0,0 +1,11 @@
1
+ module Browser
2
+ class Device
3
+ class Base
4
+ attr_reader :ua
5
+
6
+ def initialize(ua)
7
+ @ua = ua
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class BlackBerryPlaybook < Base
4
+ def id
5
+ :playbook
6
+ end
7
+
8
+ def name
9
+ "BlackBerry Playbook"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /PlayBook.*?RIM Tablet/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Ipad < Base
4
+ def id
5
+ :ipad
6
+ end
7
+
8
+ def name
9
+ "iPad"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /iPad/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Iphone < Base
4
+ def id
5
+ :iphone
6
+ end
7
+
8
+ def name
9
+ "iPhone"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /iPhone/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class IpodTouch < Base
4
+ def id
5
+ :ipod_touch
6
+ end
7
+
8
+ def name
9
+ "iPod Touch"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /iPod/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Kindle < Base
4
+ def id
5
+ :kindle
6
+ end
7
+
8
+ def name
9
+ "Kindle"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Kindle/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class KindleFire < Base
4
+ def id
5
+ :kindle_fire
6
+ end
7
+
8
+ def name
9
+ "Kindle Fire"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Kindle Fire|KFTT/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class PlayStation3 < Base
4
+ def id
5
+ :ps3
6
+ end
7
+
8
+ def name
9
+ "PlayStation 3"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /PLAYSTATION 3/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class PlayStation4 < Base
4
+ def id
5
+ :ps4
6
+ end
7
+
8
+ def name
9
+ "PlayStation 4"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /PLAYSTATION 4/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class PSP < Base
4
+ def id
5
+ :psp
6
+ end
7
+
8
+ def name
9
+ "PlayStation Portable"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /PlayStation Portable/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class PSVita < Base
4
+ def id
5
+ :psvita
6
+ end
7
+
8
+ def name
9
+ "PlayStation Vita"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Playstation Vita/
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module Browser
2
+ class Device
3
+ class Surface < Base
4
+ def id
5
+ :surface
6
+ end
7
+
8
+ def name
9
+ "Microsoft Surface"
10
+ end
11
+
12
+ def match?
13
+ platform.windows_rt? && !!(ua =~ /Touch/)
14
+ end
15
+
16
+ private
17
+
18
+ def platform
19
+ @platform ||= Platform.new(ua)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class TV < Base
4
+ def id
5
+ :tv
6
+ end
7
+
8
+ def name
9
+ "TV"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /(tv|Android.*?ADT-1|Nexus Player)/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Unknown < Base
4
+ def id
5
+ :unknown
6
+ end
7
+
8
+ def name
9
+ "Unknown"
10
+ end
11
+
12
+ def match?
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Wii < Base
4
+ def id
5
+ :wii
6
+ end
7
+
8
+ def name
9
+ "Nintendo Wii"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Nintendo Wii/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class WiiU < Base
4
+ def id
5
+ :wiiu
6
+ end
7
+
8
+ def name
9
+ "Nintendo WiiU"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Nintendo WiiU/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class Xbox360 < Base
4
+ def id
5
+ :xbox_360
6
+ end
7
+
8
+ def name
9
+ "Xbox 360"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Xbox/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Browser
2
+ class Device
3
+ class XboxOne < Base
4
+ def id
5
+ :xbox_one
6
+ end
7
+
8
+ def name
9
+ "Xbox One"
10
+ end
11
+
12
+ def match?
13
+ ua =~ /Xbox One/i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class Edge < InternetExplorer
3
+ def id
4
+ :edge
5
+ end
6
+
7
+ def name
8
+ "Microsoft Edge"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[Edge/([\d.]+)], 1] || super
13
+ end
14
+
15
+ def match?
16
+ ua =~ %r[(Edge/[\d.]+|Trident/8)]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class Firefox < Base
3
+ def id
4
+ :firefox
5
+ end
6
+
7
+ def name
8
+ "Firefox"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[(?:Firefox|FxiOS)/([\d.]+)], 1]
13
+ end
14
+
15
+ def match?
16
+ ua =~ /Firefox|FxiOS/
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module Browser
2
+ class Generic < Base
3
+ NAMES = {
4
+ "QuickTime" => "QuickTime",
5
+ "CoreMedia" => "Apple CoreMedia"
6
+ }
7
+
8
+ def id
9
+ :generic
10
+ end
11
+
12
+ def name
13
+ infer_name || "Generic Browser"
14
+ end
15
+
16
+ def full_version
17
+ ua[%r[(?:QuickTime)/([\d.]+)], 1] ||
18
+ ua[%r[CoreMedia v([\d.]+)], 1] ||
19
+ "0.0"
20
+ end
21
+
22
+ def match?
23
+ true
24
+ end
25
+
26
+ private
27
+
28
+ def infer_name
29
+ (NAMES.find {|key, _| ua.include?(key) } || []).last
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ module Browser
2
+ class InternetExplorer < Base
3
+ # https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
4
+ TRIDENT_MAPPING = {
5
+ "4.0" => "8",
6
+ "5.0" => "9",
7
+ "6.0" => "10",
8
+ "7.0" => "11",
9
+ "8.0" => "12"
10
+ }
11
+
12
+ def id
13
+ :ie
14
+ end
15
+
16
+ def name
17
+ "Internet Explorer"
18
+ end
19
+
20
+ def full_version
21
+ "#{ie_version}.0"
22
+ end
23
+
24
+ def msie_full_version
25
+ (ua.match(%r{MSIE ([\d.]+)|Trident/.*?; rv:([\d.]+)}) && ($1 || $2)) ||
26
+ "0.0"
27
+ end
28
+
29
+ def msie_version
30
+ msie_full_version.split(".").first
31
+ end
32
+
33
+ def match?
34
+ msie? || modern_ie?
35
+ end
36
+
37
+ # Detect if IE is running in compatibility mode.
38
+ def compatibility_view?
39
+ trident_version && msie_version.to_i < (trident_version.to_i + 4)
40
+ end
41
+
42
+ private
43
+
44
+ def ie_version
45
+ TRIDENT_MAPPING[trident_version] || msie_version
46
+ end
47
+
48
+ # Return the trident version.
49
+ def trident_version
50
+ ua.match(%r[Trident/([0-9.]+)]) && $1
51
+ end
52
+
53
+ def msie?
54
+ ua =~ /MSIE/ && ua !~ /Opera/
55
+ end
56
+
57
+ def modern_ie?
58
+ ua =~ %r[Trident/.*?; rv:(.*?)]
59
+ end
60
+ end
61
+ end