device_detector 1.0.3 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +8 -7
  4. data/lib/device_detector/bot.rb +2 -2
  5. data/lib/device_detector/browser.rb +364 -0
  6. data/lib/device_detector/client.rb +11 -2
  7. data/lib/device_detector/device.rb +1247 -22
  8. data/lib/device_detector/memory_cache.rb +5 -5
  9. data/lib/device_detector/metadata_extractor.rb +7 -8
  10. data/lib/device_detector/model_extractor.rb +3 -3
  11. data/lib/device_detector/name_extractor.rb +2 -2
  12. data/lib/device_detector/os.rb +150 -116
  13. data/lib/device_detector/parser.rb +23 -10
  14. data/lib/device_detector/version.rb +1 -1
  15. data/lib/device_detector/version_extractor.rb +29 -2
  16. data/lib/device_detector.rb +73 -40
  17. data/regexes/bots.yml +868 -62
  18. data/regexes/client/browser_engine.yml +11 -2
  19. data/regexes/client/browsers.yml +1132 -112
  20. data/regexes/client/feed_readers.yml +5 -11
  21. data/regexes/client/libraries.yml +86 -2
  22. data/regexes/client/mediaplayers.yml +39 -3
  23. data/regexes/client/mobile_apps.yml +940 -66
  24. data/regexes/client/pim.yml +66 -3
  25. data/regexes/device/cameras.yml +6 -6
  26. data/regexes/device/car_browsers.yml +23 -3
  27. data/regexes/device/consoles.yml +15 -3
  28. data/regexes/device/mobiles.yml +18351 -3566
  29. data/regexes/device/notebooks.yml +114 -0
  30. data/regexes/device/portable_media_player.yml +36 -9
  31. data/regexes/device/shell_tv.yml +117 -0
  32. data/regexes/device/televisions.yml +440 -35
  33. data/regexes/oss.yml +635 -284
  34. data/regexes/vendorfragments.yml +5 -1
  35. metadata +21 -118
  36. data/.gitignore +0 -14
  37. data/.travis.yml +0 -14
  38. data/Gemfile +0 -8
  39. data/Rakefile +0 -96
  40. data/device_detector.gemspec +0 -26
  41. data/spec/device_detector/bot_fixtures_spec.rb +0 -30
  42. data/spec/device_detector/client_fixtures_spec.rb +0 -31
  43. data/spec/device_detector/concrete_user_agent_spec.rb +0 -135
  44. data/spec/device_detector/detector_fixtures_spec.rb +0 -100
  45. data/spec/device_detector/device_fixtures_spec.rb +0 -36
  46. data/spec/device_detector/device_spec.rb +0 -151
  47. data/spec/device_detector/memory_cache_spec.rb +0 -148
  48. data/spec/device_detector/model_extractor_spec.rb +0 -63
  49. data/spec/device_detector/os_fixtures_spec.rb +0 -26
  50. data/spec/device_detector/version_extractor_spec.rb +0 -79
  51. data/spec/device_detector_spec.rb +0 -189
  52. data/spec/fixtures/client/browser.yml +0 -2206
  53. data/spec/fixtures/client/feed_reader.yml +0 -199
  54. data/spec/fixtures/client/library.yml +0 -175
  55. data/spec/fixtures/client/mediaplayer.yml +0 -163
  56. data/spec/fixtures/client/mobile_app.yml +0 -193
  57. data/spec/fixtures/client/pim.yml +0 -115
  58. data/spec/fixtures/detector/bots.yml +0 -3260
  59. data/spec/fixtures/detector/camera.yml +0 -121
  60. data/spec/fixtures/detector/car_browser.yml +0 -21
  61. data/spec/fixtures/detector/console.yml +0 -281
  62. data/spec/fixtures/detector/desktop.yml +0 -5361
  63. data/spec/fixtures/detector/feature_phone.yml +0 -891
  64. data/spec/fixtures/detector/feed_reader.yml +0 -551
  65. data/spec/fixtures/detector/mediaplayer.yml +0 -210
  66. data/spec/fixtures/detector/mobile_apps.yml +0 -456
  67. data/spec/fixtures/detector/phablet.yml +0 -3785
  68. data/spec/fixtures/detector/portable_media_player.yml +0 -178
  69. data/spec/fixtures/detector/smart_display.yml +0 -61
  70. data/spec/fixtures/detector/smartphone-1.yml +0 -9953
  71. data/spec/fixtures/detector/smartphone-10.yml +0 -9924
  72. data/spec/fixtures/detector/smartphone-11.yml +0 -9889
  73. data/spec/fixtures/detector/smartphone-12.yml +0 -8655
  74. data/spec/fixtures/detector/smartphone-2.yml +0 -9967
  75. data/spec/fixtures/detector/smartphone-3.yml +0 -9887
  76. data/spec/fixtures/detector/smartphone-4.yml +0 -9911
  77. data/spec/fixtures/detector/smartphone-5.yml +0 -9933
  78. data/spec/fixtures/detector/smartphone-6.yml +0 -9923
  79. data/spec/fixtures/detector/smartphone-7.yml +0 -9892
  80. data/spec/fixtures/detector/smartphone-8.yml +0 -9896
  81. data/spec/fixtures/detector/smartphone-9.yml +0 -9928
  82. data/spec/fixtures/detector/smartphone.yml +0 -9984
  83. data/spec/fixtures/detector/tablet-1.yml +0 -10023
  84. data/spec/fixtures/detector/tablet-2.yml +0 -9968
  85. data/spec/fixtures/detector/tablet-3.yml +0 -7787
  86. data/spec/fixtures/detector/tablet.yml +0 -9951
  87. data/spec/fixtures/detector/tv.yml +0 -3333
  88. data/spec/fixtures/detector/unknown.yml +0 -3283
  89. data/spec/fixtures/device/camera.yml +0 -19
  90. data/spec/fixtures/device/car_browser.yml +0 -7
  91. data/spec/fixtures/device/console.yml +0 -79
  92. data/spec/fixtures/parser/oss.yml +0 -1047
  93. data/spec/fixtures/parser/vendorfragments.yml +0 -162
  94. data/spec/spec_helper.rb +0 -9
