browser 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Base
4
4
  # Set the browser instance.
@@ -0,0 +1,9 @@
1
+ module Browser
2
+ module Meta
3
+ class Device < Base
4
+ def meta
5
+ browser.device.id
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class GenericBrowser < Base
4
4
  def meta
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Id < Base
4
4
  def meta
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class IE < Base
4
4
  def version
@@ -1,8 +1,8 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class IOS < Base
4
4
  def meta
5
- "ios" if browser.ios?
5
+ "ios" if browser.platform.ios?
6
6
  end
7
7
  end
8
8
  end
@@ -1,8 +1,8 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Mobile < Base
4
4
  def meta
5
- "mobile" if browser.mobile?
5
+ "mobile" if browser.device.mobile?
6
6
  end
7
7
  end
8
8
  end
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Modern < Base
4
4
  def meta
@@ -1,8 +1,8 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Platform < Base
4
4
  def meta
5
- browser.platform
5
+ browser.platform.id
6
6
  end
7
7
  end
8
8
  end
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Proxy < Base
4
4
  def meta
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Safari < Base
4
4
  def meta
@@ -0,0 +1,9 @@
1
+ module Browser
2
+ module Meta
3
+ class Tablet < Base
4
+ def meta
5
+ "tablet" if browser.device.tablet?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  module Meta
3
3
  class Webkit < Base
4
4
  def meta
@@ -1,6 +1,6 @@
1
1
  require "uri"
2
2
 
3
- class Browser
3
+ module Browser
4
4
  class Middleware
5
5
  # Detect the most common assets.
6
6
  ASSETS_REGEX = /\.(css|png|jpe?g|gif|js|svg|ico|flv|mov|m4v|ogg|swf)\z/i
@@ -1,4 +1,4 @@
1
- class Browser
1
+ module Browser
2
2
  class Middleware
3
3
  class Context
4
4
  attr_reader :browser, :request
@@ -7,7 +7,7 @@ class Browser
7
7
  @request = request
8
8
 
9
9
  @browser = Browser.new(
10
- ua: request.user_agent,
10
+ request.user_agent,
11
11
  accept_language: request.env["HTTP_ACCEPT_LANGUAGE"]
12
12
  )
13
13
  end
@@ -1,6 +1,6 @@
1
1
  require "browser/middleware/context/url_methods"
2
2
 
3
- class Browser
3
+ module Browser
4
4
  class Middleware
5
5
  class Context
6
6
  module Additions
@@ -1,11 +1,11 @@
1
- class Browser
1
+ module Browser
2
2
  class Middleware
3
3
  class Context
4
4
  module UrlMethods
5
5
  def default_url_options
6
6
  Rails.configuration.browser.default_url_options ||
