uaparser 1.0.0.pre.beta
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 +15 -0
- data/.codeclimate.yml +3 -0
- data/.gitignore +27 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +7 -0
- data/README.md +48 -0
- data/Rakefile +11 -0
- data/config/config.yml +105 -0
- data/example/Gemfile +1 -0
- data/example/example.rb +7 -0
- data/lib/uaparser/config.rb +29 -0
- data/lib/uaparser/parser.rb +37 -0
- data/lib/uaparser/version.rb +6 -0
- data/lib/uaparser.rb +3 -0
- data/spec/parser_spec.rb +29 -0
- data/spec/spec_helper.rb +9 -0
- data/uaparser.gemspec +21 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTY0MzVjNGZlNzdhNjVkOTEyZGUyZDVmMTk0YWU3ODdhMTk4Y2FkNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWZlNjJlOTgxMTg4OGRlYjZlYTkwNDM3Yjk1YjE4ZWU4NTMyNGRlNA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjMxMzZiZjUyZjQwY2Q0YjhiZDEwYWE4MGYwNzViZjk0MjdlNGI3ZGIwNTYz
|
10
|
+
YTEzODVlZmEwZGYyYzUyODEyOTc0ZjQyOGVjOThjYzM3M2FiYjY5MGJmNGNh
|
11
|
+
OTc3NGQyNmUyZDZiNGQ1N2ViODZjNjMwODQwYzhmNmI4YmY4ZjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzdhYjk1MjJmNGZjZTEwNThkZjVhY2M1ZDk2M2ZhYzE3ODk5NmZiZTkyMTM5
|
14
|
+
OGYzMGQxN2RmNzBkZjJiODIzYWE4Yzk3ZWNjMTk3ODVmOGZlNGVhNjdhYjAw
|
15
|
+
YzIyYTFmYmIzMjQ0NjE2ZTkxZjAxMWUzOWIyODk1MDNlNTI5ZDI=
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
pecific to RubyMotion:
|
2
|
+
.dat*
|
3
|
+
.repl_history
|
4
|
+
build/
|
5
|
+
|
6
|
+
## Documentation cache and generated files:
|
7
|
+
/.yardoc/
|
8
|
+
/_yardoc/
|
9
|
+
/doc/
|
10
|
+
/rdoc/
|
11
|
+
|
12
|
+
## Environment normalisation:
|
13
|
+
/.bundle/
|
14
|
+
/vendor/bundle
|
15
|
+
/lib/bundler/man/
|
16
|
+
|
17
|
+
# for a library or gem, you might want to ignore these files since the code is
|
18
|
+
# intended to run in multiple environments; otherwise, check them in:
|
19
|
+
Gemfile.lock
|
20
|
+
.ruby-version
|
21
|
+
.ruby-gemset
|
22
|
+
|
23
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
24
|
+
.rvmrc
|
25
|
+
|
26
|
+
# Gems:
|
27
|
+
*.gem
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
uaparser
|
2
|
+
========
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/uaparser)
|
5
|
+
[](https://travis-ci.org/rfguri/uaparser)
|
6
|
+
[](https://codeclimate.com/github/rfguri/uaparser)
|
7
|
+
[](https://codeclimate.com/github/rfguri/uaparser/coverage)
|
8
|
+
[](https://inch-ci.org/github/rfguri/uaparser)
|
9
|
+
|
10
|
+
uaparser is an apple user agent identifier build with Ruby to identify Apple device, model and iOS version based on User Agent strings.
|
11
|
+
This gem comes with a configuration file [`config.yaml`](https://github.com/rfguri/uaparser/blob/master/config/config.yml) updated
|
12
|
+
every time Apple issues a new User Agent string based on product releases.
|
13
|
+
|
14
|
+
Usage
|
15
|
+
----
|
16
|
+
|
17
|
+
First of all install the gem with:
|
18
|
+
|
19
|
+
```Shell
|
20
|
+
gem install uaparser
|
21
|
+
```
|
22
|
+
or if you have a `Gemfile` run:
|
23
|
+
```Shell
|
24
|
+
bundle install
|
25
|
+
```
|
26
|
+
After installation you can require the gem with:
|
27
|
+
|
28
|
+
```Ruby
|
29
|
+
require 'uaparser'
|
30
|
+
```
|
31
|
+
|
32
|
+
Example
|
33
|
+
-------
|
34
|
+
|
35
|
+
```Ruby
|
36
|
+
require 'uaparser'
|
37
|
+
|
38
|
+
parser = UAParser::Parser.new
|
39
|
+
|
40
|
+
puts parser.identify("Apple-iPhone7C2/1202.466") # This will output: "iPhone 6 CDMA iOS 8.1.3"
|
41
|
+
```
|
42
|
+
|
43
|
+
License
|
44
|
+
-------
|
45
|
+
|
46
|
+
uaparser is Copyright © 2015 Roger Fernandez Guri. It is free software, and may be
|
47
|
+
redistributed under the terms specified in the [LICENCE](https://github.com/rfguri/uaparser/blob/master/LICENSE) file.
|
48
|
+
|
data/Rakefile
ADDED
data/config/config.yml
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
iphone: &iphone
|
2
|
+
prefix: &prefix
|
3
|
+
"Apple-iPhone": "iPhone 3G"
|
4
|
+
"Apple-iPhone1C2": "iPhone 3G"
|
5
|
+
"Apple-iPhone2C1": "iPhone 3GS"
|
6
|
+
"Apple-iPhone3C1": "iPhone 4 GSM"
|
7
|
+
"Apple-iPhone3C2": "iPhone 4 GSM"
|
8
|
+
"Apple-iPhone3C3": "iPhone 4 CDMA"
|
9
|
+
"Apple-iPhone4C1": "iPhone 4S"
|
10
|
+
"Apple-iPhone5C1": "iPhone 5 GSM"
|
11
|
+
"Apple-iPhone5C2": "iPhone 5 CDMA"
|
12
|
+
"Apple-iPhone5C3": "iPhone 5C GSM"
|
13
|
+
"Apple-iPhone5C4": "iPhone 5C CDMA"
|
14
|
+
"Apple-iPhone6C1": "iPhone 5S GSM"
|
15
|
+
"Apple-iPhone6C2": "iPhone 5S CDMA"
|
16
|
+
"Apple-iPhone7C1": "iPhone 6+ CDMA"
|
17
|
+
"Apple-iPhone7C2": "iPhone 6 CDMA"
|
18
|
+
id: &id
|
19
|
+
"501.347": "2.0"
|
20
|
+
"502.108": "2.0.1"
|
21
|
+
"503.001": "2.0.2"
|
22
|
+
"506.136": "2.1"
|
23
|
+
"505.138": "2.1.1"
|
24
|
+
"507.077": "2.2"
|
25
|
+
"508.11": "2.2.1"
|
26
|
+
"701.341": "3.0"
|
27
|
+
"701.400": "3.0.1"
|
28
|
+
"703.144": "3.1"
|
29
|
+
"704.011": "3.1.2"
|
30
|
+
"705.018": "3.1.3"
|
31
|
+
"801.293": "4.0"
|
32
|
+
"801.306": "4.0.1"
|
33
|
+
"801.400": "4.0.2"
|
34
|
+
"802.117": "4.1"
|
35
|
+
"803.148": "4.2.1"
|
36
|
+
"803.14800001": "4.2.1"
|
37
|
+
"805.128": "4.2.5"
|
38
|
+
"805.200": "4.2.6"
|
39
|
+
"805.303": "4.2.7"
|
40
|
+
"805.401": "4.2.8"
|
41
|
+
"805.501": "4.2.9"
|
42
|
+
"805.600": "4.2.10"
|
43
|
+
"807.4": "4.3.1"
|
44
|
+
"808.7": "4.3.2"
|
45
|
+
"810.2": "4.3.3"
|
46
|
+
"811.2": "4.3.4"
|
47
|
+
"812.1": "4.3.5"
|
48
|
+
"901.334": "5.0"
|
49
|
+
"901.405": "5.0.1"
|
50
|
+
"901.406": "5.0.1"
|
51
|
+
"902.179": "5.1"
|
52
|
+
"902.206": "5.1.1"
|
53
|
+
"1001.403": "6.0"
|
54
|
+
"1001.405": "6.0"
|
55
|
+
"1001.406": "6.0"
|
56
|
+
"1001.523": "6.0.1"
|
57
|
+
"1001.525": "6.0.1"
|
58
|
+
"1202.440": "8.1.2"
|
59
|
+
"1202.466": "8.1.3"
|
60
|
+
ipod:
|
61
|
+
prefix:
|
62
|
+
"Apple-iPod": "iPod touch 1st generation"
|
63
|
+
"Apple-iPod2C1": "iPod touch 2nd generation"
|
64
|
+
"Apple-iPod3C1": "iPod touch 3rd generation"
|
65
|
+
"Apple-iPod4C1": "iPod touch 4th generation"
|
66
|
+
"Apple-iPod5C1": "iPod touch 5th generation"
|
67
|
+
id:
|
68
|
+
<<: *id
|
69
|
+
"506.137": "2.1"
|
70
|
+
"507.07700001": "2.2"
|
71
|
+
"508.01100001": "2.2.1"
|
72
|
+
"703.145": "3.1"
|
73
|
+
"703.146": "3.1"
|
74
|
+
ipad:
|
75
|
+
prefix:
|
76
|
+
"Apple-iPad": "iPad"
|
77
|
+
"Apple-iPad1C1": "iPad"
|
78
|
+
"Apple-iPad2C1": "iPad 2 WiFi"
|
79
|
+
"Apple-iPad2C2": "iPad 2 WiFi 3G GSM"
|
80
|
+
"Apple-iPad2C3": "iPad 2 WiFi 3G CDMA"
|
81
|
+
"Apple-iPad2C4": "iPad Mini WiFi"
|
82
|
+
"Apple-iPad2C5": "iPad Mini WiFi LTE"
|
83
|
+
"Apple-iPad3C1": "iPad 3rd generation WiFi"
|
84
|
+
"Apple-iPad3C2": "iPad 3rd generation WiFi 4G Verizon / International"
|
85
|
+
"Apple-iPad3C3": "iPad 3rd generation WiFi 4G AT&T / International"
|
86
|
+
"Apple-iPad3C4": "iPad 4th generation WiFi"
|
87
|
+
"Apple-iPad3C5": "iPad 4th generation 4G GSM NA LTE"
|
88
|
+
"Apple-iPad3C6": "iPad 4th generation 4G CDMA LTE"
|
89
|
+
"Apple-iPad4C1": "iPad Air WiFi"
|
90
|
+
"Apple-iPad4C2": "iPad Air WiFi LTE"
|
91
|
+
"Apple-iPad4C4": "iPad Mini Retina WiFi"
|
92
|
+
"Apple-iPad4C5": "iPad Mini Retina WiFi LTE"
|
93
|
+
id:
|
94
|
+
<<: *id
|
95
|
+
"702.367": "3.2.2"
|
96
|
+
"702.405": "3.2.1"
|
97
|
+
"702.500": "3.2.2"
|
98
|
+
"803.148": "4.2.1"
|
99
|
+
"806.190": "4.3"
|
100
|
+
"806.191": "4.3"
|
101
|
+
"806.191": "4.3"
|
102
|
+
"806.191": "4.3"
|
103
|
+
"808.8": "4.3.2"
|
104
|
+
"810.3": "4.3.3"
|
105
|
+
|
data/example/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem 'uaparser', git:'git@github.com:rfguri/uaparser.git'
|
data/example/example.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This module holds the classes to load
|
2
|
+
# configuration data and also identify
|
3
|
+
# user agent strings.
|
4
|
+
module UAParser
|
5
|
+
|
6
|
+
# This class holds the configuration funtions.
|
7
|
+
# The config method allows us to return a hash
|
8
|
+
# with all possible combinations of user agent
|
9
|
+
# strings with devices models and iOS versions.
|
10
|
+
class Config
|
11
|
+
|
12
|
+
# Constructor
|
13
|
+
def initialize
|
14
|
+
@config = YAML::load_file(File.expand_path('../../../config/config.yml', __FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return a hash with all configuration
|
18
|
+
# values.
|
19
|
+
#
|
20
|
+
# @return [Hash] instance of configuration
|
21
|
+
# hash.
|
22
|
+
def config
|
23
|
+
@config
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This module holds the classes to load
|
2
|
+
# configuration data and also identify
|
3
|
+
# user agent strings.
|
4
|
+
module UAParser
|
5
|
+
|
6
|
+
# This class holds the parsing funtions. The
|
7
|
+
# identify method allows us to identify model
|
8
|
+
# and version of the device and its operative
|
9
|
+
# system.
|
10
|
+
class Parser
|
11
|
+
|
12
|
+
# Constructor
|
13
|
+
def initialize
|
14
|
+
@config = UAParser::Config.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# Runs a hash search, identifies the user
|
18
|
+
# agent strings and returns the device model
|
19
|
+
# and its iOS version.
|
20
|
+
#
|
21
|
+
# @param str [String] user agent string
|
22
|
+
# used to identify model and ios version.
|
23
|
+
# @return [String] the user agent string
|
24
|
+
# converted to model and iOS version.
|
25
|
+
def identify(str)
|
26
|
+
hash = @config.config
|
27
|
+
prefix, id = str.split("/")
|
28
|
+
device = prefix[/iPhone|iPod|iPad/,0].downcase
|
29
|
+
model = hash[device]["prefix"][prefix]
|
30
|
+
version = hash[device]["id"][id]
|
31
|
+
info = "#{model} iOS #{version}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
data/lib/uaparser.rb
ADDED
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UAParser::Config do
|
4
|
+
|
5
|
+
it "loads configuration" do
|
6
|
+
config = UAParser::Config.new.config
|
7
|
+
expect(config).not_to eql(nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe UAParser::Parser do
|
14
|
+
|
15
|
+
it "idenfies user agent strings" do
|
16
|
+
parser = UAParser::Parser.new
|
17
|
+
config = UAParser::Config.new.config
|
18
|
+
config.each do |_, hash|
|
19
|
+
hash["prefix"].each do |prefix, model|
|
20
|
+
hash["id"].each do |id, version|
|
21
|
+
output = "#{model} iOS #{version}"
|
22
|
+
info = parser.identify("#{prefix}/#{id}")
|
23
|
+
expect(output).to eql(info)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/uaparser.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'uaparser/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.authors = ["Roger Fernandez Guri"]
|
9
|
+
spec.email = ["rfguri@gmail.com"]
|
10
|
+
spec.summary = %q{Apple user agent parser gem wittern in Ruby.}
|
11
|
+
spec.description = %q{uaparser is an apple user agent identifier build with Ruby to identify Apple device, model and iOS version based on User Agent strings.}
|
12
|
+
spec.homepage = "https://rubygems.org/gems/uaparser"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.files = `git ls-files`.split("\n")
|
15
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
spec.name = "uaparser"
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.version = UAParser::VERSION
|
20
|
+
end
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uaparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roger Fernandez Guri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: uaparser is an apple user agent identifier build with Ruby to identify
|
14
|
+
Apple device, model and iOS version based on User Agent strings.
|
15
|
+
email:
|
16
|
+
- rfguri@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .codeclimate.yml
|
22
|
+
- .gitignore
|
23
|
+
- .rspec
|
24
|
+
- .travis.yml
|
25
|
+
- Gemfile
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- config/config.yml
|
29
|
+
- example/Gemfile
|
30
|
+
- example/example.rb
|
31
|
+
- lib/uaparser.rb
|
32
|
+
- lib/uaparser/config.rb
|
33
|
+
- lib/uaparser/parser.rb
|
34
|
+
- lib/uaparser/version.rb
|
35
|
+
- spec/parser_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- uaparser.gemspec
|
38
|
+
homepage: https://rubygems.org/gems/uaparser
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>'
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.3.1
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.4.3
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Apple user agent parser gem wittern in Ruby.
|
62
|
+
test_files: []
|
63
|
+
has_rdoc:
|