@@ -1,7 +1,7 @@
1
1
  ###############
2
2
  # Device Detector - The Universal Device Detection library for parsing User Agents
3
3
  #
4
- # @link http://piwik.org
4
+ # @link https://matomo.org
5
5
  # @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
6
6
  ###############
7
7
 
@@ -69,3 +69,7 @@ HP:
69
69
 
70
70
  Hyrican:
71
71
  - 'MANM(JS)?'
72
+
73
+ Ordissimo:
74
+ - 'Ordissimo'
75
+ - 'webissimo3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mati Sójka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-09 00:00:00.000000000 Z
12
+ date: 2022-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.85.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.85.1
56
70
  description: Precise and fast user agent parser and device detector, backed by the
57
71
  largest and most up-to-date agent and device database
58
72
  email:
@@ -61,16 +75,12 @@ executables: []
61
75
  extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
- - ".gitignore"
65
- - ".travis.yml"
66
78
  - CHANGELOG.md
67
- - Gemfile
68
79
  - LICENSE.txt
69
80
  - README.md
70
- - Rakefile
71
- - device_detector.gemspec
72
81
  - lib/device_detector.rb
73
82
  - lib/device_detector/bot.rb
83
+ - lib/device_detector/browser.rb
74
84
  - lib/device_detector/client.rb
75
85
  - lib/device_detector/device.rb
76
86
  - lib/device_detector/memory_cache.rb
@@ -93,64 +103,12 @@ files:
93
103
  - regexes/device/car_browsers.yml
94
104
  - regexes/device/consoles.yml
95
105
  - regexes/device/mobiles.yml
106
+ - regexes/device/notebooks.yml
96
107
  - regexes/device/portable_media_player.yml
108
+ - regexes/device/shell_tv.yml
97
109
  - regexes/device/televisions.yml
98
110
  - regexes/oss.yml
99
111
  - regexes/vendorfragments.yml
