doxie 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -1
- data/doxie.gemspec +2 -1
- data/lib/doxie.rb +2 -119
- data/lib/doxie/client.rb +119 -0
- data/lib/doxie/version.rb +3 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d12a896170887de484098d01ed3aa71a340b19
|
4
|
+
data.tar.gz: cb8783fd43705f51653b91101241615cfd733da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261beb1d25db1fde8806789009d9da2f9e7491210d5cdf76155e4d05608599ead332ff0459fb90ed38129ef914e20b42ab166bd0b314207568d6600947843d56
|
7
|
+
data.tar.gz: 0c58ead8065c7f13fcab942efef7bc8f5b2c66a7528aafeeb43da299f883462e5b3c7aa3e7584f118fcf8376a5730a79ebe882a637f7b8df37a27719a65d7354
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/doxie.svg)](https://badge.fury.io/rb/doxie) [![Build Status](https://travis-ci.org/cbetta/doxie.svg?branch=master)](https://travis-ci.org/cbetta/doxie)
|
4
4
|
|
5
|
-
A wrapper for the Doxie Go Wifi API. Specification as per the [developer documentation](http://help.getdoxie.com/content/doxiego/05-advanced/03-wifi/04-api/Doxie-API-Developer-Guide.pdf).
|
5
|
+
A wrapper for the [Doxie Go Wifi](http://getdoxie.com) API. Specification as per the [developer documentation](http://help.getdoxie.com/content/doxiego/05-advanced/03-wifi/04-api/Doxie-API-Developer-Guide.pdf).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -25,6 +25,11 @@ client = Doxie::Client.new(ip: '192.168.1.2', password: 'test')
|
|
25
25
|
|
26
26
|
### GET /hello.json
|
27
27
|
|
28
|
+
Returns status information for the scanner, firmware, network mode, and password
|
29
|
+
configuration. Accessing this command does not require a password if one has been
|
30
|
+
set. The values returned depend on whether the scanner is creating its own
|
31
|
+
network or joining an existing network.
|
32
|
+
|
28
33
|
```rb
|
29
34
|
client.hello
|
30
35
|
=> {
|
@@ -39,8 +44,28 @@ client.hello
|
|
39
44
|
}
|
40
45
|
```
|
41
46
|
|
47
|
+
* __model__: Always DX250.
|
48
|
+
* __name__: The name of the scanner, which defaults to the form "Doxie_XXXXXX".
|
49
|
+
The name of a scanner can be changed by using the Doxie desktop app.
|
50
|
+
* __firmwareWiFi__: The Wi-Fi firmware version.
|
51
|
+
* __hasPassword__: Indicates whether a password has been set to authenticate API
|
52
|
+
access. Passwords can be set and removed by using the Doxie desktop app.
|
53
|
+
* __MAC__: The MAC address of the scanner as shown on the scanner's bottom
|
54
|
+
label.
|
55
|
+
* __mode__: "AP" if the scanner is creating its own network or "Client" if the
|
56
|
+
scanner is joining an existing network.
|
57
|
+
* __network__: If the scanner is in "Client" mode, this is the name of the
|
58
|
+
network it has joined.
|
59
|
+
* __ip__: If the scanner is in "Client" mode, this is the IP of the scanner on
|
60
|
+
the network it has joined.
|
61
|
+
|
42
62
|
### GET /hello_extra.json
|
43
63
|
|
64
|
+
Returns additional status values. These values are accessed separately from
|
65
|
+
those in `/hello.json` because there can be a delay of several seconds in
|
66
|
+
loading them. Accessing this command does not require a password if one has
|
67
|
+
been set.
|
68
|
+
|
44
69
|
```rb
|
45
70
|
client.hello_extra
|
46
71
|
=> {
|
@@ -49,8 +74,16 @@ client.hello_extra
|
|
49
74
|
}
|
50
75
|
```
|
51
76
|
|
77
|
+
* __firmware__: The scanner firmware version.
|
78
|
+
* __connectedToExternalPower__: Indicates whether the scanner is connected to
|
79
|
+
its AC adapter versus running on battery power. This value is not cached, so
|
80
|
+
it immediately reflects any state changes.
|
81
|
+
|
52
82
|
### GET /restart.json
|
53
83
|
|
84
|
+
Restarts the scanner's Wi-Fi system. The scanner's status light blinks blue
|
85
|
+
during the restart.
|
86
|
+
|
54
87
|
```rb
|
55
88
|
client.restart
|
56
89
|
=> true
|
@@ -58,6 +91,9 @@ client.restart
|
|
58
91
|
|
59
92
|
### GET /scans.json
|
60
93
|
|
94
|
+
Returns an array of all scans currently in the scanner’s memory. After scanning
|
95
|
+
a document, the scan will available via the API several second later.
|
96
|
+
|
61
97
|
```rb
|
62
98
|
client.scans
|
63
99
|
=> [
|
@@ -69,9 +105,17 @@ client.scans
|
|
69
105
|
]
|
70
106
|
```
|
71
107
|
|
108
|
+
Calling this function immediately after scanning something may return a blank
|
109
|
+
result, even if there are other scans on the scanner, due to the scanner's
|
110
|
+
memory being in use. Consider retrying if a successful HTTP status code is
|
111
|
+
returned along with a blank body.
|
72
112
|
|
73
113
|
### GET /scans/recent.json
|
74
114
|
|
115
|
+
Returns the path to the last scan if available. Monitoring this value for
|
116
|
+
changes provides a simple way to detect new scans without having to fetch the
|
117
|
+
entire list of scans.
|
118
|
+
|
75
119
|
```rb
|
76
120
|
client.recent_scans
|
77
121
|
=> {
|
@@ -111,15 +155,31 @@ client.thumbnail "/DOXIE/JPEG/IMG_0001.JPG", 'test.jpg'
|
|
111
155
|
=> true
|
112
156
|
```
|
113
157
|
|
158
|
+
Thumbnails are constrained to fit within 240x240 pixels. Thumbnails for new
|
159
|
+
scans are not generated until after the scan has been made available in
|
160
|
+
`/scans.json` and `/scans/recent.json`. This function will return 404 Not Found
|
161
|
+
if the thumbnail has not yet been generated. Retrying after a delay is
|
162
|
+
recommended to handle such cases.
|
163
|
+
|
114
164
|
### DELETE /scans/DOXIE/JPEG/IMG_XXXX.JPG
|
115
165
|
|
166
|
+
Deletes the scan at the specified path.
|
167
|
+
|
116
168
|
```rb
|
117
169
|
client.delete_scan "/DOXIE/JPEG/IMG_0001.JPG"
|
118
170
|
=> true
|
119
171
|
```
|
120
172
|
|
173
|
+
Deleting takes several seconds because a lock on the internal storage must be
|
174
|
+
obtained and released. Deleting may fail if the lock cannot be obtained
|
175
|
+
(e.g., the scanner is busy), so consider retrying on failure conditions. When
|
176
|
+
deleting multiple scans, use `/scans/delete.json` for best performance.
|
177
|
+
|
121
178
|
### POST /scans/delete.json
|
122
179
|
|
180
|
+
Deletes multiple scans in a single operation. This is much faster than deleting
|
181
|
+
each scan individually.
|
182
|
+
|
123
183
|
```rb
|
124
184
|
client.delete_scans ["/DOXIE/JPEG/IMG_0001.JPG", "/DOXIE/JPEG/IMG_0002.JPG"]
|
125
185
|
=> true
|
data/doxie.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
require File.expand_path('lib/doxie/version', File.dirname(__FILE__))
|
1
2
|
|
2
3
|
Gem::Specification.new do |s|
|
3
4
|
s.name = 'doxie'
|
4
|
-
s.version =
|
5
|
+
s.version = Doxie::VERSION
|
5
6
|
s.summary = "Doxie API Wrapper for getting scans off your Doxie scanner"
|
6
7
|
s.description = "Doxie API Wrapper for getting scans off your Doxie scanner"
|
7
8
|
s.authors = ["Cristiano Betta"]
|
data/lib/doxie.rb
CHANGED
@@ -1,119 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
4
|
-
module Doxie
|
5
|
-
class Client
|
6
|
-
class Error < StandardError; end
|
7
|
-
class ClientError < Error; end
|
8
|
-
class ServerError < Error; end
|
9
|
-
class AuthenticationError < ClientError; end
|
10
|
-
|
11
|
-
USERNAME = 'doxie'.freeze
|
12
|
-
|
13
|
-
attr_accessor :ip, :password
|
14
|
-
|
15
|
-
def initialize options
|
16
|
-
@ip = options[:ip] || ''
|
17
|
-
@password = options[:password] || ''
|
18
|
-
end
|
19
|
-
|
20
|
-
def hello
|
21
|
-
get('/hello.json')
|
22
|
-
end
|
23
|
-
|
24
|
-
def hello_extra
|
25
|
-
get('/hello_extra.json')
|
26
|
-
end
|
27
|
-
|
28
|
-
def restart
|
29
|
-
get('/restart.json')
|
30
|
-
end
|
31
|
-
|
32
|
-
def scans
|
33
|
-
get('/scans.json')
|
34
|
-
end
|
35
|
-
|
36
|
-
def recent_scans
|
37
|
-
get('/scans/recent.json')
|
38
|
-
end
|
39
|
-
|
40
|
-
def scan scan_name, file_name = nil
|
41
|
-
file "/scans#{scan_name}", file_name
|
42
|
-
end
|
43
|
-
|
44
|
-
def thumbnail scan_name, file_name = nil
|
45
|
-
file "/thumbnails#{scan_name}", file_name
|
46
|
-
end
|
47
|
-
|
48
|
-
def delete_scan scan_name
|
49
|
-
delete("/scans#{scan_name}")
|
50
|
-
end
|
51
|
-
|
52
|
-
def delete_scans scan_names
|
53
|
-
post("/scans/delete.json", scan_names)
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def get path
|
59
|
-
uri = uri_for(path)
|
60
|
-
message = Net::HTTP::Get.new(uri.request_uri)
|
61
|
-
parse(request(uri, message))
|
62
|
-
end
|
63
|
-
|
64
|
-
def post path, params
|
65
|
-
uri = uri_for(path)
|
66
|
-
message = Net::HTTP::Post.new(uri.request_uri)
|
67
|
-
message.body = JSON.generate(params)
|
68
|
-
parse(request(uri, message))
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def delete path
|
73
|
-
uri = uri_for(path)
|
74
|
-
message = Net::HTTP::Delete.new(uri.request_uri)
|
75
|
-
parse(request(uri, message))
|
76
|
-
end
|
77
|
-
|
78
|
-
def uri_for path
|
79
|
-
URI("https://#{ip}:8080#{path}")
|
80
|
-
end
|
81
|
-
|
82
|
-
def request(uri, message)
|
83
|
-
message.basic_auth USERNAME, password if password
|
84
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
-
http.request(message)
|
86
|
-
end
|
87
|
-
|
88
|
-
def parse response
|
89
|
-
case response
|
90
|
-
when Net::HTTPNoContent
|
91
|
-
return true
|
92
|
-
when Net::HTTPSuccess
|
93
|
-
if response['Content-Type'].split(';').first == 'application/json'
|
94
|
-
JSON.parse(response.body)
|
95
|
-
else
|
96
|
-
response.body
|
97
|
-
end
|
98
|
-
when Net::HTTPUnauthorized
|
99
|
-
raise AuthenticationError, "#{response.code} response from #{ip}"
|
100
|
-
when Net::HTTPClientError
|
101
|
-
raise ClientError, "#{response.code} response from #{ip}"
|
102
|
-
when Net::HTTPServerError
|
103
|
-
raise ServerError, "#{response.code} response from #{ip}"
|
104
|
-
else
|
105
|
-
raise Error, "#{response.code} response from #{ip}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def file scan_name, file_name
|
110
|
-
body = get(scan_name)
|
111
|
-
if file_name
|
112
|
-
File.open(file_name, 'wb') { |file| file.write(body) }
|
113
|
-
true
|
114
|
-
else
|
115
|
-
body
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
1
|
+
require 'doxie/version'
|
2
|
+
require 'doxie/client'
|
data/lib/doxie/client.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Doxie
|
5
|
+
class Client
|
6
|
+
class Error < StandardError; end
|
7
|
+
class ClientError < Error; end
|
8
|
+
class ServerError < Error; end
|
9
|
+
class AuthenticationError < ClientError; end
|
10
|
+
|
11
|
+
USERNAME = 'doxie'.freeze
|
12
|
+
|
13
|
+
attr_accessor :ip, :password
|
14
|
+
|
15
|
+
def initialize options
|
16
|
+
@ip = options[:ip] || ''
|
17
|
+
@password = options[:password] || ''
|
18
|
+
end
|
19
|
+
|
20
|
+
def hello
|
21
|
+
get('/hello.json')
|
22
|
+
end
|
23
|
+
|
24
|
+
def hello_extra
|
25
|
+
get('/hello_extra.json')
|
26
|
+
end
|
27
|
+
|
28
|
+
def restart
|
29
|
+
get('/restart.json')
|
30
|
+
end
|
31
|
+
|
32
|
+
def scans
|
33
|
+
get('/scans.json')
|
34
|
+
end
|
35
|
+
|
36
|
+
def recent_scans
|
37
|
+
get('/scans/recent.json')
|
38
|
+
end
|
39
|
+
|
40
|
+
def scan scan_name, file_name = nil
|
41
|
+
file "/scans#{scan_name}", file_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def thumbnail scan_name, file_name = nil
|
45
|
+
file "/thumbnails#{scan_name}", file_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_scan scan_name
|
49
|
+
delete("/scans#{scan_name}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_scans scan_names
|
53
|
+
post("/scans/delete.json", scan_names)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def get path
|
59
|
+
uri = uri_for(path)
|
60
|
+
message = Net::HTTP::Get.new(uri.request_uri)
|
61
|
+
parse(request(uri, message))
|
62
|
+
end
|
63
|
+
|
64
|
+
def post path, params
|
65
|
+
uri = uri_for(path)
|
66
|
+
message = Net::HTTP::Post.new(uri.request_uri)
|
67
|
+
message.body = JSON.generate(params)
|
68
|
+
parse(request(uri, message))
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def delete path
|
73
|
+
uri = uri_for(path)
|
74
|
+
message = Net::HTTP::Delete.new(uri.request_uri)
|
75
|
+
parse(request(uri, message))
|
76
|
+
end
|
77
|
+
|
78
|
+
def uri_for path
|
79
|
+
URI("https://#{ip}:8080#{path}")
|
80
|
+
end
|
81
|
+
|
82
|
+
def request(uri, message)
|
83
|
+
message.basic_auth USERNAME, password if password
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
http.request(message)
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse response
|
89
|
+
case response
|
90
|
+
when Net::HTTPNoContent
|
91
|
+
return true
|
92
|
+
when Net::HTTPSuccess
|
93
|
+
if response['Content-Type'].split(';').first == 'application/json'
|
94
|
+
JSON.parse(response.body)
|
95
|
+
else
|
96
|
+
response.body
|
97
|
+
end
|
98
|
+
when Net::HTTPUnauthorized
|
99
|
+
raise AuthenticationError, "#{response.code} response from #{ip}"
|
100
|
+
when Net::HTTPClientError
|
101
|
+
raise ClientError, "#{response.code} response from #{ip}"
|
102
|
+
when Net::HTTPServerError
|
103
|
+
raise ServerError, "#{response.code} response from #{ip}"
|
104
|
+
else
|
105
|
+
raise Error, "#{response.code} response from #{ip}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def file scan_name, file_name
|
110
|
+
body = get(scan_name)
|
111
|
+
if file_name
|
112
|
+
File.open(file_name, 'wb') { |file| file.write(body) }
|
113
|
+
true
|
114
|
+
else
|
115
|
+
body
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doxie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cristiano Betta
|
@@ -76,6 +76,8 @@ files:
|
|
76
76
|
- README.md
|
77
77
|
- doxie.gemspec
|
78
78
|
- lib/doxie.rb
|
79
|
+
- lib/doxie/client.rb
|
80
|
+
- lib/doxie/version.rb
|
79
81
|
- spec/doxie_spec.rb
|
80
82
|
homepage: https://github.com/cbetta/doxie
|
81
83
|
licenses:
|