detect_user_agent 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/detect_user_agent.gemspec +24 -0
- data/lib/detect_user_agent/browser.rb +21 -0
- data/lib/detect_user_agent/os.rb +28 -0
- data/lib/detect_user_agent/platform.rb +17 -0
- data/lib/detect_user_agent/version.rb +3 -0
- data/lib/detect_user_agent.rb +14 -0
- data/spec/lib/browser_spec.rb +12 -0
- data/spec/lib/detect_user_agent_spec.rb +13 -0
- data/spec/lib/os_spec.rb +12 -0
- data/spec/lib/platform_spec.rb +12 -0
- data/spec/spec_helper.rb +19 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d67ce71c0dbb7024d2fe3e89d30ac3280064b37
|
4
|
+
data.tar.gz: d8fc2df614ca5d9c0effa590ae041c1250f64b57
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32ee69c372f33d2e9c9594194341fa8fbcc09b2ccd80e69a048b3198c11034409f8e42402f550e966e6c8a7787caa57bb1bb39d76052cf8ad65fc7b261295c00
|
7
|
+
data.tar.gz: 19aece27f0d6dafa161527653a6e6f74bc108ff123c43e84149a488a7c083629061badceccec855a85bc1f805d8fced14c45b700fb37daf96bec3659cbfdd0ad
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Herman verschooten
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
[](https://codeclimate.com/github/Hermanverschooten/detect_user_agent) [](https://codeclimate.com/github/Hermanverschooten/detect_user_agent) [](https://circleci.com/gh/Hermanverschooten/detect_user_agent)
|
2
|
+
|
3
|
+
# DetectUserAgent
|
4
|
+
|
5
|
+
Detect browser, os and platform based upon user agent
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'detect_user_agent'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install detect_user_agent
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
DetectUserAgent.parse("Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>")
|
27
|
+
```
|
28
|
+
returns a hash:
|
29
|
+
```ruby
|
30
|
+
{
|
31
|
+
platform: 'phone',
|
32
|
+
os: 'blackberry'
|
33
|
+
browser: 'blackberry'
|
34
|
+
}
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/[my-github-username]/detect_user_agent/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'detect_user_agent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "detect_user_agent"
|
8
|
+
spec.version = DetectUserAgent::VERSION
|
9
|
+
spec.authors = ["Herman verschooten"]
|
10
|
+
spec.email = ["Herman@verschooten.net"]
|
11
|
+
spec.summary = %q{Detect browser, os and platform based upon user agent}
|
12
|
+
spec.homepage = "https://github.com/Hermanverschooten/detect_user_agent"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DetectUserAgent
|
2
|
+
def self.browser(useragent)
|
3
|
+
{
|
4
|
+
/\(BB10;.+Mobile Safari|BlackBerry.+Vendor/ => 'BlackBerry',
|
5
|
+
/MSIE/i => "Internet Explorer",
|
6
|
+
/Chrome/i => "Chrome",
|
7
|
+
/Dolfin/i => "Dolfin",
|
8
|
+
/Jasmine/i => "Jasmine",
|
9
|
+
/NetFront|Playstation|PSP|Nintendo 3DS/i => "NetFront",
|
10
|
+
/Silk/ => "Amazon Silk",
|
11
|
+
/Safari|AppleWebKit/i => "Safari",
|
12
|
+
/Opera|maemo/i => "Opera",
|
13
|
+
/Firefox|gecko/i => "Firefox",
|
14
|
+
/Obigo|Teleca/i => "Obigo",
|
15
|
+
/Nokia\d+/ => "Opera"
|
16
|
+
}.each do |regex,val|
|
17
|
+
return val if useragent=~regex
|
18
|
+
end
|
19
|
+
return "Other"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DetectUserAgent
|
2
|
+
def self.os(useragent)
|
3
|
+
{
|
4
|
+
/Android|Nuvifone/i => "Android",
|
5
|
+
/iPad|iPhone|Mobile\/.+Safari/i => "iOS",
|
6
|
+
/Windows (NT|98|XP|Vista|7)|Win98|EA download manager/i => "Windows",
|
7
|
+
/Windows CE|PPC|SAMSUNG-(SGH|GT)|Phone /i => "Windows Mobile",
|
8
|
+
/X11/i => "Linux",
|
9
|
+
/Macintosh/i => "Mac",
|
10
|
+
/playstation/i => "Playstation",
|
11
|
+
/Nintendo/i => "Nintendo",
|
12
|
+
/Symbian|SymbOs|SoftBank/i => "Symbian",
|
13
|
+
/BlackBerry|RIM|\(BB10;/i => "BlackBerry",
|
14
|
+
/PalmSource/i => "Palm",
|
15
|
+
/SAMSUNG.+(Dolfin|Jasmine)|Bada/i => "BadaOs",
|
16
|
+
/ARCHOS/i => "ArchOs",
|
17
|
+
/Linux/i => "Linux",
|
18
|
+
/HTC|WCE/i => "Windows Mobile",
|
19
|
+
/webOS/i => "webOS",
|
20
|
+
/LG-/ => "LG",
|
21
|
+
/Nokia/i => "Nokia",
|
22
|
+
/SonyEricsson/ => "Sony Ericsson"
|
23
|
+
}.each do |regex,val|
|
24
|
+
return val if useragent=~regex
|
25
|
+
end
|
26
|
+
return "Other"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DetectUserAgent
|
2
|
+
def self.platform(useragent)
|
3
|
+
{
|
4
|
+
/iPad/i => "iPad",
|
5
|
+
/iPhone|mobile\/.+Safari/i => "iPhone",
|
6
|
+
/Tablet|Ventana|Froyo|Eclair/i => "Tablet",
|
7
|
+
/Windows (NT|95|98|XP|Vista|7)|Win98|X11|Macintosh|Linux x|EA download manager/i => "Laptop",
|
8
|
+
/Windows CE|Windows Mobile|Windows Phone OS|webOS|WCE|Palm|maemo|Windows.*PPC|Android|Archos|Nuvifone|Folio|obigo/i => "PDA",
|
9
|
+
/playstation|PSP|Nintendo/i => "Console",
|
10
|
+
/\(BB10;|Nokia|SonyEricsson|Symbian|Motorola|Symbos|SoftBank|BlackBerry|SAMSUNG|HTC|LG|Configuration\/CLDC/i => "Phone"
|
11
|
+
|
12
|
+
}.each do |regex,val|
|
13
|
+
return val if useragent=~regex
|
14
|
+
end
|
15
|
+
return "Other"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "detect_user_agent/version"
|
2
|
+
require "detect_user_agent/platform"
|
3
|
+
require "detect_user_agent/browser"
|
4
|
+
require "detect_user_agent/os"
|
5
|
+
|
6
|
+
module DetectUserAgent
|
7
|
+
def self.parse(useragent)
|
8
|
+
{
|
9
|
+
platform: platform(useragent),
|
10
|
+
browser: browser(useragent),
|
11
|
+
os: os(useragent)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DetectUserAgent do
|
4
|
+
describe '.browser' do
|
5
|
+
it 'returns Internet Explorer for the windows useragent' do
|
6
|
+
expect(subject.browser(WINDOWS)).to eql 'Internet Explorer'
|
7
|
+
end
|
8
|
+
it 'returns BlackBerry for a blackberry device' do
|
9
|
+
expect(subject.browser(BLACKBERRY)).to eql 'BlackBerry'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/lib/os_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DetectUserAgent do
|
4
|
+
describe '.os' do
|
5
|
+
it 'returns Windows for the windows useragent' do
|
6
|
+
expect(subject.os(WINDOWS)).to eql 'Windows'
|
7
|
+
end
|
8
|
+
it 'returns BlackBerry for a blackberry device' do
|
9
|
+
expect(subject.os(BLACKBERRY)).to eql 'BlackBerry'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DetectUserAgent do
|
4
|
+
describe '.platform' do
|
5
|
+
it 'returns laptop for a windows useragent' do
|
6
|
+
expect(subject.platform(WINDOWS)).to eql 'Laptop'
|
7
|
+
end
|
8
|
+
it 'returns phone for a blackberry device' do
|
9
|
+
expect(subject.platform(BLACKBERRY)).to eql 'Phone'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'detect_user_agent'
|
5
|
+
|
6
|
+
BLACKBERRY = 'Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>'
|
7
|
+
|
8
|
+
ANDROID = 'Mozilla/5.0 (Linux; U; Android 4.2.1; fr-fr; PRO5701 Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
|
9
|
+
|
10
|
+
WINDOWS = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30729)'
|
11
|
+
|
12
|
+
IPHONE = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7E18'
|
13
|
+
|
14
|
+
IPAD = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; fr-fr) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B367'
|
15
|
+
|
16
|
+
IPOD = "Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7E18"
|
17
|
+
|
18
|
+
MAC = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2"
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: detect_user_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Herman verschooten
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- Herman@verschooten.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- detect_user_agent.gemspec
|
82
|
+
- lib/detect_user_agent.rb
|
83
|
+
- lib/detect_user_agent/browser.rb
|
84
|
+
- lib/detect_user_agent/os.rb
|
85
|
+
- lib/detect_user_agent/platform.rb
|
86
|
+
- lib/detect_user_agent/version.rb
|
87
|
+
- spec/lib/browser_spec.rb
|
88
|
+
- spec/lib/detect_user_agent_spec.rb
|
89
|
+
- spec/lib/os_spec.rb
|
90
|
+
- spec/lib/platform_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/Hermanverschooten/detect_user_agent
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Detect browser, os and platform based upon user agent
|
116
|
+
test_files:
|
117
|
+
- spec/lib/browser_spec.rb
|
118
|
+
- spec/lib/detect_user_agent_spec.rb
|
119
|
+
- spec/lib/os_spec.rb
|
120
|
+
- spec/lib/platform_spec.rb
|
121
|
+
- spec/spec_helper.rb
|