100
- - spec/device_detector/bot_fixtures_spec.rb
101
- - spec/device_detector/client_fixtures_spec.rb
102
- - spec/device_detector/concrete_user_agent_spec.rb
103
- - spec/device_detector/detector_fixtures_spec.rb
104
- - spec/device_detector/device_fixtures_spec.rb
105
- - spec/device_detector/device_spec.rb
106
- - spec/device_detector/memory_cache_spec.rb
107
- - spec/device_detector/model_extractor_spec.rb
108
- - spec/device_detector/os_fixtures_spec.rb
109
- - spec/device_detector/version_extractor_spec.rb
110
- - spec/device_detector_spec.rb
111
- - spec/fixtures/client/browser.yml
112
- - spec/fixtures/client/feed_reader.yml
113
- - spec/fixtures/client/library.yml
114
- - spec/fixtures/client/mediaplayer.yml
115
- - spec/fixtures/client/mobile_app.yml
116
- - spec/fixtures/client/pim.yml
117
- - spec/fixtures/detector/bots.yml
118
- - spec/fixtures/detector/camera.yml
119
- - spec/fixtures/detector/car_browser.yml
120
- - spec/fixtures/detector/console.yml
121
- - spec/fixtures/detector/desktop.yml
122
- - spec/fixtures/detector/feature_phone.yml
123
- - spec/fixtures/detector/feed_reader.yml
124
- - spec/fixtures/detector/mediaplayer.yml
125
- - spec/fixtures/detector/mobile_apps.yml
126
- - spec/fixtures/detector/phablet.yml
127
- - spec/fixtures/detector/portable_media_player.yml
128
- - spec/fixtures/detector/smart_display.yml
129
- - spec/fixtures/detector/smartphone-1.yml
130
- - spec/fixtures/detector/smartphone-10.yml
131
- - spec/fixtures/detector/smartphone-11.yml
132
- - spec/fixtures/detector/smartphone-12.yml
133
- - spec/fixtures/detector/smartphone-2.yml
134
- - spec/fixtures/detector/smartphone-3.yml
135
- - spec/fixtures/detector/smartphone-4.yml
136
- - spec/fixtures/detector/smartphone-5.yml
137
- - spec/fixtures/detector/smartphone-6.yml
138
- - spec/fixtures/detector/smartphone-7.yml
139
- - spec/fixtures/detector/smartphone-8.yml
140
- - spec/fixtures/detector/smartphone-9.yml
141
- - spec/fixtures/detector/smartphone.yml
142
- - spec/fixtures/detector/tablet-1.yml
143
- - spec/fixtures/detector/tablet-2.yml
144
- - spec/fixtures/detector/tablet-3.yml
145
- - spec/fixtures/detector/tablet.yml
146
- - spec/fixtures/detector/tv.yml
147
- - spec/fixtures/detector/unknown.yml
148
- - spec/fixtures/device/camera.yml
149
- - spec/fixtures/device/car_browser.yml
150
- - spec/fixtures/device/console.yml
151
- - spec/fixtures/parser/oss.yml
152
- - spec/fixtures/parser/vendorfragments.yml
153
- - spec/spec_helper.rb
154
112
  homepage: http://podigee.github.io/device_detector
155
113
  licenses:
156
114
  - LGPL-3.0
@@ -170,63 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
128
  - !ruby/object:Gem::Version
171
129
  version: '0'
172
130
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.5.1
131
+ rubygems_version: 3.0.3
175
132
  signing_key:
176
133
  specification_version: 4
177
134
  summary: Precise and fast user agent parser and device detector
