browserino 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +56 -27
- data/bin/console +1 -1
- data/lib/browserino/agent.rb +37 -23
- data/lib/browserino/alias.rb +8 -17
- data/lib/browserino/patterns.rb +14 -1
- data/lib/browserino/version.rb +1 -1
- data/lib/browserino.rb +12 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acb8ac94ab2c1c344c35baadf3a9b4c2467895af
|
4
|
+
data.tar.gz: 805054e5d7704be888eee25548d813d8d448ff41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1617ffc71a77a90e28bec8d4fb77a5e94491d0930449d0b68ae689a75f5168669e7c6dbaceee6ca8a905938a90a0e18044ef343bf79f156dbb356f3d6381994f
|
7
|
+
data.tar.gz: 37f7b4465efe6a522c3e1127b0b2911fbbe81ead5039d82ca73f0a35f33ba60723ad055a22fcf4af08df1eda4de43b2bc9b584adb54faf8f5d9964a3a688a396
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,14 @@ This gem aims to provide information about the browser that your visitor is usin
|
|
10
10
|
_dates are in dd-mm-yyyy format_
|
11
11
|
_older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md)_
|
12
12
|
|
13
|
+
#### 04-01-2016 VERSION 2.1.0
|
14
|
+
|
15
|
+
- Small restructuring of test suite
|
16
|
+
- Added bot detection
|
17
|
+
- Added `#bot?` method
|
18
|
+
- Added dynamic method support for bots
|
19
|
+
- Added support for the seamonkey browser
|
20
|
+
|
13
21
|
#### 03-01-2016 VERSION 2.0.0
|
14
22
|
|
15
23
|
- **IMPORTANT** Changed behaviour of all dynamic methods to include version as an argument rather than in the method name.
|
@@ -29,11 +37,6 @@ _older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/brow
|
|
29
37
|
- Changed `#to_s` to add dashes (`-`) between browser names if they have a space
|
30
38
|
- `#to_s` now has an optional (`sep = ''`) parameter that allows info and version numbers to be seperated
|
31
39
|
|
32
|
-
#### 31-12-2015 VERSION 1.5.3
|
33
|
-
|
34
|
-
- Added blackberry support
|
35
|
-
- Added tests for blackberry user agent strings
|
36
|
-
|
37
40
|
## Installation
|
38
41
|
|
39
42
|
*supports ruby 1.9.3+*
|
@@ -96,7 +99,10 @@ agent.system_architecture # => 'x32' or 'x64' if known
|
|
96
99
|
agent.x32? # => true for 32bit UA's
|
97
100
|
agent.x64? # => true for 64bit UA's
|
98
101
|
|
99
|
-
agent.
|
102
|
+
agent.bot_name # => name of bot if the UA was identified as bot
|
103
|
+
agent.bot? # => returns true or false depending on if the agent is a bot
|
104
|
+
|
105
|
+
agent.known? # => true if browser_name or bot_name present
|
100
106
|
agent.mobile? # => true if agent is a mobile device
|
101
107
|
|
102
108
|
# methods to convert object into a String, Array or hash
|
@@ -132,9 +138,9 @@ Browsers can also accept a float / integer to check for a specific version.
|
|
132
138
|
|
133
139
|
### DEPRECATION NOTICE
|
134
140
|
|
135
|
-
**Methods that include a version number in their name (`agent.android4?`) are deprecated as of version 2.0.0. Supply the version as argument instead `agent.android?(4)`**
|
141
|
+
**Methods that include a version number in their name (`agent.android4?`) are deprecated as of version 2.0.0. Supply the version as argument instead `agent.android?(4)` or `agent.android('Ice Cream Sandwich')`**
|
136
142
|
|
137
|
-
Supported systems
|
143
|
+
##### Supported systems
|
138
144
|
|
139
145
|
```ruby
|
140
146
|
agent.android?
|
@@ -182,7 +188,7 @@ agent.not.linux?
|
|
182
188
|
|
183
189
|
The `#windows?`, `#macintosh?` and `#blackberry?` each have a shortcut method to allow for easier access, `#win?`, `#osx?`, `#bb?`
|
184
190
|
|
185
|
-
Supported browsers
|
191
|
+
##### Supported browsers
|
186
192
|
|
187
193
|
```ruby
|
188
194
|
agent.opera?
|
@@ -196,42 +202,56 @@ agent.firefox?
|
|
196
202
|
agent.chrome?
|
197
203
|
agent.safari?
|
198
204
|
|
199
|
-
# or with the .not method
|
205
|
+
# or with the .not method (v1.4.0+)
|
200
206
|
|
201
207
|
agent.not.opera?
|
202
208
|
agent.not.maxthon?
|
203
209
|
# etc etc...
|
210
|
+
```
|
204
211
|
|
212
|
+
##### Supported bots
|
213
|
+
```ruby
|
214
|
+
agent.msnbot?
|
215
|
+
agent.yahoo_slurp?
|
216
|
+
agent.googlebot?
|
217
|
+
agent.bingbot?
|
218
|
+
|
219
|
+
# or with the .not method (v1.4.0+)
|
220
|
+
agent.not.msnbot?
|
221
|
+
agent.not.yahoo_slurp?
|
222
|
+
# etc etc...
|
205
223
|
```
|
206
224
|
|
207
225
|
## Development
|
208
226
|
|
209
227
|
The tests are dynamically produced and quite easy to write.
|
210
228
|
|
211
|
-
The __/spec/
|
212
|
-
tests will
|
229
|
+
The __/spec/user_agents_browsers.rb__ and __/spec/user_agents_bots.rb__ actually contain the test cases for both browsers and bots respectively, here you can see how they are setup and all you simply have to do is read the UA yourself and fill in the correct information for the test to run.
|
230
|
+
the tests will lowercase most of the input to make sure there's no case mismatches, this happens mainly on the `*_name` properties
|
213
231
|
|
214
232
|
If I wanted to add a test case for a different browser for instance (just picking a random FF on windows that is already in the tests)
|
215
233
|
|
216
234
|
```ruby
|
217
235
|
module UserAgents
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
236
|
+
module Browsers
|
237
|
+
FIREFOX = {
|
238
|
+
win: {
|
239
|
+
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1' => {
|
240
|
+
browser_name: 'Firefox',
|
241
|
+
browser_version: '40.1',
|
242
|
+
engine_name: 'Gecko',
|
243
|
+
engine_version: '40.0',
|
244
|
+
system_name: ['windows', '7'],
|
245
|
+
system_version: '6.1',
|
246
|
+
system_architecture: 'x64',
|
247
|
+
x64?: true,
|
248
|
+
x32?: false,
|
249
|
+
known?: true,
|
250
|
+
mobile: false
|
251
|
+
}
|
232
252
|
}
|
233
253
|
}
|
234
|
-
|
254
|
+
end
|
235
255
|
end
|
236
256
|
```
|
237
257
|
|
@@ -246,6 +266,7 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
|
|
246
266
|
'opera_mini'
|
247
267
|
'bolt'
|
248
268
|
'ucbrowser'
|
269
|
+
'seamonkey'
|
249
270
|
'maxthon'
|
250
271
|
```
|
251
272
|
|
@@ -256,6 +277,14 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
|
|
256
277
|
'trident'
|
257
278
|
```
|
258
279
|
|
280
|
+
#### bot_name examples
|
281
|
+
```ruby
|
282
|
+
'googlebot'
|
283
|
+
'yahoo_slurp'
|
284
|
+
'msnbot'
|
285
|
+
'bingbot'
|
286
|
+
```
|
287
|
+
|
259
288
|
#### system_name examples
|
260
289
|
|
261
290
|
_The main reason for not having Linux distro's / versions is because of the fact that there are MANY different distro's with no real structured release system. The best I can do here is allow a `linux?` system to be found atleast_
|
data/bin/console
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "browserino"
|
5
5
|
require "pry"
|
6
|
-
ua = '
|
6
|
+
ua = 'msnbot/2.1'
|
7
7
|
@agent = Browserino::parse(ua)
|
8
8
|
|
9
9
|
puts "> @agent variable available parsed with: '#{ua}'\n\n"
|
data/lib/browserino/agent.rb
CHANGED
@@ -6,16 +6,21 @@ module Browserino
|
|
6
6
|
@not = false
|
7
7
|
|
8
8
|
cleansed_ua = Browserino::cleanse @ua
|
9
|
-
name = Browserino::
|
10
|
-
|
9
|
+
name = Browserino::agent_id cleansed_ua
|
10
|
+
info = {
|
11
11
|
browser_name: name,
|
12
12
|
browser_version: Browser::version(cleansed_ua, PATTERNS[:browser][name]),
|
13
13
|
engine_name: Engine::name(cleansed_ua),
|
14
14
|
engine_version: Engine::version(cleansed_ua),
|
15
15
|
system_name: OperatingSystem::name(cleansed_ua),
|
16
16
|
system_version: OperatingSystem::version(cleansed_ua),
|
17
|
-
system_architecture: OperatingSystem::architecture(cleansed_ua)
|
18
|
-
|
17
|
+
system_architecture: OperatingSystem::architecture(cleansed_ua),
|
18
|
+
bot_name: nil
|
19
|
+
}
|
20
|
+
if Browserino::PATTERNS[:bot].include? name
|
21
|
+
info.merge!({browser_name: nil, browser_version: nil, bot_name: name})
|
22
|
+
end
|
23
|
+
@info = Browserino::check_for_aliases(info)
|
19
24
|
end
|
20
25
|
|
21
26
|
def browser_name
|
@@ -66,52 +71,60 @@ module Browserino
|
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
74
|
+
def bot_name
|
75
|
+
with_valid(@info[:bot_name]) do |v|
|
76
|
+
v.to_s.downcase.gsub(/_/, ' ')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
69
80
|
def ua
|
70
81
|
@ua
|
71
82
|
end
|
72
83
|
|
73
84
|
def known?
|
74
|
-
|
75
|
-
@not = false
|
76
|
-
res
|
85
|
+
allow_inverted_return (browser_name != @unknown || bot_name != @unknown)
|
77
86
|
end
|
78
87
|
|
79
88
|
def mobile?
|
80
|
-
allow_inverted_return !!(ua =~
|
89
|
+
allow_inverted_return !!(ua =~ Browserino::PATTERNS[:operating_system][:mobile])
|
81
90
|
end
|
82
91
|
|
83
92
|
def x64?
|
84
|
-
allow_inverted_return
|
93
|
+
allow_inverted_return system_architecture == 'x64'
|
85
94
|
end
|
86
95
|
|
87
96
|
def x32?
|
88
|
-
allow_inverted_return
|
97
|
+
allow_inverted_return system_architecture == 'x32'
|
89
98
|
end
|
90
99
|
|
91
100
|
def osx?(*arg)
|
92
|
-
macintosh?(*arg)
|
101
|
+
allow_inverted_return macintosh?(*arg)
|
93
102
|
end
|
94
103
|
|
95
104
|
def win?(*arg)
|
96
|
-
windows?(*arg)
|
105
|
+
allow_inverted_return windows?(*arg)
|
97
106
|
end
|
98
107
|
|
99
108
|
def bb?(*arg)
|
100
|
-
blackberry?(*arg)
|
109
|
+
allow_inverted_return blackberry?(*arg)
|
110
|
+
end
|
111
|
+
|
112
|
+
def bot?
|
113
|
+
allow_inverted_return (bot_name.nil? ? false : true)
|
101
114
|
end
|
102
115
|
|
103
116
|
def method_missing(method_sym, *args, &block)
|
104
117
|
name = method_sym.to_s.gsub('?', '')
|
105
|
-
res = case
|
118
|
+
res = case agent_or_system?(method_sym)
|
106
119
|
when :system then correct_system?(name, *args)
|
107
|
-
when :
|
120
|
+
when :agent then correct_agent?(name, *args)
|
108
121
|
else super
|
109
122
|
end
|
110
123
|
allow_inverted_return res
|
111
124
|
end
|
112
125
|
|
113
126
|
def respond_to?(method_sym)
|
114
|
-
|
127
|
+
agent_or_system?(method_sym).nil? ? false : true
|
115
128
|
end
|
116
129
|
|
117
130
|
def not
|
@@ -178,8 +191,9 @@ module Browserino
|
|
178
191
|
end
|
179
192
|
end
|
180
193
|
|
181
|
-
def
|
182
|
-
|
194
|
+
def correct_agent?(name, version = nil)
|
195
|
+
name = name.gsub(/_/, ' ')
|
196
|
+
browser_equal = (name == browser_name || name == bot_name)
|
183
197
|
if version
|
184
198
|
browser_equal && compare_versions(version, browser_version)
|
185
199
|
else
|
@@ -187,14 +201,14 @@ module Browserino
|
|
187
201
|
end
|
188
202
|
end
|
189
203
|
|
190
|
-
def
|
191
|
-
name = method_sym.to_s.gsub('?', '')
|
204
|
+
def agent_or_system?(method_sym)
|
205
|
+
name = method_sym.to_s.gsub('?', '')
|
192
206
|
sys = Browserino::Mapping.constants(true).include?(name.upcase.to_sym)
|
193
|
-
|
207
|
+
agent = Browserino::PATTERNS[:browser].merge(Browserino::PATTERNS[:bot]).keys.include?(name.to_sym)
|
194
208
|
if sys
|
195
209
|
:system
|
196
|
-
elsif
|
197
|
-
:
|
210
|
+
elsif agent
|
211
|
+
:agent
|
198
212
|
else
|
199
213
|
nil
|
200
214
|
end
|
data/lib/browserino/alias.rb
CHANGED
@@ -1,30 +1,21 @@
|
|
1
1
|
module Browserino
|
2
2
|
ALIAS = {
|
3
3
|
browser_name: {
|
4
|
-
'ie' => ['msie']
|
5
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
|
6
|
-
},
|
7
|
-
browser_version: {
|
8
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
|
4
|
+
'ie' => ['msie']
|
9
5
|
},
|
6
|
+
browser_version: {},
|
10
7
|
engine_name: {
|
11
|
-
'webkit' => ['applewebkit']
|
12
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
|
13
|
-
},
|
14
|
-
engine_version: {
|
15
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
|
8
|
+
'webkit' => ['applewebkit']
|
16
9
|
},
|
10
|
+
engine_version: {},
|
17
11
|
system_name: {
|
18
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil],
|
19
12
|
'linux' => ['ubuntu', 'x11']
|
20
13
|
},
|
21
|
-
system_version: {
|
22
|
-
Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
|
23
|
-
},
|
14
|
+
system_version: {},
|
24
15
|
system_architecture: {
|
25
16
|
'x64' => ['64', 'x86_64', 'amd64', 'wow64'],
|
26
|
-
'x32' => ['32', 'i686', 'i383', 'x86_32']
|
27
|
-
|
28
|
-
}
|
17
|
+
'x32' => ['32', 'i686', 'i383', 'x86_32']
|
18
|
+
},
|
19
|
+
bot_name: {}
|
29
20
|
}
|
30
21
|
end
|
data/lib/browserino/patterns.rb
CHANGED
@@ -36,6 +36,11 @@ module Browserino
|
|
36
36
|
version: /(?:(?:ms)?ie\s|rv\:)(?<version>[\d\.b]+)/i
|
37
37
|
},
|
38
38
|
|
39
|
+
seamonkey: {
|
40
|
+
name: /(?<name>seamonkey)/i,
|
41
|
+
version: /seamonkey\/(?<version>[\d\.]+)/i
|
42
|
+
},
|
43
|
+
|
39
44
|
firefox: {
|
40
45
|
name: /(?<name>(?:fire|water)(?:fox|bird)|ice(?:weasel|cat)|netscape)/i,
|
41
46
|
version: /(?:(?:fire|water)(?:fox|bird)|ice(?:weasel|cat)|netscape)[\/]?(?<version>[\d\.]+)/i
|
@@ -52,6 +57,13 @@ module Browserino
|
|
52
57
|
}
|
53
58
|
},
|
54
59
|
|
60
|
+
bot: {
|
61
|
+
googlebot: { name: /(?<name>googlebot)/i },
|
62
|
+
yahoo_slurp: { name: /(?<name>yahoo\!\sslurp)/i },
|
63
|
+
msnbot: { name: /(?<name>msnbot)/i },
|
64
|
+
bingbot: { name: /(?<name>bingbot)/i }
|
65
|
+
},
|
66
|
+
|
55
67
|
engine: {
|
56
68
|
name: /(?<name>((apple)?webkit|presto|gecko|trident))/i,
|
57
69
|
version: /(?:(?:apple)?webkit|presto|rv:|trident)[\/\s]?(?<version>[\d\.]+)/i
|
@@ -60,7 +72,8 @@ module Browserino
|
|
60
72
|
operating_system: {
|
61
73
|
name: /(?<name>windows|macintosh|android|ios|blackberry|linux|ubuntu|x11)/i,
|
62
74
|
version: /(?:nt|mac\sos\sx|android|(cpu\s|i)os|blackberry)\s?(?<version>[\d\._]+)/i,
|
63
|
-
architecture: /(?<architecture>((?:x|x86_|amd|wow)64)|i(3|6)86)/i
|
75
|
+
architecture: /(?<architecture>((?:x|x86_|amd|wow)64)|i(3|6)86)/i,
|
76
|
+
mobile: /bolt|nokia|samsung|mobi(?:le)?|android|ip(?:[ao]d|hone)|bb\d+|blackberry|iemobile|fennec|bada|meego|vodafone|t\-mobile|opera\sm(?:ob|in)i/i
|
64
77
|
}
|
65
78
|
}
|
66
79
|
end
|
data/lib/browserino/version.rb
CHANGED
data/lib/browserino.rb
CHANGED
@@ -16,6 +16,10 @@ require "browserino/browser"
|
|
16
16
|
require "browserino/engine"
|
17
17
|
require "browserino/operating_system"
|
18
18
|
|
19
|
+
# require_relative "../spec/user_agents"
|
20
|
+
# require_relative "../spec/user_agents_bots"
|
21
|
+
# require_relative "../spec/user_agents_browsers"
|
22
|
+
|
19
23
|
module Browserino
|
20
24
|
def self.parse(ua, unknown_alt = Browserino::UNKNOWN)
|
21
25
|
Agent.new(ua, unknown_alt)
|
@@ -37,19 +41,20 @@ module Browserino
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def self.check_for_aliases(hash)
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
hash.inject({}) do |memo, kv|
|
45
|
+
ls = ALIAS[kv.first].select { |k, m| true if m.include?(kv.last) }.keys.first || kv.last
|
46
|
+
memo[kv.first] = ls
|
47
|
+
memo
|
43
48
|
end
|
44
|
-
h
|
45
49
|
end
|
46
50
|
|
47
|
-
def self.
|
51
|
+
def self.agent_id(ua)
|
48
52
|
name = nil
|
49
|
-
|
53
|
+
patterns = PATTERNS[:browser].merge(PATTERNS[:bot])
|
54
|
+
browsers = patterns.keys
|
50
55
|
until browsers.empty? || !name.nil?
|
51
56
|
tmp = browsers.shift
|
52
|
-
name = tmp if (ua.match(
|
57
|
+
name = tmp if (ua.match(patterns[tmp][:name]))
|
53
58
|
end
|
54
59
|
name ||= Browserino::UNKNOWN
|
55
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browserino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sidney Liebrand
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|