doxie-scanner 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d19094d1abad744e8bf10c3e9c1fddf14459be1158db960c460a61ed9e76123
4
- data.tar.gz: 32e13587cd42cdddfbc070384d6c31d20948ea93cb138450606db8529326ca86
3
+ metadata.gz: 40d9bc6a4652f5e0583fa1afa774bd4da8923d73478b7da3eac9412767d2a5f8
4
+ data.tar.gz: 6d6e799b5bb6420d97dd6efd284ca7cdef53bd31a565c54c285730da0478ab90
5
5
  SHA512:
6
- metadata.gz: f6c217d412b6aec0e69d04c2d781fd8152846b4ea4126f838e6113b83d9564db39de1bf7c6b5dff48fcf25b173d499b84414c59da1277f194c62b9a4c8b0dabc
7
- data.tar.gz: 3061edd67b68532ad3b3118394b91b2ecbfd31298e35f671d097fc5f75f44e89b93310f8314c5739b50c72d1b8f198a2e526377bdbfb1fa7bdd7e7719a85629e
6
+ metadata.gz: cd4bbddd1fb17295e71de69a64d1e4ce9de5961233eb6df7ba13d49ac651be6b788d42aa0f3b4101b107b376c5218e23fd788ceb63c74977aa6f7ee1b390a3bd
7
+ data.tar.gz: 6abc7acd5698f9b4c655898e5b226104bb5e16e589fed90e0f4f9033d5f2fccb986889c1f12ef8ca2ae6db4555e45d7e982c7fcf7aa734116756a27d65494ea8
data/README.md CHANGED
@@ -26,6 +26,15 @@ Doxie::Scanner.ips
26
26
  ]
