browserino 1.5.3 → 1.6.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 +37 -0
- data/README.md +30 -38
- data/bin/console +2 -3
- data/lib/browserino/agent.rb +64 -19
- data/lib/browserino/patterns.rb +18 -3
- data/lib/browserino/version.rb +1 -1
- data/lib/browserino.rb +14 -12
- metadata +3 -3
- data/lib/browserino/agent_manipulator.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2ae02d6780d0cef93f9a41bb022a147dba31557
|
4
|
+
data.tar.gz: 3225266d8e2fbf37d3ea436bac8d3928779bba45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af7551c42f54dc920a7bd309baab7106f69375e1914d1669a49f2bca63cfaf308d944b771e7f11dd4fe1bf73eae2ebec0f4b8978855871d3a446d7b4630dcb94
|
7
|
+
data.tar.gz: 78d2fca76155ac213f4c04dd81b9fe5fbd2ebba65ae73bc107cc2f767782c2509b888f6612dfd85f72376eaabe07bafa18d4370ff9072b0290723f8568129326
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## CHANGELOG
|
2
|
+
_dates are in dd-mm-yyyy format_
|
3
|
+
|
4
|
+
#### 23-12-2015 VERSION 1.5.1.1
|
5
|
+
|
6
|
+
- Removed print statements from method
|
7
|
+
- Builds are now executed for Ruby 1.9.3 as well as 2.2.1
|
8
|
+
|
9
|
+
#### 20-12-2015 VERSION 1.5.1
|
10
|
+
|
11
|
+
- Fixed `respond_to?` method which would first return inverted results (e.g. false when it should be true)
|
12
|
+
|
13
|
+
#### 19-12-2015 VERSION 1.5.0
|
14
|
+
|
15
|
+
- Implemented to_s to return a concatenated string of property values
|
16
|
+
- Implemented to_a to return an array with arrays containing property name-value pairs
|
17
|
+
- Implemented to_h to return a hash containing property name-value pairs
|
18
|
+
- Removed unused code
|
19
|
+
|
20
|
+
#### 19-12-2015 VERSION 1.4.0
|
21
|
+
|
22
|
+
- Added not method to invert questions about browser / system
|
23
|
+
- Added random test cases to verify that all inverted answers are correct
|
24
|
+
|
25
|
+
#### 17-12-2015 VERSION 1.3.0
|
26
|
+
|
27
|
+
- Added Edge detection
|
28
|
+
- For supported browsers, it is now possible to check name and version through `method_missing?`
|
29
|
+
|
30
|
+
#### 16-12-2015 VERSION 1.2.0
|
31
|
+
|
32
|
+
- Opera tests didn't run before
|
33
|
+
- For supported systems, it is possible to check OS and version through `method_missing?`
|
34
|
+
|
35
|
+
#### 15-12-2015 VERSION 1.1.2
|
36
|
+
|
37
|
+
- User definable 'unknown' return value
|
data/README.md
CHANGED
@@ -7,7 +7,20 @@
|
|
7
7
|
This gem aims to provide information about the browser that your visitor is using, it's main goal is not to let you exclude any browser from partying on your website (e.g. sniffing) but to provide you with more flexibility towards designing maybe a browser-themed website or knowledge of what your visitors are using to check out your website!
|
8
8
|
|
9
9
|
## Changelog
|
10
|
-
_dates are in dd-mm-yyyy format_
|
10
|
+
_dates are in dd-mm-yyyy format_
|
11
|
+
_older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md)_
|
12
|
+
|
13
|
+
#### 03-01-2016 VERSION 1.6.0
|
14
|
+
|
15
|
+
- Added more tests
|
16
|
+
- Added more browsers to check: *(bolt, opera mini and ucbrowser)*
|
17
|
+
- Added `#known?` method to check if the agent is known
|
18
|
+
- Added a `#ua` method to return the User Agent string as given to `Browserino::parse()`
|
19
|
+
- Added `#x64?` and `#x32?` convenience methods to check system architecture
|
20
|
+
- Added `#mobile?` to check wether or not a user agent is mobile
|
21
|
+
- Moved older changelogs to its own [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md) file
|
22
|
+
- Changed `#to_s` to add dashes (`-`) between browser names if they have a space
|
23
|
+
- `#to_s` now has an optional (`sep = ''`) parameter that allows info and version numbers to be seperated
|
11
24
|
|
12
25
|
#### 31-12-2015 VERSION 1.5.3
|
13
26
|
|
@@ -20,41 +33,6 @@ _dates are in dd-mm-yyyy format_
|
|
20
33
|
- Patterns could falsely identify a 64bit system, made the pattern more strict
|
21
34
|
- using `X11` in a user agent as a synonym to a `#linux?` system
|
22
35
|
|
23
|
-
#### 23-12-2015 VERSION 1.5.1.1
|
24
|
-
|
25
|
-
- Removed print statements from method
|
26
|
-
- Builds are now executed for Ruby 1.9.3 as well as 2.2.1
|
27
|
-
|
28
|
-
#### 20-12-2015 VERSION 1.5.1
|
29
|
-
|
30
|
-
- Fixed `respond_to?` method which would first return inverted results (e.g. false when it should be true)
|
31
|
-
|
32
|
-
#### 19-12-2015 VERSION 1.5.0
|
33
|
-
|
34
|
-
- Implemented to_s to return a concatenated string of property values
|
35
|
-
- Implemented to_a to return an array with arrays containing property name-value pairs
|
36
|
-
- Implemented to_h to return a hash containing property name-value pairs
|
37
|
-
- Removed unused code
|
38
|
-
|
39
|
-
#### 19-12-2015 VERSION 1.4.0
|
40
|
-
|
41
|
-
- Added not method to invert questions about browser / system
|
42
|
-
- Added random test cases to verify that all inverted answers are correct
|
43
|
-
|
44
|
-
#### 17-12-2015 VERSION 1.3.0
|
45
|
-
|
46
|
-
- Added Edge detection
|
47
|
-
- For supported browsers, it is now possible to check name and version through `method_missing?`
|
48
|
-
|
49
|
-
#### 16-12-2015 VERSION 1.2.0
|
50
|
-
|
51
|
-
- Opera tests didn't run before
|
52
|
-
- For supported systems, it is possible to check OS and version through `method_missing?`
|
53
|
-
|
54
|
-
#### 15-12-2015 VERSION 1.1.2
|
55
|
-
|
56
|
-
- User definable 'unknown' return value
|
57
|
-
|
58
36
|
## Installation
|
59
37
|
|
60
38
|
*supports ruby 1.9.3+*
|
@@ -111,11 +89,20 @@ agent.engine_version # => 537.75.14
|
|
111
89
|
agent.system_name # => 'macintosh'
|
112
90
|
# or optionally, the full name (guessed from OS version)
|
113
91
|
agent.system_name full: true # => ['macintosh', 'mavericks']
|
114
|
-
agent.system_version # =>
|
115
|
-
agent.system_architecture # => 'x32' or 'x64'
|
92
|
+
agent.system_version # => 10.9.3
|
93
|
+
agent.system_architecture # => 'x32' or 'x64' if known
|
94
|
+
# or through convenience methods:
|
95
|
+
agent.x32? # => true for 32bit UA's
|
96
|
+
agent.x64? # => true for 64bit UA's
|
97
|
+
|
98
|
+
agent.known? # => true if browser_name present
|
99
|
+
agent.mobile? # => true if agent is a mobile device
|
116
100
|
|
117
101
|
# methods to convert object into a String, Array or hash
|
118
102
|
agent.to_s # => 'safari safari7 webkit webkit537 macintosh macintosh10'
|
103
|
+
# to_s can split version numbers from words if a seperator is supplied
|
104
|
+
agent.to_s '-' # => 'safari safari-7 webkit webkit-537 macintosh macintosh-10'
|
105
|
+
|
119
106
|
agent.to_a # => [
|
120
107
|
# [:browser_name, 'safari'],
|
121
108
|
# [:browser_version, '7.0.3'],
|
@@ -146,6 +133,7 @@ agent.android?
|
|
146
133
|
agent.ios?
|
147
134
|
agent.windows?
|
148
135
|
agent.macintosh?
|
136
|
+
agent.blackberry?
|
149
137
|
agent.linux?
|
150
138
|
```
|
151
139
|
|
@@ -157,6 +145,7 @@ agent.not.android?
|
|
157
145
|
agent.not.ios?
|
158
146
|
agent.not.windows?
|
159
147
|
agent.not.macintosh?
|
148
|
+
agent.not.blackberry?
|
160
149
|
agent.not.linux?
|
161
150
|
```
|
162
151
|
|
@@ -164,6 +153,9 @@ Supported browsers
|
|
164
153
|
|
165
154
|
```ruby
|
166
155
|
agent.opera?
|
156
|
+
agent.opera_mini?
|
157
|
+
agent.bolt?
|
158
|
+
agent.ucbrowser?
|
167
159
|
agent.maxthon?
|
168
160
|
agent.edge?
|
169
161
|
agent.ie?
|
data/bin/console
CHANGED
@@ -3,11 +3,10 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "browserino"
|
5
5
|
require "pry"
|
6
|
-
|
7
|
-
ua = 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136'
|
6
|
+
ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; BOLT/2.800) AppleWebKit/534.6 (KHTML, like Gecko) Version/5.0 Safari/534.6.3'
|
8
7
|
@agent = Browserino::parse(ua)
|
9
8
|
|
10
|
-
puts "> @agent variable available parsed with: '
|
9
|
+
puts "> @agent variable available parsed with: '#{ua}'\n\n"
|
11
10
|
puts "> You can create a fresh object by using\n"
|
12
11
|
puts "> Browserino::parse((string) ua, (any) unknown_alt = nil)\n\n"
|
13
12
|
puts "> ua - The user agent you'd actually want to parse as a string"
|
data/lib/browserino/agent.rb
CHANGED
@@ -1,30 +1,52 @@
|
|
1
1
|
module Browserino
|
2
2
|
class Agent
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(ua, unknown = Browserino::UNKNOWN)
|
4
|
+
@ua = ua
|
5
5
|
@unknown = unknown
|
6
6
|
@not = false
|
7
|
+
|
8
|
+
cleansed_ua = Browserino::cleanse @ua
|
9
|
+
name = Browserino::find_browser_name cleansed_ua
|
10
|
+
@info = Browserino::check_for_aliases({
|
11
|
+
browser_name: name,
|
12
|
+
browser_version: Browser::version(cleansed_ua, PATTERNS[:browser][name]),
|
13
|
+
engine_name: Engine::name(cleansed_ua),
|
14
|
+
engine_version: Engine::version(cleansed_ua),
|
15
|
+
system_name: OperatingSystem::name(cleansed_ua),
|
16
|
+
system_version: OperatingSystem::version(cleansed_ua),
|
17
|
+
system_architecture: OperatingSystem::architecture(cleansed_ua)
|
18
|
+
})
|
7
19
|
end
|
8
20
|
|
9
21
|
def browser_name
|
10
|
-
with_valid(@info[:browser_name])
|
22
|
+
with_valid(@info[:browser_name]) do |v|
|
23
|
+
v.to_s.downcase.gsub(/_/, ' ')
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
27
|
def browser_version
|
14
|
-
with_valid(@info[:browser_version])
|
28
|
+
with_valid(@info[:browser_version]) do |v|
|
29
|
+
v.to_s.downcase.gsub('_', '.')
|
30
|
+
end
|
15
31
|
end
|
16
32
|
|
17
33
|
def engine_name
|
18
|
-
with_valid(@info[:engine_name])
|
34
|
+
with_valid(@info[:engine_name]) do |v|
|
35
|
+
v.to_s.downcase
|
36
|
+
end
|
19
37
|
end
|
20
38
|
|
21
39
|
def engine_version
|
22
|
-
with_valid(@info[:engine_version])
|
40
|
+
with_valid(@info[:engine_version]) do |v|
|
41
|
+
v.to_s.downcase.gsub('_', '.')
|
42
|
+
end
|
23
43
|
end
|
24
44
|
|
25
45
|
def system_name(opts = {})
|
26
46
|
opts = {full: false}.merge(opts)
|
27
|
-
name = with_valid(@info[:system_name])
|
47
|
+
name = with_valid(@info[:system_name]) do |v|
|
48
|
+
v.to_s.downcase
|
49
|
+
end
|
28
50
|
if opts[:full]
|
29
51
|
[name, fetch_system_version_name(name)]
|
30
52
|
else
|
@@ -33,11 +55,35 @@ module Browserino
|
|
33
55
|
end
|
34
56
|
|
35
57
|
def system_version
|
36
|
-
with_valid(@info[:system_version])
|
58
|
+
with_valid(@info[:system_version]) do |v|
|
59
|
+
v.to_s.downcase.gsub('_', '.')
|
60
|
+
end
|
37
61
|
end
|
38
62
|
|
39
63
|
def system_architecture
|
40
|
-
with_valid(@info[:system_architecture])
|
64
|
+
with_valid(@info[:system_architecture]) do |v|
|
65
|
+
v.to_s.downcase
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def ua
|
70
|
+
@ua
|
71
|
+
end
|
72
|
+
|
73
|
+
def known?
|
74
|
+
browser_name != @unknown
|
75
|
+
end
|
76
|
+
|
77
|
+
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)
|
79
|
+
end
|
80
|
+
|
81
|
+
def x64?
|
82
|
+
system_architecture == 'x64'
|
83
|
+
end
|
84
|
+
|
85
|
+
def x32?
|
86
|
+
system_architecture == 'x32'
|
41
87
|
end
|
42
88
|
|
43
89
|
def correct_system?(name, version = nil)
|
@@ -50,7 +96,7 @@ module Browserino
|
|
50
96
|
end
|
51
97
|
|
52
98
|
def correct_browser?(name, version = nil)
|
53
|
-
browser_equal = (name == browser_name)
|
99
|
+
browser_equal = (name.gsub(/_/, ' ') == browser_name)
|
54
100
|
if version
|
55
101
|
browser_equal && version == browser_version.to_s[0..(version.size - 1)]
|
56
102
|
else
|
@@ -59,7 +105,7 @@ module Browserino
|
|
59
105
|
end
|
60
106
|
|
61
107
|
def method_missing(method_sym, *args, &block)
|
62
|
-
criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-
|
108
|
+
criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z_])(?=\d+)/)
|
63
109
|
name = criteria[0]
|
64
110
|
res = case browser_or_system?(method_sym)
|
65
111
|
when :system then correct_system?(criteria[0], criteria[1])
|
@@ -83,20 +129,19 @@ module Browserino
|
|
83
129
|
self
|
84
130
|
end
|
85
131
|
|
86
|
-
def to_s
|
87
|
-
props = @info.map do |k,
|
88
|
-
res = send k
|
132
|
+
def to_s(sep = '')
|
133
|
+
props = @info.map do |k, _|
|
89
134
|
case k
|
90
135
|
when :system_version
|
91
|
-
system_name +
|
136
|
+
system_name + sep + send(k).to_s.split('.').first.to_s
|
92
137
|
when :engine_version
|
93
|
-
engine_name +
|
138
|
+
engine_name + sep + send(k).to_s.split('.').first.to_s
|
94
139
|
when :browser_version
|
95
|
-
browser_name +
|
96
|
-
else
|
140
|
+
browser_name + sep + send(k).to_s.split('.').first.to_s
|
141
|
+
else send(k)
|
97
142
|
end
|
98
143
|
end
|
99
|
-
props.compact.join(' ')
|
144
|
+
props.compact.map { |v| v.gsub(/\s/, '-') }.join(' ')
|
100
145
|
end
|
101
146
|
|
102
147
|
def to_a
|
data/lib/browserino/patterns.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
module Browserino
|
2
2
|
PATTERNS = {
|
3
3
|
browser: {
|
4
|
+
ucbrowser: {
|
5
|
+
name: /(?<name>ucbrowser)/i,
|
6
|
+
version: /ucbrowser\/?(?<version>[\d\.]+)/i
|
7
|
+
},
|
8
|
+
|
9
|
+
bolt: {
|
10
|
+
name: /(?<name>bolt)/i,
|
11
|
+
version: /bolt\/(?<version>[\d\.]+)/i
|
12
|
+
},
|
13
|
+
|
14
|
+
opera_mini: {
|
15
|
+
name: /(?<name>ope?ra?\smini)/i,
|
16
|
+
version: /(?:ope?ra?\smini)\/(?<version>[\d\.]+)/i
|
17
|
+
},
|
18
|
+
|
4
19
|
opera: {
|
5
20
|
name: /(?<name>ope?ra?)/i,
|
6
21
|
version: /(?:ope?ra?|version)(\/|\s)(?<version>[\d\.]+)/i
|
@@ -38,13 +53,13 @@ module Browserino
|
|
38
53
|
},
|
39
54
|
|
40
55
|
engine: {
|
41
|
-
name: /(?<name>((apple)?webkit|gecko|trident
|
42
|
-
version: /(?:(?:apple)?webkit|rv:|trident
|
56
|
+
name: /(?<name>((apple)?webkit|presto|gecko|trident))/i,
|
57
|
+
version: /(?:(?:apple)?webkit|presto|rv:|trident)[\/\s]?(?<version>[\d\.]+)/i
|
43
58
|
},
|
44
59
|
|
45
60
|
operating_system: {
|
46
61
|
name: /(?<name>windows|macintosh|android|ios|blackberry|linux|ubuntu|x11)/i,
|
47
|
-
version: /(?:nt|mac\sos\sx|android|(cpu\s|i)os|blackberry)\s(?<version>[\d\._]+)/i,
|
62
|
+
version: /(?:nt|mac\sos\sx|android|(cpu\s|i)os|blackberry)\s?(?<version>[\d\._]+)/i,
|
48
63
|
architecture: /(?<architecture>((?:x|x86_|amd|wow)64)|i(3|6)86)/i
|
49
64
|
}
|
50
65
|
}
|
data/lib/browserino/version.rb
CHANGED
data/lib/browserino.rb
CHANGED
@@ -9,7 +9,6 @@ require "browserino/unknown"
|
|
9
9
|
require "browserino/agent"
|
10
10
|
|
11
11
|
require "browserino/alias"
|
12
|
-
require "browserino/agent_manipulator"
|
13
12
|
require "browserino/version"
|
14
13
|
require "browserino/match_extractor"
|
15
14
|
require "browserino/patterns"
|
@@ -19,21 +18,24 @@ require "browserino/operating_system"
|
|
19
18
|
|
20
19
|
module Browserino
|
21
20
|
def self.parse(ua, unknown_alt = Browserino::UNKNOWN)
|
22
|
-
|
23
|
-
name = find_browser_name(ua)
|
24
|
-
Agent.new(check_for_aliases({
|
25
|
-
browser_name: name,
|
26
|
-
browser_version: Browser::version(ua, PATTERNS[:browser][name]),
|
27
|
-
engine_name: Engine::name(ua),
|
28
|
-
engine_version: Engine::version(ua),
|
29
|
-
system_name: OperatingSystem::name(ua),
|
30
|
-
system_version: OperatingSystem::version(ua),
|
31
|
-
system_architecture: OperatingSystem::architecture(ua)
|
32
|
-
}), unknown_alt)
|
21
|
+
Agent.new(ua, unknown_alt)
|
33
22
|
end
|
34
23
|
|
35
24
|
private
|
36
25
|
|
26
|
+
def self.cleanse(ua)
|
27
|
+
#make iphone / ipad / ipod consistent
|
28
|
+
ua = ua.gsub(/ip((a|o)d|hone)/i, 'ios')
|
29
|
+
#strip legacy mozilla version
|
30
|
+
ua = ua.gsub(/(Mozilla\/[\d\.]+)/i, '')
|
31
|
+
#strip fake opera version
|
32
|
+
ua = ua.gsub(/9\.80/i, '')
|
33
|
+
#strip webkit if presto engine is used
|
34
|
+
ua = ua.gsub(/(?:apple)?webkit\/[\d\.]+/i, '') if /presto/i =~ ua
|
35
|
+
ua = ua.gsub(/linux/i, '') if /android/i =~ ua
|
36
|
+
ua
|
37
|
+
end
|
38
|
+
|
37
39
|
def self.check_for_aliases(hash)
|
38
40
|
h = {}
|
39
41
|
hash.each do |prop, val|
|
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: 1.
|
4
|
+
version: 1.6.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:
|
11
|
+
date: 2016-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
121
|
- ".travis.yml"
|
122
|
+
- CHANGELOG.md
|
122
123
|
- CODE_OF_CONDUCT.md
|
123
124
|
- Gemfile
|
124
125
|
- Guardfile
|
@@ -130,7 +131,6 @@ files:
|
|
130
131
|
- browserino.gemspec
|
131
132
|
- lib/browserino.rb
|
132
133
|
- lib/browserino/agent.rb
|
133
|
-
- lib/browserino/agent_manipulator.rb
|
134
134
|
- lib/browserino/alias.rb
|
135
135
|
- lib/browserino/browser.rb
|
136
136
|
- lib/browserino/engine.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Browserino
|
2
|
-
@ua = nil
|
3
|
-
|
4
|
-
class AgentManipulator
|
5
|
-
def initialize(ua)
|
6
|
-
@ua = ua
|
7
|
-
standardize_ios!
|
8
|
-
strip_legacy_mozilla!
|
9
|
-
strip_fake_opera_version!
|
10
|
-
end
|
11
|
-
|
12
|
-
def standardize_ios!
|
13
|
-
@ua = @ua.gsub(/ip((a|o)d|hone)/i, 'ios')
|
14
|
-
end
|
15
|
-
|
16
|
-
def strip_legacy_mozilla!
|
17
|
-
@ua = @ua.gsub(/(Mozilla\/[\d\.]+)/i, '')
|
18
|
-
end
|
19
|
-
|
20
|
-
def strip_fake_opera_version!
|
21
|
-
@ua = @ua.gsub(/9\.80/i, '')
|
22
|
-
end
|
23
|
-
|
24
|
-
def ua
|
25
|
-
@ua
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|