178
- test_files:
179
- - spec/device_detector/bot_fixtures_spec.rb
180
- - spec/device_detector/client_fixtures_spec.rb
181
- - spec/device_detector/concrete_user_agent_spec.rb
182
- - spec/device_detector/detector_fixtures_spec.rb
183
- - spec/device_detector/device_fixtures_spec.rb
184
- - spec/device_detector/device_spec.rb
185
- - spec/device_detector/memory_cache_spec.rb
186
- - spec/device_detector/model_extractor_spec.rb
187
- - spec/device_detector/os_fixtures_spec.rb
188
- - spec/device_detector/version_extractor_spec.rb
189
- - spec/device_detector_spec.rb
190
- - spec/fixtures/client/browser.yml
191
- - spec/fixtures/client/feed_reader.yml
192
- - spec/fixtures/client/library.yml
193
- - spec/fixtures/client/mediaplayer.yml
194
- - spec/fixtures/client/mobile_app.yml
195
- - spec/fixtures/client/pim.yml
196
- - spec/fixtures/detector/bots.yml
197
- - spec/fixtures/detector/camera.yml
198
- - spec/fixtures/detector/car_browser.yml
199
- - spec/fixtures/detector/console.yml
200
- - spec/fixtures/detector/desktop.yml
201
- - spec/fixtures/detector/feature_phone.yml
202
- - spec/fixtures/detector/feed_reader.yml
203
- - spec/fixtures/detector/mediaplayer.yml
204
- - spec/fixtures/detector/mobile_apps.yml
205
- - spec/fixtures/detector/phablet.yml
206
- - spec/fixtures/detector/portable_media_player.yml
207
- - spec/fixtures/detector/smart_display.yml
208
- - spec/fixtures/detector/smartphone-1.yml
209
- - spec/fixtures/detector/smartphone-10.yml
210
- - spec/fixtures/detector/smartphone-11.yml
211
- - spec/fixtures/detector/smartphone-12.yml
212
- - spec/fixtures/detector/smartphone-2.yml
213
- - spec/fixtures/detector/smartphone-3.yml
214
- - spec/fixtures/detector/smartphone-4.yml
215
- - spec/fixtures/detector/smartphone-5.yml
216
- - spec/fixtures/detector/smartphone-6.yml
217
- - spec/fixtures/detector/smartphone-7.yml
218
- - spec/fixtures/detector/smartphone-8.yml
219
- - spec/fixtures/detector/smartphone-9.yml
220
- - spec/fixtures/detector/smartphone.yml
221
- - spec/fixtures/detector/tablet-1.yml
222
- - spec/fixtures/detector/tablet-2.yml
223
- - spec/fixtures/detector/tablet-3.yml
224
- - spec/fixtures/detector/tablet.yml
225
- - spec/fixtures/detector/tv.yml
226
- - spec/fixtures/detector/unknown.yml
227
- - spec/fixtures/device/camera.yml
228
- - spec/fixtures/device/car_browser.yml
229
- - spec/fixtures/device/console.yml
230
- - spec/fixtures/parser/oss.yml
231
- - spec/fixtures/parser/vendorfragments.yml
232
- - spec/spec_helper.rb
135
+ test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- dist: bionic
3
- rvm:
4
- - 2.4
5
- - 2.5
6
- - 2.6
7
- before_install:
8
- - gem update --system
9
- - gem --version
10
- - gem update bundler
11
- - bundler --version
12
- cache: bundler
13
- script:
14
- bundle exec rake test
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in device_detector.gemspec
4
- gemspec
5
-
6
- if RUBY_VERSION >= "2.0" && defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
7
- gem 'byebug'
8
- end
data/Rakefile DELETED
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rake'
4
- require 'rake/testtask'
5
-
6
- $LOAD_PATH.unshift 'lib'
7
- require 'device_detector'
8
-
9
- Rake::TestTask.new do |t|
10
- t.pattern = 'spec/**/*_spec.rb'
11
- t.libs.push 'spec'
12
- end
13
-
14
- task default: :test
15
-
16
- task :detectable_names do
17
- require 'Date'
18
-
19
- bot_names = DeviceDetector::Bot.new.send(:regexes).map { |r| r[:name] }.uniq.sort_by(&:downcase)
20
- bot_names.delete('$1')
21
- client_names = DeviceDetector::Client.new.send(:regexes).map { |r| r[:name] }.uniq.sort_by(&:downcase)
22
- client_names.delete('$1')
23
- device = DeviceDetector::Device.new
24
- device_paths = device.send(:filepaths)
25
- device_regexes = device.send(:load_regexes, device_paths)
26
- device_names = device_regexes.flat_map { |dn| dn[1].keys }.uniq.sort_by(&:downcase)
27
-
28
- today = Date.today.strftime
29
-
30
- puts '## Detectable clients, bots and devices'
31
- puts
32
- puts "Updated on #{today}"
33
- puts
34
- puts '### Bots'
35
- puts
36
- puts bot_names.join(', ')
37
- puts
38
- puts '### Clients'
39
- puts
40
- puts client_names.join(', ')
41
- puts
42
- puts '### Devices'
43
- puts
44
- puts device_names.join(', ')
45
- puts
46
- end
47
-
48
- PIWIK_REPO_URL = 'https://github.com/matomo-org/device-detector'
49
- PIWIK_CHECKOUT_LOCATION = '/tmp/matomo_device_detector'
50
-
51
- def get_latest_piwik_checkout
52
- if File.exist?(PIWIK_CHECKOUT_LOCATION)
53
- system "cd #{PIWIK_CHECKOUT_LOCATION}; git reset --hard HEAD; git pull origin master"
54
- else
55
- system "git clone --depth 1 #{PIWIK_REPO_URL} #{PIWIK_CHECKOUT_LOCATION}"
56
- end
57
- end
58
-
59
- desc 'update regex database from piwik project'
60
- task :update_regexes do
61
- top = File.expand_path(__dir__)
62
- get_latest_piwik_checkout
63
- system "cp -R #{PIWIK_CHECKOUT_LOCATION}/regexes/* #{top}/regexes"
64
- end
65
-
66
- desc 'fix regexes that are broken because of a bug in ruby'
67
- task :fix_regexes do
68
- # fix broken regexes: https://github.com/podigee/device_detector/issues/65
69
-
70
- # modify regex to bypass ruby bug
71
- system "sed -i '' 's/\|ImSmart \|ERGO \|X-Style Tab //g' regexes/device/mobiles.yml"
72
-
73
- # remove fixtures that test that regex
74
- system "sed -i '' '/X-Style Tab A101/,/^-/{d;};' spec/fixtures/**/*.yml"
75
- system "sed -i '' '/ERGO A500 Best Build/,/^-/{d;};' spec/fixtures/**/*.yml"
76
- system "sed -i '' '/ImSmart A501 Build.KOT49H/,/^-/{d;};' spec/fixtures/**/*.yml"
77
- end
78
-
79
- desc 'update fixtures from piwik project'
80
- task :update_fixtures do
81
- top = File.expand_path(__dir__)
82
- get_latest_piwik_checkout
83
-
84
- fixture_mappings = [
85
- { target_path: "#{top}/spec/fixtures/detector", source_path: 'Tests/fixtures/*.yml' },
86
- { target_path: "#{top}/spec/fixtures/client", source_path: 'Tests/Parser/Client/fixtures/*.yml' },
87
- { target_path: "#{top}/spec/fixtures/parser", source_path: 'Tests/Parser/fixtures/*.yml' },
88
- { target_path: "#{top}/spec/fixtures/device", source_path: 'Tests/Parser/Devices/fixtures/*.yml' }
89
- ]
90
-
91
- fixture_mappings.each do |mapping|
92
- source_path = mapping.fetch(:source_path)
93
- target_path = mapping.fetch(:target_path)
94
- system "cp -R #{PIWIK_CHECKOUT_LOCATION}/#{source_path} #{target_path}"
95
- end
96
- end
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'device_detector/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'device_detector'
8
- spec.version = DeviceDetector::VERSION
9
- spec.authors = ['Mati Sójka', 'Ben Zimmer']
10
- spec.email = ['yagooar@gmail.com']
11
- spec.summary = %q{Precise and fast user agent parser and device detector}
12
- spec.description = %q{Precise and fast user agent parser and device detector, backed by the largest and most up-to-date agent and device database}
13
- spec.homepage = 'http://podigee.github.io/device_detector'
14
- spec.license = 'LGPL-3.0'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = []
18
- spec.test_files = spec.files.grep(%r{^(spec)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.required_ruby_version = '>= 1.9.3'
22
-
23
- spec.add_development_dependency 'minitest'
24
- spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'pry', '>= 0.10'
26
- end
@@ -1,30 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe DeviceDetector::Bot do
4
-
5
- fixture_dir = File.expand_path('../../fixtures/parser', __FILE__)
6
- fixture_files = Dir["#{fixture_dir}/bots.yml"]
7
- fixture_files.each do |fixture_file|
8
-
9
- describe File.basename(fixture_file) do
10
-
11
- fixtures = YAML.load_file(fixture_file)
12
-
13
- fixtures.each do |f|
14
- user_agent = f["user_agent"]
15
- bot = DeviceDetector::Bot.new(user_agent)
16
-
17
- describe user_agent do
18
- it "should be a bot" do
19
- assert bot.bot?, "isn't a bot"
20
- end
21
-
22
- it "should have the expected name" do
23
- assert_equal f["bot"]["name"], bot.name, "failed bot name detection"
24
- end
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
@@ -1,31 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe DeviceDetector::Client do
4
-
5
- fixture_dir = File.expand_path('../../fixtures/client', __FILE__)
6
- fixture_files = Dir["#{fixture_dir}/*.yml"]
7
- fixture_files.each do |fixture_file|
8
-
9
- describe File.basename(fixture_file) do
10
-
11
- fixtures = YAML.load_file(fixture_file)
12
- fixtures.each do |f|
13
-
14
- user_agent = f["user_agent"]
15
- client = DeviceDetector::Client.new(user_agent)
16
-
17
- describe user_agent do
18
-
19
- it "should be known" do
20
- assert client.known?, "isn't known as a client"
21
- end
22
-
23
- it "should have the expected name" do
24
- assert_equal f["client"]["name"], client.name, "failed client name detection"
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,135 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe DeviceDetector do
4
-
5
- subject { DeviceDetector.new(user_agent) }
6
-
7
- alias :client :subject
8
-
9
- describe 'mobile iPhone 5S' do
10
-
11
- let(:user_agent) { 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B440 [FBDV/iPhone6,1]' }
12
-
13
- describe '#device_name' do
14
-
15
- it 'returns device name' do
16
- value(client.device_name).must_equal 'iPhone 5S'
17
- end
18
-
19
- end
20
-
21
- describe '#device_type' do
22
-
23
- it 'returns the device type' do
24
- value(client.device_type).must_equal 'smartphone'
25
- end
26
-
27
- end
28
-
29
- end
30
-
31
- describe 'Ubuntu 10' do
32
-
33
- let(:user_agent) { 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Ubuntu/10.10 Chromium/10.0.648.133 Chrome/10.0.648.133 Safari/534.16' }
34
-
35
- describe '#os_name' do
36
-
37
- it 'returns the OS name' do
38
- value(client.os_name).must_equal 'Ubuntu'
39
- end
40
-
41
- end
42
-
43
- end
44
-
45
- describe 'Mac OS X' do
46
-
47
- let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36' }
48
-
49
- describe '#full_version' do
50
-
51
- it 'returns the correct OS version' do
52
- value(client.os_full_version).must_equal '10.10.1'
53
- end
54
-
55
- end
56
-
57
- end
58
-
59
- describe 'Chrome on Windows' do
60
-
61
- describe '32bit' do
62
-
63
- let(:user_agent) { 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36' }
64
-
65
- it 'returns the correct client name' do
66
- value(client.name).must_equal 'Chrome'
67
- end
68
-
69
- it 'recognizes the device name' do
70
- value(client.device_name).must_be_nil
71
- end
72
-
73
- it 'recognizes the device type' do
74
- value(client.device_type).must_equal "desktop"
75
- end
76
-
77
- end
78
-
79
- describe '64bit' do
80
-
81
- let(:user_agent) { 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' }
82
-
83
- it 'returns the correct client name' do
84
- value(client.name).must_equal 'Chrome'
85
- end
86
-
87
- it 'recognizes the device name' do
88
- value(client.device_name).must_be_nil
89
- end
90
-
91
- it 'recognizes the device type' do
92
- value(client.device_type).must_equal "desktop"
93
- end
94
-
95
- end
96
-
97
- end
98
-
99
- describe 'recognize and ignore sprd- prefix' do
100
-
101
- let(:user_agent) { 'sprd-Galaxy-S5/1.0 Linux/2.6.35.7 Android/4.4.4 Release/11.29.2014 Browser/AppleWebKit533.1 (KHTML, like Gecko) Mozilla/5.0 Mobile' }
102
-
103
- it 'returns the correct client name' do
104
- value(client.name).must_equal "Android Browser"
105
- end
106
-
107
- it 'recognizes the device name' do
108
- value(client.device_name).must_equal "GALAXY S5"
109
- end
110
-
111
- it 'recognizes the device type' do
112
- value(client.device_type).must_equal "smartphone"
113
- end
114
-
115
- end
116
-
117
- describe 'remove TD suffix from model' do
118
-
119
- let(:user_agent) { 'Lenovo-A398t+_TD/S100 Linux/3.4.5 Android/4.1.2 Release/09.10.2013 Browser/AppleWebKit534.30 Mobile Safari/534.30' }
120
-
121
- it 'returns the correct client name' do
122
- value(client.name).must_equal "Android Browser"
123
- end
124
-
125
- it 'recognizes the device name' do
126
- value(client.device_name).must_equal "A398t+"
127
- end
128
-
129
- it 'recognizes the device type' do
130
- value(client.device_type).must_equal "smartphone"
131
- end
132
-
133
- end
134
-
135
- end
@@ -1,100 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe DeviceDetector do
4
-
5
- fixture_dir = File.expand_path('../../fixtures/detector', __FILE__)
6
- fixture_files = Dir["#{fixture_dir}/*.yml"]
7
- fixture_files.each do |fixture_file|
8
-
9
- describe File.basename(fixture_file) do
10
-
11
- fixtures = nil
12
- begin
13
- fixtures = YAML.load(File.read(fixture_file))
14
- rescue Psych::SyntaxError => e
15
- fail "Failed to parse #{fixture_file}, reason: #{e}"
16
- end
17
-
18
- def str_or_nil(string)
19
- return nil if string == ''
20
- string
21
- end
22
-
23
- fixtures.each do |f|
24
-
25
- user_agent = f["user_agent"]
26
- detector = DeviceDetector.new(user_agent)
27
- os = detector.send(:os)
28
-
29
- describe user_agent do
30
- it "should be detected" do
31
- if detector.bot?
32
- assert_equal str_or_nil(f["bot"]["name"]), detector.bot_name, "failed bot name detection"
33
- else
34
- if f["client"]
35
- assert_equal str_or_nil(f["client"]["name"]), detector.name, "failed client name detection"
36
- end
37
-
38
- os_family = str_or_nil(f["os_family"])
39
- if os_family != "Unknown"
40
- if os_family.nil?
41
- assert_nil os.family, "failed os family detection"
42
- else
43
- assert_equal os_family, os.family, "failed os family detection"
44
- end
45
-
46
- name = str_or_nil(f["os"]["name"])
47
- if name.nil?
48
- assert_nil os.name, "failed os name detection"
49
- else
50
- assert_equal name, os.name, "failed os name detection"
51
- end
52
-
53
- short_name = str_or_nil(f["os"]["short_name"])
54
- if short_name.nil?
55
- assert_nil os.short_name, "failed os short name detection"
56
- else
57
- assert_equal short_name, os.short_name, "failed os short name detection"
58
- end
59
-
60
- os_version = str_or_nil(f["os"]["version"])
61
- if os_version.nil?
62
- assert_nil os.full_version, "failed os version detection"
63
- else
64
- assert_equal os_version, os.full_version, "failed os version detection"
65
- end
66
- end
67
- if f["device"]
68
- expected_type = str_or_nil(f["device"]["type"])
69
- actual_type = detector.device_type
70
-
71
- if expected_type != actual_type
72
- # puts "\n", f.inspect, expected_type, actual_type, detector.device_name, regex_meta.inspect
73
- # debugger
74
- # detector.device_type
75
- end
76
- if expected_type.nil?
77
- assert_nil actual_type, "failed device type detection"
78
- else
79
- assert_equal expected_type, actual_type, "failed device type detection"
80
- end
81
-
82
- model = str_or_nil(f["device"]["model"])
83
- model = model.to_s unless model.nil?
84
-
85
- if model.nil?
86
- assert_nil detector.device_name, "failed device name detection"
87
- else
88
- assert_equal model, detector.device_name, "failed device name detection"
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
95
-
96
- end
97
-
98
- end
99
-
100
- end