27
27
  ```
28
28
 
29
+ For usage with the [Doxie client library](https://github.com/cbetta/doxie) you can use the `.devices` method to automatically detect the model number and IP.
30
+
31
+ ```rb
32
+ require 'doxie'
33
+ require 'doxie/scanner'
34
+
35
+ client = Doxie::Client.new(Doxie::Scanner.devices.first)
36
+ ```
37
+
29
38
  ## Contributing
30
39
 
31
40
  1. **Fork** the repo on GitHub
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'doxie-scanner'
3
- s.version = '1.1.0'
4
- s.summary = "A simple scanner for your Doxie Go Wifi"
5
- s.description = "A simple scanner for your Doxie Go Wifi"
3
+ s.version = '1.2.0'
4
+ s.summary = "A simple scanner for your Wifi enabled Doxie scanner"
5
+ s.description = "A simple scanner for your Wifi enabled Doxie scanner"
6
6
  s.authors = ["Cristiano Betta"]
7
- s.email = 'cbetta@gmail.com'
7
+ s.email = 'cristiano@betta.io'
8
8
  s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE README.md doxie-scanner.gemspec)
9
9
  s.homepage = 'https://github.com/cbetta/doxie-scanner'
10
10
  s.license = 'MIT'
@@ -8,5 +8,23 @@ module Doxie
8
8
  hosts = doxies.map {|doxie| URI.parse(doxie[:location]).host }
9
9
  hosts.uniq
10
10
  end
11
+
12
+ def self.devices(frisky = Frisky::SSDP)
13
+ root_devices = frisky.search 'upnp:rootdevices'
14
+ doxies = root_devices.select { |device| device[:location].include?('doxie')}
15
+ hosts = doxies.map do |doxie|
16
+ {
17
+ ip: URI.parse(doxie[:location]).host,
18
+ model: Doxie::Scanner.api_version(doxie[:server])
19
+ }
20
+ end
21
+ hosts.uniq
22
+ end
23
+
24
+ private
25
+
26
+ def self.api_version server
27
+ server.include?('DX250') ? "API_V1" : "API_V2"
28
+ end
11
29
  end
12
30
  end
@@ -4,32 +4,65 @@ require 'doxie/scanner'
4
4
  describe 'Doxie::Scanner' do
5
5
  before do
6
6
  @frisky = Minitest::Mock.new
7
- @return_value = []
8
7
  @args = ['upnp:rootdevices']
8
+ @return_value = []
9
9
  end
10
10
 
11
- it 'should search for upnp:rootdevices' do
12
- @frisky.expect :search, @return_value, @args
13
- ips = Doxie::Scanner.ips(@frisky)
14
- @frisky.verify
15
- assert_equal ips, @return_value
16
- end
11
+ describe '.ips' do
12
+ it 'should search for upnp:rootdevices' do
13
+ @frisky.expect :search, @return_value, @args
14
+ ips = Doxie::Scanner.ips(@frisky)
15
+ @frisky.verify
16
+ assert_equal ips, @return_value
17
+ end
18
+
19
+ it 'should extract the host names for doxie devices' do
20
+ @frisky.expect :search, [
21
+ { location: "http://127.0.0.1/doxie/foo" },
22
+ { location: "http://127.0.0.2/doksy/foo" },
23
+ ], @args
24
+ ips = Doxie::Scanner.ips(@frisky)
25
+ assert_equal ips, ['127.0.0.1']
26
+ end
17
27
 
18
- it 'should extract the host names for doxie devices' do
19
- @frisky.expect :search, [
20
- { location: "http://127.0.0.1/doxie/foo" },
21
- { location: "http://127.0.0.2/doksy/foo" },
22
- ], @args
23
- ips = Doxie::Scanner.ips(@frisky)
24
- assert_equal ips, ['127.0.0.1']
28
+ it 'should only find unique host names' do
29
+ @frisky.expect :search, [
30
+ { location: "http://127.0.0.1/doxie/foo" },
31
+ { location: "http://127.0.0.1/doxie/foo" },
32
+ ], @args
33
+ ips = Doxie::Scanner.ips(@frisky)
34
+ assert_equal ips.length, 1
35
+ end
25
36
  end
26
37
 
27
- it 'should only find unique host names' do
28
- @frisky.expect :search, [
29
- { location: "http://127.0.0.1/doxie/foo" },
30
- { location: "http://127.0.0.1/doxie/foo" },
31
- ], @args
32
- ips = Doxie::Scanner.ips(@frisky)
33
- assert_equal ips.length, 1
38
+ describe '.devices' do
39
+ it 'should search for upnp:rootdevices' do
40
+ @frisky.expect :search, @return_value, @args
41
+ devices = Doxie::Scanner.devices(@frisky)
42
+ @frisky.verify
43
+ assert_equal devices, @return_value
44
+ end
45
+
46
+ it 'should extract the host names and api version number for doxie devices' do
47
+ @frisky.expect :search, [
48
+ { location: "http://127.0.0.1/doxie/foo", server: 'Linux/2.6.30.9, UPnP/1.0, DoxieDX300/1.08' },
49
+ { location: "http://127.0.0.2/doxie/foo", server: 'Linux/2.6.30.9, UPnP/1.0, DoxieDX250/1.08' },
50
+ { location: "http://127.0.0.3/noxie/foo", server: 'Linux/2.6.30.9, UPnP/1.0, Noxie/1.08' },
51
+ ], @args
52
+ devices = Doxie::Scanner.devices(@frisky)
53
+ assert_equal devices, [
54
+ { ip: '127.0.0.1', model: 'API_V2' },
55
+ { ip: '127.0.0.2', model: 'API_V1' },
56
+ ]
57
+ end
58
+
59
+ it 'should only find unique host names' do
60
+ @frisky.expect :search, [
61
+ { location: "http://127.0.0.1/doxie/foo", server: 'Linux/2.6.30.9, UPnP/1.0, DoxieDX300/1.08' },
62
+ { location: "http://127.0.0.1/doxie/foo", server: 'Linux/2.6.30.9, UPnP/1.0, DoxieDX300/1.08' },
63
+ ], @args
64
+ devices = Doxie::Scanner.devices(@frisky)
65
+ assert_equal devices.length, 1
66
+ end
34
67
  end
35
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doxie-scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristiano Betta
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: A simple scanner for your Doxie Go Wifi
56
- email: cbetta@gmail.com
55
+ description: A simple scanner for your Wifi enabled Doxie scanner
56
+ email: cristiano@betta.io
57
57
  executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
@@ -86,5 +86,5 @@ requirements: []
86
86
  rubygems_version: 3.0.2
87
87
  signing_key:
88
88
  specification_version: 4
89
- summary: A simple scanner for your Doxie Go Wifi
89
+ summary: A simple scanner for your Wifi enabled Doxie scanner
90
90
  test_files: []