browserino 1.6.0 → 2.0.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 +6 -0
- data/README.md +55 -30
- data/bin/console +2 -2
- data/lib/browserino/agent.rb +56 -29
- data/lib/browserino/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f392dc373a4a65f8091c0a80772e098d93a7132
|
4
|
+
data.tar.gz: f6d67b00f1d80d5a9dad9f99234bded0fa5358be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e4b698e954091489aba295f223d4cb6c48cb7d438db514c04731de975416215420ddcaf261cbe3321ba45dc2d16d1f766516d5a5b3b5ca8730f9e4ad90e5e5
|
7
|
+
data.tar.gz: 562b3de888cf132cfe05200590478293c6bbf20433354dbdd60447259ffa86b823b9b7f6b70e0ed9875d38218219bbbf856dc37ac9c5a6dd4cf4cbef710f5198
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
## CHANGELOG
|
2
2
|
_dates are in dd-mm-yyyy format_
|
3
3
|
|
4
|
+
#### 31-12-2015 VERSION 1.5.2
|
5
|
+
|
6
|
+
- Added user agents
|
7
|
+
- Patterns could falsely identify a 64bit system, made the pattern more strict
|
8
|
+
- using `X11` in a user agent as a synonym to a `#linux?` system
|
9
|
+
|
4
10
|
#### 23-12-2015 VERSION 1.5.1.1
|
5
11
|
|
6
12
|
- Removed print statements from method
|
data/README.md
CHANGED
@@ -10,6 +10,13 @@ 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
|
+
#### 03-01-2016 VERSION 2.0.0
|
14
|
+
|
15
|
+
- **IMPORTANT** Changed behaviour of all dynamic methods to include version as an argument rather than in the method name.
|
16
|
+
- **IMPORTANT** Changed the behaviour of version checking to be more strict
|
17
|
+
- Changed tests to reflect new behaviour
|
18
|
+
- Added convenience methods `#win?`, `#osx?` and `#bb?`
|
19
|
+
|
13
20
|
#### 03-01-2016 VERSION 1.6.0
|
14
21
|
|
15
22
|
- Added more tests
|
@@ -27,15 +34,9 @@ _older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/brow
|
|
27
34
|
- Added blackberry support
|
28
35
|
- Added tests for blackberry user agent strings
|
29
36
|
|
30
|
-
#### 31-12-2015 VERSION 1.5.2
|
31
|
-
|
32
|
-
- Added user agents
|
33
|
-
- Patterns could falsely identify a 64bit system, made the pattern more strict
|
34
|
-
- using `X11` in a user agent as a synonym to a `#linux?` system
|
35
|
-
|
36
37
|
## Installation
|
37
38
|
|
38
|
-
*supports ruby 1.9.3+*
|
39
|
+
*supports ruby 1.9.3+*
|
39
40
|
Add this line to your application's Gemfile:
|
40
41
|
|
41
42
|
```ruby
|
@@ -125,13 +126,32 @@ agent.to_h # => {
|
|
125
126
|
|
126
127
|
It is now also possible to call methods to determine a specific OS or browser if it's supported, a `noMethodError` will be thrown otherwise
|
127
128
|
The function uses the names of the `Browserino::Mapping.constants(true)` or `Browserino::PATTERNS[:browser].keys` output to identify wether or not to throw this exception.
|
129
|
+
Versions are also supported as an argument to the function, for operating systems versions could include a string, symbol or float / integer to indicate a version.
|
130
|
+
_(examples given for windows, android and ios, for a full list of versions check the **maps** folder)_
|
131
|
+
Browsers can also accept a float / integer to check for a specific version.
|
132
|
+
|
133
|
+
### DEPRECATION NOTICE
|
134
|
+
|
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)`**
|
128
136
|
|
129
137
|
Supported systems
|
130
138
|
|
131
139
|
```ruby
|
132
140
|
agent.android?
|
141
|
+
# check for android jellybean
|
142
|
+
# agent.android?(:jellybean) or agent.android?('jellybean') or agent.android?(4.1)
|
133
143
|
agent.ios?
|
144
|
+
# check version of iOS (v1.x.x)
|
145
|
+
# agent.ios9?
|
146
|
+
# check version of iOS (v2.x.x)
|
147
|
+
# agent.ios?(9)
|
134
148
|
agent.windows?
|
149
|
+
# check for windows Vista (v1.x.x)
|
150
|
+
# agent.windows60?
|
151
|
+
# check for windows Vista (v2.x.x)
|
152
|
+
# agent.windows?(6) - based on NT version
|
153
|
+
# agent.windows?(6.0) - based on NT version
|
154
|
+
# agent.windows?(:vista) or agent.windows?('vista')
|
135
155
|
agent.macintosh?
|
136
156
|
agent.blackberry?
|
137
157
|
agent.linux?
|
@@ -139,16 +159,29 @@ agent.linux?
|
|
139
159
|
|
140
160
|
You could also invert these questions by using the `.not` method
|
141
161
|
|
142
|
-
|
143
162
|
```ruby
|
144
163
|
agent.not.android?
|
164
|
+
# check for android jellybean
|
165
|
+
# agent.not.android?(:jelly_bean) or agent.not.android?('jelly bean') or agent.not.android?(4.1)
|
145
166
|
agent.not.ios?
|
167
|
+
# check if iOS version isn't 9 (v1.4.0+)
|
168
|
+
# agent.not.ios9?
|
169
|
+
# check if iOS version isn't 9 (v2.x.x)
|
170
|
+
# agent.not.ios?(9)
|
146
171
|
agent.not.windows?
|
172
|
+
# check if not windows vista (v1.4.0+)
|
173
|
+
# agent.not.windows60?
|
174
|
+
# check if not windows vista (v2.x.x)
|
175
|
+
# agent.not.windows?(6) - based on NT version
|
176
|
+
# agent.not.windows?(6.0) - based on NT version
|
177
|
+
# agent.not.windows?(:vista) or agent.not.windows?('vista')
|
147
178
|
agent.not.macintosh?
|
148
179
|
agent.not.blackberry?
|
149
180
|
agent.not.linux?
|
150
181
|
```
|
151
182
|
|
183
|
+
The `#windows?`, `#macintosh?` and `#blackberry?` each have a shortcut method to allow for easier access, `#win?`, `#osx?`, `#bb?`
|
184
|
+
|
152
185
|
Supported browsers
|
153
186
|
|
154
187
|
```ruby
|
@@ -167,19 +200,10 @@ agent.safari?
|
|
167
200
|
|
168
201
|
agent.not.opera?
|
169
202
|
agent.not.maxthon?
|
170
|
-
|
171
203
|
# etc etc...
|
172
204
|
|
173
205
|
```
|
174
206
|
|
175
|
-
Since linux doesn't have any supported versions all you can pretty much do is check if `agent.linux?` is true if you want to check for linux systems. Also - `X11` in a user agent string will now also cause the OS to be set to linux. The others do have versions so if you wanted to check for windows 10 you could do:
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
agent.windows10?
|
179
|
-
```
|
180
|
-
|
181
|
-
**note** Windows versions use their respective *NT* versioning so `agent.windows6?` equals `Vista` - I have yet to make changes to fix that. Browser versions use their actual version which always matches up with their real version, the same goes for the other systems.
|
182
|
-
|
183
207
|
## Development
|
184
208
|
|
185
209
|
The tests are dynamically produced and quite easy to write.
|
@@ -192,7 +216,6 @@ If I wanted to add a test case for a different browser for instance (just pickin
|
|
192
216
|
```ruby
|
193
217
|
module UserAgents
|
194
218
|
FIREFOX = {
|
195
|
-
mac: {},
|
196
219
|
win: {
|
197
220
|
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1' => {
|
198
221
|
browser_name: 'Firefox',
|
@@ -201,10 +224,13 @@ module UserAgents
|
|
201
224
|
engine_version: '40.0',
|
202
225
|
system_name: ['windows', '7'],
|
203
226
|
system_version: '6.1',
|
204
|
-
system_architecture: 'x64'
|
205
|
-
|
206
|
-
|
207
|
-
|
227
|
+
system_architecture: 'x64',
|
228
|
+
x64?: true,
|
229
|
+
x32?: false,
|
230
|
+
known?: true,
|
231
|
+
mobile: false
|
232
|
+
}
|
233
|
+
}
|
208
234
|
}
|
209
235
|
end
|
210
236
|
```
|
@@ -213,17 +239,18 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
|
|
213
239
|
|
214
240
|
#### browser_name examples
|
215
241
|
```ruby
|
216
|
-
'unknown'
|
217
242
|
'ie'
|
218
243
|
'firefox'
|
219
244
|
'chrome'
|
220
245
|
'opera'
|
246
|
+
'opera_mini'
|
247
|
+
'bolt'
|
248
|
+
'ucbrowser'
|
221
249
|
'maxthon'
|
222
250
|
```
|
223
251
|
|
224
252
|
#### engine_name examples
|
225
253
|
```ruby
|
226
|
-
'unknown'
|
227
254
|
'gecko'
|
228
255
|
'webkit'
|
229
256
|
'trident'
|
@@ -231,24 +258,22 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
|
|
231
258
|
|
232
259
|
#### system_name examples
|
233
260
|
|
234
|
-
_The main reason for not having Linux distro's / versions
|
261
|
+
_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_
|
235
262
|
|
236
263
|
```ruby
|
237
264
|
['windows', '7'] # where the 'windows' part is the name of the OS and the '7' is the actual version release (e.g. NT 6.1)
|
238
265
|
['macintosh', 'yosemite'] # same as above but OSX has different names ofcourse.
|
239
|
-
['android', 'lollipop'] # etcetera...
|
240
|
-
['
|
266
|
+
['android', 'lollipop 22'] # etcetera...
|
267
|
+
['linux', nil] # in every linux case, the version will be missing on system_name full: true
|
268
|
+
[nil, nil] # when nothing about the agent could be found
|
241
269
|
```
|
242
270
|
|
243
271
|
#### system_architecture examples
|
244
272
|
```ruby
|
245
|
-
'unknown'
|
246
273
|
'x32'
|
247
274
|
'x64'
|
248
275
|
```
|
249
276
|
|
250
|
-
__The value of unknown is a default error value that will always be available to test against. If it ain't known it's unknown__
|
251
|
-
|
252
277
|
## Contributing
|
253
278
|
|
254
279
|
Bug reports and pull requests are welcome on GitHub at https://github.com/SidOfc/browserino. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
data/bin/console
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "browserino"
|
5
5
|
require "pry"
|
6
|
-
ua = 'Mozilla/5.0 (
|
6
|
+
ua = 'UCBROWSER -> Mozilla/5.0 (Linux; U; Android 4.1.2; en-us; SM-T210R Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 UCBrowser/2.3.2.300'
|
7
7
|
@agent = Browserino::parse(ua)
|
8
8
|
|
9
9
|
puts "> @agent variable available parsed with: '#{ua}'\n\n"
|
10
10
|
puts "> You can create a fresh object by using\n"
|
11
11
|
puts "> Browserino::parse((string) ua, (any) unknown_alt = nil)\n\n"
|
12
12
|
puts "> ua - The user agent you'd actually want to parse as a string"
|
13
|
-
puts "> unknown_alt - A default value for unknown properties, default nil\n\n"
|
13
|
+
puts "> unknown_alt - A default value for unknown properties, default nil (recommended)\n\n"
|
14
14
|
|
15
15
|
Pry.start
|
data/lib/browserino/agent.rb
CHANGED
@@ -71,53 +71,43 @@ module Browserino
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def known?
|
74
|
-
browser_name != @unknown
|
74
|
+
res = !@not && browser_name != @unknown
|
75
|
+
@not = false
|
76
|
+
res
|
75
77
|
end
|
76
78
|
|
77
79
|
def mobile?
|
78
|
-
!!(ua =~ /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)
|
80
|
+
allow_inverted_return !!(ua =~ /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)
|
79
81
|
end
|
80
82
|
|
81
83
|
def x64?
|
82
|
-
system_architecture == 'x64'
|
84
|
+
allow_inverted_return(system_architecture == 'x64')
|
83
85
|
end
|
84
86
|
|
85
87
|
def x32?
|
86
|
-
system_architecture == 'x32'
|
88
|
+
allow_inverted_return(system_architecture == 'x32')
|
87
89
|
end
|
88
90
|
|
89
|
-
def
|
90
|
-
|
91
|
-
if version
|
92
|
-
os_equal && version == system_version.to_s[0..(version.size - 1)]
|
93
|
-
else
|
94
|
-
os_equal
|
95
|
-
end
|
91
|
+
def osx?(*arg)
|
92
|
+
macintosh?(*arg)
|
96
93
|
end
|
97
94
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
95
|
+
def win?(*arg)
|
96
|
+
windows?(*arg)
|
97
|
+
end
|
98
|
+
|
99
|
+
def bb?(*arg)
|
100
|
+
blackberry?(*arg)
|
105
101
|
end
|
106
102
|
|
107
103
|
def method_missing(method_sym, *args, &block)
|
108
|
-
|
109
|
-
name = criteria[0]
|
104
|
+
name = method_sym.to_s.gsub('?', '')
|
110
105
|
res = case browser_or_system?(method_sym)
|
111
|
-
when :system then correct_system?(
|
112
|
-
when :browser then correct_browser?(
|
106
|
+
when :system then correct_system?(name, *args)
|
107
|
+
when :browser then correct_browser?(name, *args)
|
113
108
|
else super
|
114
109
|
end
|
115
|
-
|
116
|
-
@not = false
|
117
|
-
!res
|
118
|
-
else
|
119
|
-
res
|
120
|
-
end
|
110
|
+
allow_inverted_return res
|
121
111
|
end
|
122
112
|
|
123
113
|
def respond_to?(method_sym)
|
@@ -160,8 +150,45 @@ module Browserino
|
|
160
150
|
|
161
151
|
private
|
162
152
|
|
153
|
+
def allow_inverted_return(res)
|
154
|
+
if @not
|
155
|
+
@not = false
|
156
|
+
!res
|
157
|
+
else
|
158
|
+
res
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def compare_versions(a, b)
|
163
|
+
b = b.to_s.split('.')
|
164
|
+
!a.to_s.split('.').map { |v| v == b.shift }.include?(false)
|
165
|
+
end
|
166
|
+
|
167
|
+
def correct_system?(name, version = nil)
|
168
|
+
sys_name = name.to_s.downcase.gsub(/\s/, '_')
|
169
|
+
sys_name_compare = system_name(full: true).join.downcase.gsub(/\s/, '_')
|
170
|
+
name_variations = [sys_name_compare, sys_name_compare.gsub(/^[\s_]+|\d|[\s_]+$/, '')]
|
171
|
+
|
172
|
+
if (name_variations.include?((sys_name + version.to_s).gsub(/\s/, '_').downcase) ||
|
173
|
+
(sys_name == system_name.gsub(/\s/, '_') && compare_versions(version, system_version)) ||
|
174
|
+
(!version && sys_name == system_name.gsub(/\s/, '_')))
|
175
|
+
true
|
176
|
+
else
|
177
|
+
false
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def correct_browser?(name, version = nil)
|
182
|
+
browser_equal = (name.gsub(/_/, ' ') == browser_name)
|
183
|
+
if version
|
184
|
+
browser_equal && compare_versions(version, browser_version)
|
185
|
+
else
|
186
|
+
browser_equal
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
163
190
|
def browser_or_system?(method_sym)
|
164
|
-
name = method_sym.to_s.gsub('?', '').split(/
|
191
|
+
name = method_sym.to_s.gsub('?', '').split(/_/).first
|
165
192
|
sys = Browserino::Mapping.constants(true).include?(name.upcase.to_sym)
|
166
193
|
browser = Browserino::PATTERNS[:browser].keys.include?(name.to_sym)
|
167
194
|
if sys
|
data/lib/browserino/version.rb
CHANGED