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
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'device_wizard/resolvers/base'
|
4
|
+
|
5
|
+
require 'device_wizard/resolvers/android'
|
6
|
+
require 'device_wizard/resolvers/firefox'
|
7
|
+
require 'device_wizard/resolvers/google_chrome'
|
8
|
+
require 'device_wizard/resolvers/internet_explorer'
|
9
|
+
require 'device_wizard/resolvers/ios'
|
10
|
+
require 'device_wizard/resolvers/mac'
|
11
|
+
require 'device_wizard/resolvers/safari'
|
12
|
+
require 'device_wizard/resolvers/windows'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class Android < Base
|
6
|
+
NAME = 'Android'
|
7
|
+
KEYWORD = 'android'
|
8
|
+
REGEX = Regexp.new('android (\d+(?:\.\d+)+)')
|
9
|
+
|
10
|
+
def details_klass
|
11
|
+
Details::OperatingSystem
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class Base
|
6
|
+
def get_version(user_agent)
|
7
|
+
user_agent.downcase!
|
8
|
+
result = UNKNOWN
|
9
|
+
result = $1 if self.class::REGEX =~ user_agent
|
10
|
+
end
|
11
|
+
|
12
|
+
def identify(user_agent)
|
13
|
+
user_agent.downcase!
|
14
|
+
|
15
|
+
return unless user_agent.include? self.class::KEYWORD
|
16
|
+
|
17
|
+
result = details_klass.new
|
18
|
+
result.name = self.class::NAME
|
19
|
+
result.version = get_version(user_agent)
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def details_klass
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
require 'device_wizard/resolvers/base'
|
6
|
+
|
7
|
+
class Firefox < Base
|
8
|
+
NAME = 'Firefox'
|
9
|
+
KEYWORD = 'firefox'
|
10
|
+
REGEX = Regexp.new('firefox/([0-9]+.[0-9])')
|
11
|
+
|
12
|
+
def details_klass
|
13
|
+
Details::Browser
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class GoogleChrome < Base
|
6
|
+
NAME = 'Google Chrome'
|
7
|
+
KEYWORD = 'chrome'
|
8
|
+
REGEX = Regexp.new('chrome/([0-9]+.[0-9]+.[0-9]+.[0-9])')
|
9
|
+
|
10
|
+
def details_klass
|
11
|
+
Details::Browser
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class InternetExplorer < Base
|
6
|
+
NAME = 'Internet Explorer'
|
7
|
+
KEYWORD = 'msie'
|
8
|
+
KEYWORD2 = ' rv:'
|
9
|
+
REGEX = Regexp.new('msie ([0-9]+.[0-9])')
|
10
|
+
REGEX2 = Regexp.new('rv:([0-9]+.[0-9])')
|
11
|
+
|
12
|
+
def get_version(user_agent)
|
13
|
+
user_agent.downcase!
|
14
|
+
result = UNKNOWN
|
15
|
+
|
16
|
+
return result = $1 if REGEX =~ user_agent
|
17
|
+
return result = $1 if REGEX2 =~ user_agent
|
18
|
+
end
|
19
|
+
|
20
|
+
def identify(user_agent)
|
21
|
+
user_agent.downcase!
|
22
|
+
|
23
|
+
unless user_agent.include? KEYWORD
|
24
|
+
return unless user_agent.include? KEYWORD2
|
25
|
+
end
|
26
|
+
|
27
|
+
result = details_klass.new
|
28
|
+
result.name = NAME
|
29
|
+
result.version = get_version(user_agent)
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
def details_klass
|
34
|
+
Details::Browser
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class IOS < Base
|
6
|
+
NAME = 'IOS'
|
7
|
+
IPHONE = 'iphone'
|
8
|
+
IPAD = 'ipad'
|
9
|
+
IPOD = 'ipod'
|
10
|
+
REGEX = Regexp.new('os ((\d+_?){2,3})\s')
|
11
|
+
|
12
|
+
def get_version(user_agent)
|
13
|
+
result = super(user_agent)
|
14
|
+
result.gsub('_','.')
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_type(user_agent)
|
18
|
+
user_agent.downcase!
|
19
|
+
|
20
|
+
return 'IPod' if user_agent.include? IPOD
|
21
|
+
return 'IPad' if user_agent.include? IPAD
|
22
|
+
return 'IPhone' if user_agent.include? IPHONE
|
23
|
+
return UNKNOWN
|
24
|
+
end
|
25
|
+
|
26
|
+
def identify(user_agent)
|
27
|
+
user_agent.downcase!
|
28
|
+
|
29
|
+
return unless [IPHONE, IPAD, IPOD].any? { |i| user_agent.include? i }
|
30
|
+
|
31
|
+
result = details_klass.new
|
32
|
+
result.name = NAME
|
33
|
+
result.type = get_type(user_agent)
|
34
|
+
result.version = get_version(user_agent)
|
35
|
+
return result
|
36
|
+
end
|
37
|
+
|
38
|
+
def details_klass
|
39
|
+
Details::OperatingSystem
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class Mac < Base
|
6
|
+
NAME = 'Mac OSX'
|
7
|
+
KEYWORD = 'intel mac os x'
|
8
|
+
REGEX = Regexp.new('intel mac os x ([0-9]+_[0-9])')
|
9
|
+
|
10
|
+
def get_version(user_agent)
|
11
|
+
result = super(user_agent)
|
12
|
+
result.gsub('_','.')
|
13
|
+
end
|
14
|
+
|
15
|
+
def details_klass
|
16
|
+
Details::OperatingSystem
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
module Resolvers
|
5
|
+
class Windows < Base
|
6
|
+
NAME = 'Windows'
|
7
|
+
KEYWORD = 'windows nt'
|
8
|
+
REGEX = Regexp.new('windows nt ([0-9]{1,}[\.0-9]{0,})')
|
9
|
+
NTVERSION = [ '4.0', '5.0', '5.01', '5.1', '5.2', '6.0', '6.1', '6.2', '6.3' ]
|
10
|
+
NTNAME = [ 'NT 4.0', '2000', '2000 SP1', 'XP', 'XP x64', 'Vista', '7', '8', '8.1' ]
|
11
|
+
|
12
|
+
def get_version(user_agent)
|
13
|
+
user_agent.downcase!
|
14
|
+
result = UNKNOWN
|
15
|
+
|
16
|
+
if REGEX =~ user_agent
|
17
|
+
if NTVERSION.index($1)
|
18
|
+
result = NTNAME[NTVERSION.index($1)]
|
19
|
+
else
|
20
|
+
result = $1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def details_klass
|
26
|
+
Details::OperatingSystem
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviceWizard
|
4
|
+
class UserAgentDetector
|
5
|
+
#########
|
6
|
+
##CONST Keywords
|
7
|
+
MOBILE = 'mobile'
|
8
|
+
IPAD = 'ipad'
|
9
|
+
IPHONE = 'iphone'
|
10
|
+
ANDROID = 'android'
|
11
|
+
TABLET = 'tablet'
|
12
|
+
SILK = 'silk'
|
13
|
+
#########
|
14
|
+
|
15
|
+
#########
|
16
|
+
##CONST Regex Patterns
|
17
|
+
#########
|
18
|
+
REGEX_OS = /(windows|linux|os\s+[x9]|solaris|bsd)/
|
19
|
+
REGEX_MOBILE = /(iphone|ipod|blackberry|android|palm|windows\s+ce|mobile|symbian|phone)/
|
20
|
+
REGEX_CRAWLER = /(spider|crawl|slurp|bot)/
|
21
|
+
#########
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@browser_resolvers = []
|
25
|
+
@browser_resolvers.push(Resolvers::Firefox.new)
|
26
|
+
@browser_resolvers.push(Resolvers::GoogleChrome.new)
|
27
|
+
@browser_resolvers.push(Resolvers::InternetExplorer.new)
|
28
|
+
@browser_resolvers.push(Resolvers::Safari.new)
|
29
|
+
|
30
|
+
@os_resolvers = []
|
31
|
+
@os_resolvers.push(Resolvers::Android.new)
|
32
|
+
@os_resolvers.push(Resolvers::IOS.new)
|
33
|
+
@os_resolvers.push(Resolvers::Mac.new)
|
34
|
+
@os_resolvers.push(Resolvers::Windows.new)
|
35
|
+
end
|
36
|
+
|
37
|
+
def unknown
|
38
|
+
UNKNOWN
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_device_type(user_agent)
|
42
|
+
if user_agent.to_s.strip.length == 0
|
43
|
+
return DeviceType::UNKNOWN
|
44
|
+
end
|
45
|
+
|
46
|
+
user_agent.downcase!
|
47
|
+
|
48
|
+
if user_agent.include? TABLET
|
49
|
+
return DeviceType::TABLET
|
50
|
+
end
|
51
|
+
|
52
|
+
type = determine_type(user_agent)
|
53
|
+
type || DeviceType::UNKNOWN
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_browser(user_agent)
|
57
|
+
@browser_resolvers.each do |r|
|
58
|
+
browser = r.identify(user_agent)
|
59
|
+
return browser unless browser.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
Details::Browser.new
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_os(user_agent)
|
66
|
+
@os_resolvers.each do |r|
|
67
|
+
os = r.identify(user_agent)
|
68
|
+
return os unless os.nil?
|
69
|
+
end
|
70
|
+
|
71
|
+
Details::OperatingSystem.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_details(user_agent)
|
75
|
+
details = Details::Device.new
|
76
|
+
details.type = get_device_type(user_agent)
|
77
|
+
details.browser = get_browser(user_agent)
|
78
|
+
details.os = get_os(user_agent)
|
79
|
+
details
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def determine_type(user_agent)
|
85
|
+
return DeviceType::TABLET if user_agent.include? TABLET
|
86
|
+
|
87
|
+
if user_agent.include? MOBILE
|
88
|
+
if user_agent.include? IPAD
|
89
|
+
return DeviceType::TABLET
|
90
|
+
else
|
91
|
+
return DeviceType::MOBILE
|
92
|
+
end
|
93
|
+
elsif user_agent.include? ANDROID
|
94
|
+
return DeviceType::TABLET
|
95
|
+
end
|
96
|
+
|
97
|
+
return DeviceType::MOBILE if REGEX_MOBILE =~ user_agent
|
98
|
+
return DeviceType::TABLET if user_agent.include? SILK
|
99
|
+
return DeviceType::DESKTOP if REGEX_OS =~ user_agent
|
100
|
+
return DeviceType::CRAWLER if REGEX_CRAWLER =~ user_agent
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: device_wizard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,46 +42,69 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
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
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
description: A device detection framework that is not based on lookup dictionaries,
|
56
70
|
which makes this framework extra light weight, ultra fast and future proof as new
|
57
71
|
devices don't need to be added into the framework.
|
58
72
|
email:
|
59
|
-
-
|
73
|
+
- vaughan.britton@sage.com
|
60
74
|
executables: []
|
61
75
|
extensions: []
|
62
76
|
extra_rdoc_files: []
|
63
77
|
files:
|
64
78
|
- ".gitignore"
|
65
|
-
- ".idea/.name"
|
66
|
-
- ".idea/.rakeTasks"
|
67
|
-
- ".idea/device_wizard.iml"
|
68
|
-
- ".idea/encodings.xml"
|
69
|
-
- ".idea/misc.xml"
|
70
|
-
- ".idea/modules.xml"
|
71
|
-
- ".idea/vcs.xml"
|
72
|
-
- ".idea/workspace.xml"
|
73
79
|
- ".rspec"
|
80
|
+
- ".travis.yml"
|
74
81
|
- CODE_OF_CONDUCT.md
|
75
82
|
- Gemfile
|
76
|
-
- LICENSE
|
83
|
+
- LICENSE
|
77
84
|
- README.md
|
78
85
|
- Rakefile
|
79
86
|
- bin/console
|
80
87
|
- bin/setup
|
81
88
|
- device_wizard.gemspec
|
82
89
|
- lib/device_wizard.rb
|
90
|
+
- lib/device_wizard/details.rb
|
91
|
+
- lib/device_wizard/details/browser.rb
|
92
|
+
- lib/device_wizard/details/device.rb
|
93
|
+
- lib/device_wizard/details/operating_system.rb
|
94
|
+
- lib/device_wizard/device_type.rb
|
95
|
+
- lib/device_wizard/resolvers.rb
|
96
|
+
- lib/device_wizard/resolvers/android.rb
|
97
|
+
- lib/device_wizard/resolvers/base.rb
|
98
|
+
- lib/device_wizard/resolvers/firefox.rb
|
99
|
+
- lib/device_wizard/resolvers/google_chrome.rb
|
100
|
+
- lib/device_wizard/resolvers/internet_explorer.rb
|
101
|
+
- lib/device_wizard/resolvers/ios.rb
|
102
|
+
- lib/device_wizard/resolvers/mac.rb
|
103
|
+
- lib/device_wizard/resolvers/safari.rb
|
104
|
+
- lib/device_wizard/resolvers/windows.rb
|
105
|
+
- lib/device_wizard/user_agent_detector.rb
|
83
106
|
- lib/device_wizard/version.rb
|
84
|
-
homepage: https://github.com/
|
107
|
+
homepage: https://github.com/sage/device_wizard
|
85
108
|
licenses:
|
86
109
|
- MIT
|
87
110
|
metadata: {}
|
@@ -101,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
124
|
version: '0'
|
102
125
|
requirements: []
|
103
126
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.6
|
105
128
|
signing_key:
|
106
129
|
specification_version: 4
|
107
130
|
summary: A fast & lightweight device detection framework.
|
108
131
|
test_files: []
|
109
|
-
has_rdoc:
|