7
- Rails.configuration.action_mailer.default_url_options ||
8
- {}
7
+ Rails.configuration.action_mailer.default_url_options ||
8
+ {}
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class Nokia < Base
3
+ def id
4
+ :nokia
5
+ end
6
+
7
+ def name
8
+ "Nokia S40 Ovi Browser"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[S40OviBrowser/([\d.]+)], 1]
13
+ end
14
+
15
+ def match?
16
+ ua =~ /S40OviBrowser/
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class Opera < Base
3
+ def id
4
+ :opera
5
+ end
6
+
7
+ def name
8
+ "Opera"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[OPR/([\d.]+)], 1] || ua[%r[Version/([\d.]+)], 1]
13
+ end
14
+
15
+ def match?
16
+ ua =~ /(Opera|OPR)/
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Browser
2
+ class PhantomJS < Base
3
+ def id
4
+ :phantom_js
5
+ end
6
+
7
+ def name
8
+ "PhantomJS"
9
+ end
10
+
11
+ def full_version
12
+ ua[%r[PhantomJS/([\d.]+)], 1]
13
+ end
14
+
15
+ def match?
16
+ ua =~ /PhantomJS/
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,152 @@
1
+ module Browser
2
+ class Platform
3
+ include DetectVersion
4
+
5
+ attr_reader :ua
6
+
7
+ def initialize(ua)
8
+ @ua = ua
9
+ end
10
+
11
+ def subject
12
+ @subject ||= [
13
+ AdobeAir.new(ua),
14
+ ChromeOS.new(ua),
15
+ WindowsMobile.new(ua),
16
+ WindowsPhone.new(ua),
17
+ Android.new(ua),
18
+ BlackBerry.new(ua),
19
+ IOS.new(ua),
20
+ Mac.new(ua),
21
+ FirefoxOS.new(ua),
22
+ Windows.new(ua),
23
+ Linux.new(ua),
24
+ Other.new(ua)
25
+ ].find(&:match?)
26
+ end
27
+
28
+ def adobe_air?
29
+ id == :adobe_air
30
+ end
31
+
32
+ def chrome_os?
33
+ id == :chrome_os
34
+ end
35
+
36
+ def android?(expected_version = nil)
37
+ id == :android && detect_version?(version, expected_version)
38
+ end
39
+
40
+ def other?
41
+ id == :other
42
+ end
43
+
44
+ def linux?
45
+ id == :linux
46
+ end
47
+
48
+ def mac?
49
+ id == :mac
50
+ end
51
+
52
+ def windows?
53
+ id == :windows
54
+ end
55
+
56
+ def firefox_os?
57
+ id == :firefox_os
58
+ end
59
+
60
+ def ios?(expected_version = nil)
61
+ id == :ios && detect_version?(version, expected_version)
62
+ end
63
+
64
+ def blackberry?(expected_version = nil)
65
+ id == :blackberry && detect_version?(version, expected_version)
66
+ end
67
+
68
+ def windows_phone?(expected_version = nil)
69
+ id == :windows_phone && detect_version?(version, expected_version)
70
+ end
71
+
72
+ def windows_mobile?(expected_version = nil)
73
+ id == :windows_mobile && detect_version?(version, expected_version)
74
+ end
75
+
76
+ def id
77
+ subject.id
78
+ end
79
+
80
+ def version
81
+ subject.version
82
+ end
83
+
84
+ def name
85
+ subject.name
86
+ end
87
+
88
+ def to_s
89
+ id.to_s
90
+ end
91
+
92
+ def ==(other)
93
+ id == other
94
+ end
95
+
96
+ # Detect if running on iOS app webview.
97
+ def ios_app?
98
+ ios? && !ua.include?("Safari")
99
+ end
100
+
101
+ # Detect if is iOS webview.
102
+ def ios_webview?
103
+ ios_app?
104
+ end
105
+
106
+ # http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
107
+ def windows_xp?
108
+ windows? && !!(ua =~ /Windows NT 5\.[12]/)
109
+ end
110
+
111
+ def windows_vista?
112
+ windows? && !!(ua =~ /Windows NT 6\.0/)
113
+ end
114
+
115
+ def windows7?
116
+ windows? && !!(ua =~ /Windows NT 6\.1/)
117
+ end
118
+
119
+ def windows8?
120
+ windows? && !!(ua =~ /Windows NT 6\.[2-3]/)
121
+ end
122
+
123
+ def windows8_1?
124
+ windows? && !!(ua =~ /Windows NT 6\.3/)
125
+ end
126
+
127
+ def windows10?
128
+ windows? && !!(ua =~ /Windows NT 10/)
129
+ end
130
+
131
+ def windows_rt?
132
+ windows8? && !!(ua =~ /ARM/)
133
+ end
134
+
135
+ # Detect if current platform is Windows in 64-bit architecture.
136
+ def windows_x64?
137
+ !!(windows? && ua =~ /(Win64|x64|Windows NT 5\.2)/)
138
+ end
139
+
140
+ def windows_wow64?
141
+ windows? && !!(ua =~ /WOW64/i)
142
+ end
143
+
144
+ def windows_x64_inclusive?
145
+ windows_x64? || windows_wow64?
146
+ end
147
+
148
+ def windows_touchscreen_desktop?
149
+ windows? && !!(ua =~ /Touch/)
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class AdobeAir < Base
4
+ def match?
5
+ ua =~ /AdobeAIR/
6
+ end
7
+
8
+ def version
9
+ ua[%r[AdobeAIR/([\d.]+)]]
10
+ end
11
+
12
+ def name
13
+ "Adobe AIR"
14
+ end
15
+
16
+ def id
17
+ :adobe_air
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class Android < Base
4
+ def match?
5
+ ua =~ /Android/
6
+ end
7
+
8
+ def name
9
+ "Android"
10
+ end
11
+
12
+ def id
13
+ :android
14
+ end
15
+
16
+ def version
17
+ ua[/Android ([\d.]+)/, 1]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Browser
2
+ class Platform
3
+ class Base
4
+ attr_reader :ua
5
+
6
+ def initialize(ua)
7
+ @ua = ua
8
+ end
9
+
10
+ def match?
11
+ false
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module Browser
2
+ class Platform
3
+ class BlackBerry < Base
4
+ def match?
5
+ ua =~ /BB10|BlackBerry/
6
+ end
7
+
8
+ def name
9
+ "BlackBerry"
10
+ end
11
+
12
+ def id
13
+ :blackberry
14
+ end
15
+
16
+ def version
17
+ ua[%r[(?:Version|BlackBerry[\da-z]+)/([\d.]+)], 1]
18
+ end
19
+ end
20
+ end
21
+ end