android-devices 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +52 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/android-devices.gemspec +21 -0
- data/config.yml +1 -0
- data/lib/android/devices.rb +52 -0
- data/lib/android/devices/model.rb +19 -0
- data/lib/android/devices/version.rb +5 -0
- data/spec/android_devices_spec.rb +36 -0
- data/spec/test_devices.csv +4 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10867c7e75f189159d21ff97a362a552f64e730e
|
4
|
+
data.tar.gz: 002e326e0d72e3741096c9eed3d0907f3610ff31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0eb6fbb954b14ae1c9720f066da34b7802efe4f352401ff16833798742fac8940b19e78917817cd6bd57bbee103ca0cb9e8b90bad67cf1d56bc49b845d76f60
|
7
|
+
data.tar.gz: db1df57f64a557b99482c24c0c3111fb821bc052c0a3894e350d40301c81b74a4c4ad455e55d73d69889aa76beb2d7b820318fbb560208795120306f40c6f90c
|
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/spec/examples.txt
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
## Specific to RubyMotion:
|
18
|
+
.dat*
|
19
|
+
.repl_history
|
20
|
+
build/
|
21
|
+
*.bridgesupport
|
22
|
+
build-iPhoneOS/
|
23
|
+
build-iPhoneSimulator/
|
24
|
+
|
25
|
+
## Specific to RubyMotion (use of CocoaPods):
|
26
|
+
#
|
27
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
28
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
29
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
30
|
+
#
|
31
|
+
# vendor/Pods/
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalization:
|
40
|
+
/.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
Gemfile.lock
|
47
|
+
.ruby-version
|
48
|
+
.ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
52
|
+
.idea
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 BBC
|
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,55 @@
|
|
1
|
+
# Android::Devices
|
2
|
+
|
3
|
+
Gem used to convert android model numbers (e.g. GT-I9507) into something more human readable (e.g. Samsung Galaxy S4)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following into your application's Gemfile:
|
8
|
+
|
9
|
+
`gem android-devices`
|
10
|
+
|
11
|
+
Then execute:
|
12
|
+
|
13
|
+
`bundle install`
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
This gem uses the devices list provided by the Google Play store as it's information store. When you first run the gem it
|
19
|
+
will attempt to automatically download the list, if you wish to re-download the list you can use the following command:
|
20
|
+
|
21
|
+
` Android::Devices.update_devices`
|
22
|
+
|
23
|
+
To then search for a device, you can do something similar to the following:
|
24
|
+
|
25
|
+
```
|
26
|
+
device = Android::Devices.search_by_model('GT-I9507')
|
27
|
+
=> #<Android::Devices::Model:0x007fadd9582d28 @manufacturer="Samsung", @brand="Galaxy S4", @device="jftdd", @model="GT-I9507">
|
28
|
+
|
29
|
+
device.name
|
30
|
+
=> "Samsung Galaxy S4"
|
31
|
+
|
32
|
+
device.brand
|
33
|
+
=> "Galaxy S4"
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
If a brand name isn't available it will make use the manufacturer and model as the name:
|
38
|
+
|
39
|
+
```
|
40
|
+
device = Android::Devices.search_by_model('GT-S5820')
|
41
|
+
=> #<Android::Devices::Model:0x007f93889a4700 @manufacturer="Samsung", @brand=nil, @device="GT-S5820", @model="GT-S5820">
|
42
|
+
|
43
|
+
device.name
|
44
|
+
=> "Samsung GT-S5820"
|
45
|
+
```
|
46
|
+
|
47
|
+
Finally, if you want a list of devices by a certain manufacturer you can:
|
48
|
+
|
49
|
+
```
|
50
|
+
devices = Android::Devices.search_by_manufacturer('Samsung')
|
51
|
+
=> [#<Android::Devices::Model:0x007f9388864278 @manufacturer="Samsung", @brand="Galaxy Core Prime", @device="coreprimeltetfnvzw", @model="SM-S820L">,
|
52
|
+
#<Android::Devices::Model:0x007f9388864250 @manufacturer="Samsung", @brand="Galaxy Core Prime", @device="coreprimeltevzw", @model="SM-G360V">,
|
53
|
+
#<Android::Devices::Model:0x007f9388864228 @manufacturer="Samsung", @brand="Galaxy Core Prime", @device="coreprimeve3g", @model="SM-G361H">,
|
54
|
+
etc.
|
55
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'android/devices'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'android-devices'
|
9
|
+
spec.version = Android::Devices::VERSION
|
10
|
+
spec.authors = ['Jon Wilson']
|
11
|
+
spec.email = ['jon.wilson01@bbc.co.uk']
|
12
|
+
spec.summary = %q{Human readable Android device names}
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_development_dependency 'bundler'
|
18
|
+
spec.add_development_dependency 'rake'
|
19
|
+
spec.add_development_dependency 'pry'
|
20
|
+
spec.add_development_dependency 'rspec'
|
21
|
+
end
|
data/config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
url: http://storage.googleapis.com/play_public/supported_devices.csv
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'android/devices/version'
|
2
|
+
require 'android/devices/model'
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Android
|
6
|
+
module Devices
|
7
|
+
|
8
|
+
def self.update_devices(url = '')
|
9
|
+
csv_url = url.nil? || url.empty? ? 'http://storage.googleapis.com/play_public/supported_devices.csv' : url
|
10
|
+
begin
|
11
|
+
devices = CSV.parse(open(csv_url).read)
|
12
|
+
File.open('devices.csv','w') {|f| f.write(devices.inject([]) { |csv,row| csv << CSV.generate_line(row) }.join('').encode('UTF-8'))}
|
13
|
+
return true
|
14
|
+
rescue Exception
|
15
|
+
raise 'Unable to update devices'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.list_exists
|
20
|
+
return File.exists?('devices.csv')
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.old_list?
|
24
|
+
return (File.mtime('devices.csv') < Time.parse((DateTime.now - 30).to_s))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.search_by_model(model)
|
28
|
+
models.select { |device| device.model == model}.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.search_by_manufacturer(manufacturer)
|
32
|
+
models.select { |device| device.manufacturer == manufacturer}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.models
|
36
|
+
return @models unless @models.nil?
|
37
|
+
@models = []
|
38
|
+
devices.shift
|
39
|
+
devices.each do |device|
|
40
|
+
@models << Model.new(device[0], device[1], device[2], device[3])
|
41
|
+
end
|
42
|
+
@models
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.devices
|
46
|
+
return @devices unless @devices.nil?
|
47
|
+
update_devices unless list_exists
|
48
|
+
@devices = CSV.read('devices.csv')
|
49
|
+
@devices
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Android
|
2
|
+
module Devices
|
3
|
+
class Model
|
4
|
+
attr_accessor :manufacturer, :brand, :device, :model
|
5
|
+
|
6
|
+
def initialize(manufacturer, brand, device, model)
|
7
|
+
@manufacturer = manufacturer
|
8
|
+
@brand = brand
|
9
|
+
@device = device
|
10
|
+
@model = model
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
return "#{@manufacturer} #{@brand}" if @brand
|
15
|
+
"#{@manufacturer} #{@model}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
describe Android::Devices do
|
2
|
+
describe 'check' do
|
3
|
+
|
4
|
+
it 'should check if the devices list exists' do
|
5
|
+
File.delete('devices.csv') if File.exists? 'devices.csv'
|
6
|
+
expect(Android::Devices.list_exists).to be(false)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should warn if the devices list is over 30 days old' do
|
10
|
+
FileUtils.touch 'devices.csv', :mtime => Time.parse((DateTime.now - 31).to_s)
|
11
|
+
expect(Android::Devices.old_list?).to be(true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'update' do
|
16
|
+
it 'should be able to update itself' do
|
17
|
+
expect(Android::Devices.update_devices('spec/test_devices.csv')).to be(true)
|
18
|
+
expect(Android::Devices.list_exists).to be(true)
|
19
|
+
expect(CSV.read('devices.csv').count).to be(4)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'search' do
|
24
|
+
before(:all) do
|
25
|
+
Android::Devices.update_devices('spec/test_devices.csv')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should search by model' do
|
29
|
+
expect(Android::Devices.search_by_model('GT-I9507').manufacturer).to eq('Samsung')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should search by manufacturer' do
|
33
|
+
expect(Android::Devices.search_by_manufacturer('Samsung').count).to be(3)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: android-devices
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-18 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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
|
+
- jon.wilson01@bbc.co.uk
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- android-devices.gemspec
|
83
|
+
- config.yml
|
84
|
+
- lib/android/devices.rb
|
85
|
+
- lib/android/devices/model.rb
|
86
|
+
- lib/android/devices/version.rb
|
87
|
+
- spec/android_devices_spec.rb
|
88
|
+
- spec/test_devices.csv
|
89
|
+
homepage:
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Human readable Android device names
|
112
|
+
test_files: []
|