device_wizard 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rspec +0 -1
- data/.travis.yml +22 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +46 -29
- data/Rakefile +6 -2
- data/device_wizard.gemspec +11 -11
- data/lib/device_wizard.rb +8 -432
- data/lib/device_wizard/details.rb +5 -0
- data/lib/device_wizard/details/browser.rb +15 -0
- data/lib/device_wizard/details/device.rb +11 -0
- data/lib/device_wizard/details/operating_system.rb +11 -0
- data/lib/device_wizard/device_type.rb +11 -0
- data/lib/device_wizard/resolvers.rb +12 -0
- data/lib/device_wizard/resolvers/android.rb +15 -0
- data/lib/device_wizard/resolvers/base.rb +28 -0
- data/lib/device_wizard/resolvers/firefox.rb +17 -0
- data/lib/device_wizard/resolvers/google_chrome.rb +15 -0
- data/lib/device_wizard/resolvers/internet_explorer.rb +38 -0
- data/lib/device_wizard/resolvers/ios.rb +43 -0
- data/lib/device_wizard/resolvers/mac.rb +20 -0
- data/lib/device_wizard/resolvers/safari.rb +15 -0
- data/lib/device_wizard/resolvers/windows.rb +30 -0
- data/lib/device_wizard/user_agent_detector.rb +103 -0
- data/lib/device_wizard/version.rb +3 -1
- metadata +41 -19
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/device_wizard.iml +0 -29
- data/.idea/encodings.xml +0 -6
- data/.idea/misc.xml +0 -14
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/.idea/workspace.xml +0 -730
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ee4a7895de008768c343a7825805b36cc7aca3214c6f636cbe943217bf82fd1
|
4
|
+
data.tar.gz: 89fcb5c82a9e451cff573c27db3ad28ffc9d67cc197b53c785f1914adb6da8ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962c9ab30dc9aceba9cc5109d72816324c6e4adce74cde2ad8d3cccd3cc61ad52f1cf915f63e906e200fd152c5d133fcee5b9046a6e45a01744dea2dfceb73c9
|
7
|
+
data.tar.gz: cfeb3693aebe1f7a5756b9c0750a4fca2643d8ad5bbb91e74413ae975175263938c493d908f9580cfd69325ae826d39a9fcb418e0a94ef8ee6f437c85c2b34bc
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3.5
|
4
|
+
before_script:
|
5
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
6
|
+
> ./cc-test-reporter
|
7
|
+
- chmod +x ./cc-test-reporter
|
8
|
+
- "./cc-test-reporter before-build"
|
9
|
+
after_script:
|
10
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
secure: F6wCA9Gp7+vRRl/JzEqr2Lp0f/lGd+VnDVNX8ifOjQqOtCKvHNz5+9P+FaxCouDSicq5d1z7FdHGaGRsERDbo/oWfoDh81fNx/DaQoMaPC30xt4ihIP7d3AcPj15Y5WoqzNFejOCMFxkg2T0P8kiaj/0yQsiAXfiQmRC3jaemOaK2ashxj7MR7OXdPh0EwjZ4xKFiaFQVTau0vULqRAwe3IJ3XbrHsCl/mEimEPH3lse0/+ZnCbrmC6bRQf327gbOk53PWeagLH/mxXK188073Ju037d9w6b/5pkrfCSpTIaQ4Q0y7bhHp9CgmvU6xAzFW2QsglMUIefGKcpPeJ3RkA/iJH9dLGkTaVeRBwTleS4kAhQVHO/RdeTnJPAazm5KWX3WoTOo9Fd0B/ShJddHVEB2FpkVhNIQ3USxLMq8N8IExWLF99tLcIeM3kK1cMVW1wJMdEXe/v9ifzkrv3OCveKgfIuzULRFrlPxKSS9DLSQWtIFZKUFG6Doj4hw+679fNdfW3FvDUWgJNTjPskxMfxpsbn7IAqxx4dY2iLH4O1eHKoLIwsZ0KUZPr8O8HI6QM5YhtRJNPmukcAvdXtErl1w29YMorUmNDc/LM0gl1zjLEc8jt2/TTPsUNitzhqZiBZhMmFk9USrvpcTsik6HFw4vmfR4sCn4dygOV/P4k=
|
14
|
+
deploy:
|
15
|
+
provider: rubygems
|
16
|
+
api_key:
|
17
|
+
secure: shl5iQVT11TYdOTEy9rXePLOukcInAIoYUdzeXEKwiszwxJ0XKC62DRBkXqIKf9goYyHnd96EQfYFBy9yjbtcwp/pJ9TUxOFBIIwr1OJduble8WduJgAgG3xIG7i7gUB7DnCDSC8jdKO28v03UzyvZw5zNFzzugzPy+H27BHcfp1KEoor31U0uMS/4qjfSAmS8mxejuPj5JmL8GKghMcGbLNOY8lqDLNfF5mCaYCBUrnFsqxlnbQsnymAsZKQXtdg3fUV6GHfV/YTOdA8rdmVUBaiQMV8JZZNE0PZG+neJ/3uIW+MHB8PZdz5Df5BwB/G1cw77A42pjO0UNTgImeDPXsGLkOmI5rl0hrxigLJ6GjV+Qur//kNlSusmbKIA6YMmnCd2NPVYt7BUejtS/kUIPBC9Lppq2BQTbkpXhy51a9e4kKH6zNw173XIHwLAj9c4+c/H5Pde7zfXNGp1pPQ17tk+Bk6G7Sosfb+ZBY0elmoZCNwr0DDi6icVujkg70CHTzEfzx/fI8ejZ/L0dVuB9kGZ9MZ3MWd38//Zp4jWzKD422nHdh1RlU7jR4M2rn9WKPW8l6mKJ9r1ozK/hyLqcQGKl/QqXNBc7oOL8rYLXszbmHqq99uE1+uw+oQP0e+SkX/F2w6gWHX4n9VY0hUMzz4y/QUG4iM3/1yIZtJgo=
|
18
|
+
gem: device_wizard
|
19
|
+
on:
|
20
|
+
tags: true
|
21
|
+
repo: Sage/device_wizard
|
22
|
+
condition: "$TRAVIS_RUBY_VERSION == 2.3.5"
|
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# DeviceWizard
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/Sage/device_wizard.svg?branch=master)](https://travis-ci.org/Sage/device_wizard)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/f0d6439302f953419f93/maintainability)](https://codeclimate.com/github/Sage/device_wizard/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/f0d6439302f953419f93/test_coverage)](https://codeclimate.com/github/Sage/device_wizard/test_coverage)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/device_wizard.svg)](https://badge.fury.io/rb/device_wizard)
|
7
|
+
|
3
8
|
Welcome to DeviceWizard!
|
4
9
|
|
5
10
|
The super fast, ultra light weight device detection framework.
|
@@ -16,53 +21,63 @@ gem 'device_wizard'
|
|
16
21
|
|
17
22
|
And then execute:
|
18
23
|
|
19
|
-
|
24
|
+
```bash
|
25
|
+
$ bundle
|
26
|
+
```
|
20
27
|
|
21
28
|
Or install it yourself as:
|
22
29
|
|
23
|
-
|
30
|
+
```bash
|
31
|
+
$ gem install device_wizard
|
32
|
+
```
|
24
33
|
|
25
34
|
## Usage
|
26
35
|
|
27
36
|
**Identify All Details**
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
```ruby
|
39
|
+
#create the user agent detector
|
40
|
+
detector = DeviceWizard::UserAgentDetector.new
|
41
|
+
|
42
|
+
#pass the user agent to the detector
|
43
|
+
details = detector.get_details(user_agent)
|
44
|
+
```
|
45
|
+
|
35
46
|
The detected details will return the following:
|
36
47
|
- **Type** This is the device type of the request [mobile/tablet/desktop etc]
|
37
48
|
- **Browser** This is the browser of the request {name, version}
|
38
49
|
|
50
|
+
```ruby
|
51
|
+
browser = details.browser
|
52
|
+
|
53
|
+
browser_name = details.browser.name
|
54
|
+
|
55
|
+
browser_version = details.browser.version
|
56
|
+
```
|
39
57
|
|
40
|
-
browser = details.browser
|
41
|
-
|
42
|
-
browser_name = details.browser.name
|
43
|
-
|
44
|
-
browser_version = details.browser.version
|
45
|
-
|
46
58
|
- **OS** This is the operating system of the request {name, type, version}
|
47
59
|
|
60
|
+
```ruby
|
61
|
+
os = details.os
|
62
|
+
|
63
|
+
os_name = details.os.name
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
os_type = details.os.type
|
54
|
-
|
55
|
-
os_version = details.os.version
|
65
|
+
os_type = details.os.type
|
66
|
+
|
67
|
+
os_version = details.os.version
|
68
|
+
```
|
56
69
|
|
57
70
|
|
58
71
|
**Identify Device Type**
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
```ruby
|
74
|
+
#create the user agent detector
|
75
|
+
detector = DeviceWizard::UserAgentDetector.new
|
76
|
+
|
77
|
+
#pass the user agent to the detector
|
78
|
+
device_type = detector.get_device_type(user_agent_string)
|
79
|
+
```
|
80
|
+
|
66
81
|
The detected device type will be one of the following:
|
67
82
|
- **desktop**
|
68
83
|
- **tablet**
|
@@ -80,10 +95,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
80
95
|
|
81
96
|
## Contributing
|
82
97
|
|
83
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sage/device_wizard. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
84
99
|
|
85
100
|
|
86
101
|
## License
|
87
102
|
|
88
|
-
|
103
|
+
This gem is available as open source under the terms of the
|
104
|
+
[MIT licence](LICENSE).
|
89
105
|
|
106
|
+
Copyright (c) 2018 Sage Group Plc. All rights reserved.
|
data/Rakefile
CHANGED
data/device_wizard.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'device_wizard/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'device_wizard'
|
8
7
|
spec.version = DeviceWizard::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['vaughanbrittonsage']
|
9
|
+
spec.email = ['vaughan.britton@sage.com']
|
11
10
|
|
12
11
|
spec.summary = 'A fast & lightweight device detection framework.'
|
13
12
|
spec.description = "A device detection framework that is not based on lookup dictionaries, which makes this framework extra light weight, ultra fast and future proof as new devices don't need to be added into the framework."
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/sage/device_wizard'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
19
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
21
20
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'simplecov'
|
25
25
|
end
|
data/lib/device_wizard.rb
CHANGED
@@ -1,435 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
DESKTOP='desktop'
|
9
|
-
TABLET='tablet'
|
10
|
-
MOBILE='mobile'
|
11
|
-
CRAWLER='crawler'
|
12
|
-
UNKNOWN='unknown'
|
13
|
-
end
|
14
|
-
|
15
|
-
class UserAgentDetector
|
16
|
-
|
17
|
-
#########
|
18
|
-
##CONST Keywords
|
19
|
-
MOBILE = 'mobile'
|
20
|
-
IPAD = 'ipad'
|
21
|
-
IPHONE = 'iphone'
|
22
|
-
ANDROID = 'android'
|
23
|
-
TABLET = 'tablet'
|
24
|
-
SILK = 'silk'
|
25
|
-
#########
|
26
|
-
|
27
|
-
#########
|
28
|
-
##CONST Regex Patterns
|
29
|
-
#########
|
30
|
-
REGEX_OS = /(windows|linux|os\s+[x9]|solaris|bsd)/
|
31
|
-
REGEX_MOBILE = /(iphone|ipod|blackberry|android|palm|windows\s+ce|mobile|symbian|phone)/
|
32
|
-
REGEX_CRAWLER = /(spider|crawl|slurp|bot)/
|
33
|
-
#########
|
34
|
-
|
35
|
-
def initialize
|
36
|
-
@browser_resolvers = []
|
37
|
-
@browser_resolvers.push(FirefoxResolver.new)
|
38
|
-
@browser_resolvers.push(GoogleChromeResolver.new)
|
39
|
-
@browser_resolvers.push(InternetExplorerResolver.new)
|
40
|
-
@browser_resolvers.push(SafariResolver.new)
|
41
|
-
|
42
|
-
@os_resolvers = []
|
43
|
-
@os_resolvers.push(AndroidResolver.new)
|
44
|
-
@os_resolvers.push(IOSResolver.new)
|
45
|
-
@os_resolvers.push(MacResolver.new)
|
46
|
-
@os_resolvers.push(WindowsResolver.new)
|
47
|
-
end
|
48
|
-
|
49
|
-
def unknown
|
50
|
-
UNKNOWN
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_device_type(user_agent)
|
54
|
-
|
55
|
-
if user_agent.to_s.strip.length == 0
|
56
|
-
return DeviceType::UNKNOWN
|
57
|
-
end
|
58
|
-
|
59
|
-
user_agent.downcase!
|
60
|
-
|
61
|
-
if user_agent.include? TABLET
|
62
|
-
return DeviceType::TABLET
|
63
|
-
end
|
64
|
-
|
65
|
-
if user_agent.include? MOBILE
|
66
|
-
if user_agent.include? IPAD
|
67
|
-
return DeviceType::TABLET
|
68
|
-
else
|
69
|
-
return DeviceType::MOBILE
|
70
|
-
end
|
71
|
-
elsif user_agent.include? ANDROID
|
72
|
-
return DeviceType::TABLET
|
73
|
-
end
|
74
|
-
|
75
|
-
if REGEX_MOBILE =~ user_agent
|
76
|
-
return DeviceType::MOBILE
|
77
|
-
end
|
78
|
-
|
79
|
-
if user_agent.include? SILK
|
80
|
-
return DeviceType::TABLET
|
81
|
-
end
|
82
|
-
|
83
|
-
if REGEX_OS =~ user_agent
|
84
|
-
return DeviceType::DESKTOP
|
85
|
-
end
|
86
|
-
|
87
|
-
if REGEX_CRAWLER =~ user_agent
|
88
|
-
return DeviceType::CRAWLER
|
89
|
-
end
|
90
|
-
|
91
|
-
return DeviceType::UNKNOWN
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def get_browser(user_agent)
|
96
|
-
|
97
|
-
@browser_resolvers.each do |r|
|
98
|
-
|
99
|
-
browser = r.identify(user_agent)
|
100
|
-
|
101
|
-
if browser != nil
|
102
|
-
return browser
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
return BrowserDetails.new
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
def get_os(user_agent)
|
112
|
-
|
113
|
-
@os_resolvers.each do |r|
|
114
|
-
|
115
|
-
os = r.identify(user_agent)
|
116
|
-
|
117
|
-
if os != nil
|
118
|
-
return os
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
return OperatingSystemDetails.new
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
def get_details(user_agent)
|
128
|
-
details = DeviceDetails.new
|
129
|
-
|
130
|
-
details.type = get_device_type(user_agent)
|
131
|
-
details.browser = get_browser(user_agent)
|
132
|
-
details.os = get_os(user_agent)
|
133
|
-
|
134
|
-
return details
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
class DeviceDetails
|
140
|
-
attr_accessor :type
|
141
|
-
attr_accessor :browser
|
142
|
-
attr_accessor :os
|
143
|
-
end
|
144
|
-
|
145
|
-
class BrowserDetails
|
146
|
-
attr_accessor :name
|
147
|
-
attr_accessor :version
|
148
|
-
|
149
|
-
def initialize
|
150
|
-
@name = UNKNOWN
|
151
|
-
@version = UNKNOWN
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
class FirefoxResolver
|
156
|
-
|
157
|
-
KEYWORD = 'firefox'
|
158
|
-
REGEX = Regexp.new('firefox/([0-9]+.[0-9])')
|
159
|
-
|
160
|
-
def get_version(user_agent)
|
161
|
-
user_agent.downcase!
|
162
|
-
result = UNKNOWN
|
163
|
-
|
164
|
-
if REGEX =~ user_agent
|
165
|
-
result = $1
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def identify(user_agent)
|
170
|
-
user_agent.downcase!
|
171
|
-
|
172
|
-
if !user_agent.include? KEYWORD
|
173
|
-
return nil
|
174
|
-
end
|
175
|
-
|
176
|
-
result = BrowserDetails.new
|
177
|
-
result.name = 'Firefox'
|
178
|
-
result.version = get_version(user_agent)
|
179
|
-
return result
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
class GoogleChromeResolver
|
184
|
-
|
185
|
-
KEYWORD = 'chrome'
|
186
|
-
REGEX = Regexp.new('chrome/([0-9]+.[0-9]+.[0-9]+.[0-9])')
|
187
|
-
|
188
|
-
def get_version(user_agent)
|
189
|
-
user_agent.downcase!
|
190
|
-
result = UNKNOWN
|
191
|
-
|
192
|
-
if REGEX =~ user_agent
|
193
|
-
result = $1
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def identify(user_agent)
|
198
|
-
user_agent.downcase!
|
199
|
-
|
200
|
-
if !user_agent.include? KEYWORD
|
201
|
-
return nil
|
202
|
-
end
|
203
|
-
|
204
|
-
result = BrowserDetails.new
|
205
|
-
result.name = 'Google Chrome'
|
206
|
-
result.version = get_version(user_agent)
|
207
|
-
return result
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
class InternetExplorerResolver
|
213
|
-
KEYWORD = 'msie'
|
214
|
-
KEYWORD2 = ' rv:'
|
215
|
-
REGEX = Regexp.new('msie ([0-9]+.[0-9])')
|
216
|
-
REGEX2 = Regexp.new('rv:([0-9]+.[0-9])')
|
217
|
-
|
218
|
-
def get_version(user_agent)
|
219
|
-
user_agent.downcase!
|
220
|
-
result = UNKNOWN
|
221
|
-
|
222
|
-
if REGEX =~ user_agent
|
223
|
-
return result = $1
|
224
|
-
end
|
225
|
-
if REGEX2 =~ user_agent
|
226
|
-
return result = $1
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def identify(user_agent)
|
231
|
-
user_agent.downcase!
|
232
|
-
|
233
|
-
if !user_agent.include? KEYWORD
|
234
|
-
if !user_agent.include? KEYWORD2
|
235
|
-
return nil
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
result = BrowserDetails.new
|
240
|
-
result.name = 'Internet Explorer'
|
241
|
-
result.version = get_version(user_agent)
|
242
|
-
return result
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
class SafariResolver
|
248
|
-
|
249
|
-
KEYWORD = 'safari'
|
250
|
-
REGEX = Regexp.new('safari/([\.0-9]{3,})')
|
251
|
-
|
252
|
-
def get_version(user_agent)
|
253
|
-
user_agent.downcase!
|
254
|
-
result = UNKNOWN
|
255
|
-
|
256
|
-
if REGEX =~ user_agent
|
257
|
-
result = $1
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def identify(user_agent)
|
262
|
-
user_agent.downcase!
|
263
|
-
|
264
|
-
if !user_agent.include? KEYWORD
|
265
|
-
return nil
|
266
|
-
end
|
267
|
-
|
268
|
-
result = BrowserDetails.new
|
269
|
-
result.name = 'Safari'
|
270
|
-
result.version = get_version(user_agent)
|
271
|
-
return result
|
272
|
-
end
|
273
|
-
|
274
|
-
end
|
275
|
-
|
276
|
-
class OperatingSystemDetails
|
277
|
-
|
278
|
-
attr_accessor :name
|
279
|
-
attr_accessor :type
|
280
|
-
attr_accessor :version
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
|
-
class AndroidResolver
|
285
|
-
|
286
|
-
KEYWORD = 'android'
|
287
|
-
REGEX = Regexp.new('android (\d+(?:\.\d+)+)')
|
288
|
-
|
289
|
-
def get_version(user_agent)
|
290
|
-
user_agent.downcase!
|
291
|
-
result = UNKNOWN
|
292
|
-
|
293
|
-
if REGEX =~ user_agent
|
294
|
-
result = $1
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def identify(user_agent)
|
299
|
-
user_agent.downcase!
|
300
|
-
|
301
|
-
if !user_agent.include? KEYWORD
|
302
|
-
return nil
|
303
|
-
end
|
304
|
-
|
305
|
-
result = OperatingSystemDetails.new
|
306
|
-
result.name = 'Android'
|
307
|
-
result.version = get_version(user_agent)
|
308
|
-
return result
|
309
|
-
end
|
310
|
-
|
311
|
-
end
|
312
|
-
|
313
|
-
class IOSResolver
|
314
|
-
|
315
|
-
IPHONE = 'iphone'
|
316
|
-
IPAD = 'ipad'
|
317
|
-
IPOD = 'ipod'
|
318
|
-
REGEX = Regexp.new('os ((\d+_?){2,3})\s')
|
319
|
-
|
320
|
-
def get_version(user_agent)
|
321
|
-
user_agent.downcase!
|
322
|
-
result = UNKNOWN
|
323
|
-
|
324
|
-
if REGEX =~ user_agent
|
325
|
-
result = $1
|
326
|
-
end
|
327
|
-
|
328
|
-
return result.gsub('_','.')
|
329
|
-
end
|
330
|
-
|
331
|
-
def get_type(user_agent)
|
332
|
-
user_agent.downcase!
|
333
|
-
|
334
|
-
if user_agent.include? IPOD
|
335
|
-
return 'IPod'
|
336
|
-
end
|
337
|
-
|
338
|
-
if user_agent.include? IPAD
|
339
|
-
return 'IPad'
|
340
|
-
end
|
341
|
-
|
342
|
-
if user_agent.include? IPHONE
|
343
|
-
return 'IPhone'
|
344
|
-
end
|
345
|
-
|
346
|
-
return UNKNOWN
|
347
|
-
end
|
348
|
-
|
349
|
-
def identify(user_agent)
|
350
|
-
user_agent.downcase!
|
351
|
-
|
352
|
-
if !user_agent.include? IPHONE
|
353
|
-
if !user_agent.include? IPAD
|
354
|
-
if !user_agent.include? IPOD
|
355
|
-
return nil
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
result = OperatingSystemDetails.new
|
361
|
-
result.name = 'IOS'
|
362
|
-
result.type = get_type(user_agent)
|
363
|
-
result.version = get_version(user_agent)
|
364
|
-
return result
|
365
|
-
end
|
366
|
-
|
367
|
-
end
|
368
|
-
|
369
|
-
class MacResolver
|
370
|
-
|
371
|
-
KEYWORD = 'intel mac os x'
|
372
|
-
REGEX = Regexp.new('intel mac os x ([0-9]+_[0-9])')
|
373
|
-
|
374
|
-
def get_version(user_agent)
|
375
|
-
user_agent.downcase!
|
376
|
-
result = UNKNOWN
|
377
|
-
|
378
|
-
if REGEX =~ user_agent
|
379
|
-
result = $1
|
380
|
-
end
|
381
|
-
|
382
|
-
return result.gsub('_','.')
|
383
|
-
end
|
384
|
-
|
385
|
-
def identify(user_agent)
|
386
|
-
user_agent.downcase!
|
387
|
-
|
388
|
-
if !user_agent.include? KEYWORD
|
389
|
-
return nil
|
390
|
-
end
|
391
|
-
|
392
|
-
result = OperatingSystemDetails.new
|
393
|
-
result.name = 'Mac OSX'
|
394
|
-
result.version = get_version(user_agent)
|
395
|
-
return result
|
396
|
-
end
|
397
|
-
|
398
|
-
end
|
399
|
-
|
400
|
-
class WindowsResolver
|
401
|
-
|
402
|
-
KEYWORD = 'windows nt'
|
403
|
-
REGEX = Regexp.new('windows nt ([0-9]{1,}[\.0-9]{0,})')
|
404
|
-
NTVERSION = [ '4.0', '5.0', '5.01', '5.1', '5.2', '6.0', '6.1', '6.2', '6.3' ]
|
405
|
-
NTNAME = [ 'NT 4.0', '2000', '2000 SP1', 'XP', 'XP x64', 'Vista', '7', '8', '8.1' ]
|
406
|
-
|
407
|
-
def get_version(user_agent)
|
408
|
-
user_agent.downcase!
|
409
|
-
result = UNKNOWN
|
410
|
-
|
411
|
-
if REGEX =~ user_agent
|
412
|
-
if NTVERSION.index($1)
|
413
|
-
result = NTNAME[NTVERSION.index($1)]
|
414
|
-
else
|
415
|
-
result = $1
|
416
|
-
end
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
def identify(user_agent)
|
421
|
-
user_agent.downcase!
|
422
|
-
|
423
|
-
if !user_agent.include? KEYWORD
|
424
|
-
return nil
|
425
|
-
end
|
426
|
-
|
427
|
-
result = OperatingSystemDetails.new
|
428
|
-
result.name = 'Windows'
|
429
|
-
result.version = get_version(user_agent)
|
430
|
-
return result
|
431
|
-
end
|
432
|
-
|
433
|
-
end
|
3
|
+
require 'device_wizard/details'
|
4
|
+
require 'device_wizard/device_type'
|
5
|
+
require 'device_wizard/resolvers'
|
6
|
+
require 'device_wizard/user_agent_detector'
|
7
|
+
require 'device_wizard/version'
|
434
8
|
|
9
|
+
module DeviceWizard
|
10
|
+
UNKNOWN = 'Unknown'
|
435
11
|
end
|