doxie 2.0.0 → 3.0.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
- SHA1:
3
- metadata.gz: b397c377274d4870e902d85ae5e2b58045f35816
4
- data.tar.gz: 9b8346d5b0e6420622ca033ca9341c101b2feeca
2
+ SHA256:
3
+ metadata.gz: 86ca65be716261fc75507c33432181058e8c567be9e9c8f34e88b884222822be
4
+ data.tar.gz: 2686549b36f731522f3f7c11c505f9c57dbb2ff5e1d8cac461b2827d2a535b90
5
5
  SHA512:
6
- metadata.gz: 43c469dfc64dea3f032ad43743406fdc3bcc464b55b1f742e26b48d9557bc1df13f1af769b84dd823facb08f11d41bbdc5a623949522bfb12618acf1c6fbf9aa
7
- data.tar.gz: 9b0bfcdb9a2ad6df382fbeaa3950b257d631fb3369491432e7619f03194317f092c9ac2c197c26ecb5b78ca897bdeb93a27e2c54d72f6341c2a4a27362cc0279
6
+ metadata.gz: 87d150d0d5fc9cf79c06e3aa6726d92c3a1eaf83c8208043f4dd512f79f32af37512402a83919a095769ec63ba80722df70f83b225a00eb6ffe32cf60bb3fae7
7
+ data.tar.gz: b3b46c8ceb2128959117a7ca2502da83cf77ff3afece80acd563d95f849dd58ba6f42b31bef641770edd6cd80ef23578ab048cbbda5fe521f77c119ba8792f2b
data/README.md CHANGED
@@ -2,7 +2,15 @@
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](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).
5
+ A client library for the API available on WiFi-enabled [Doxie scanners](http://getdoxie.com). The specification of the API is available in their [developer documentation](/docs).
6
+
7
+ ## Scanners Supported
8
+
9
+ This library supports the following scanners:
10
+
11
+ * Doxie Go Wifi (DX250)
12
+ * Doxie Go SE (DX255)
13
+ * Doxie Q (DX300)
6
14
 
7
15
  ## Installation
8
16
 
@@ -15,9 +23,9 @@ gem 'doxie-scanner' # optional if your Doxie is not on a fixed IP
15
23
 
16
24
  ## Usage
17
25
 
18
- ### Finding your Doxie
26
+ ### Optional: Finding your Doxie's IP
19
27
 
20
- This requires the [`doxie_scanner`](https://github.com/cbetta/doxie_scanner) gem. This gem has a bigger dependency than the `doxie` gem which is why it has been split into a seperate library.
28
+ This optional step requires the [`doxie-scanner`](https://github.com/cbetta/doxie-scanner) gem. This gem has a bigger dependency than the `doxie` gem, which is why it has been intentionally separated into a seperate library.
21
29
 
22
30
  ```rb
23
31
  require 'doxie/scanner'
@@ -29,14 +37,29 @@ Doxie::Scanner.ips
29
37
 
30
38
  ### Client
31
39
 
32
- The client accepts an `ip` and `password`. You can omit the `password` if your Doxie has non set.
40
+ The client accepts an `ip` address, a scanner model number (defaults to `Doxie::GO`) and an optional `password`. You can omit the `password` if your Doxie has non set.
33
41
 
34
42
  ```rb
35
43
  require 'doxie'
36
- client = Doxie::Client.new(ip: '192.168.1.2', password: 'test')
44
+ client = Doxie::Client.new(
45
+ ip: '192.168.1.2',
46
+ model: Doxie::Q, # of Doxie::GO, or Doxie::GO_SE
47
+ password: 'test'
48
+ )
37
49
  ```
38
50
 
39
- ### GET /hello.json
51
+ Alternatively, you can use the [`doxie-scanner`](https://github.com/cbetta/doxie-scanner) gem to automatically connect to any scanner found.
52
+
53
+ ```rb
54
+ require 'doxie'
55
+ require 'doxie/scanner'
56
+
57
+ client = Doxie::Client.new(
58
+ Doxie::Scanner.devices.first
59
+ )
60
+ ```
61
+
62
+ ### `GET /hello.json`
40
63
 
41
64
  Returns status information for the scanner, firmware, network mode, and password
42
65
  configuration. Accessing this command does not require a password if one has been
@@ -57,22 +80,22 @@ client.hello
57
80
  }
58
81
  ```
59
82
 
60
- * __model__: Always DX250.
61
- * __name__: The name of the scanner, which defaults to the form "Doxie_XXXXXX".
83
+ * `model`: DX250 for the Doxie Go WiFi.
84
+ * `name`: The name of the scanner, which defaults to the form "Doxie_XXXXXX".
62
85
  The name of a scanner can be changed by using the Doxie desktop app.
63
- * __firmwareWiFi__: The Wi-Fi firmware version.
64
- * __hasPassword__: Indicates whether a password has been set to authenticate API
86
+ * `firmwareWiFi`: The Wi-Fi firmware version.
87
+ * `hasPassword`: Indicates whether a password has been set to authenticate API
65
88
  access. Passwords can be set and removed by using the Doxie desktop app.
66
- * __MAC__: The MAC address of the scanner as shown on the scanner's bottom
89
+ * `MAC`: The MAC address of the scanner as shown on the scanner's bottom
67
90
  label.
68
- * __mode__: "AP" if the scanner is creating its own network or "Client" if the
91
+ * `mode`: "AP" if the scanner is creating its own network or "Client" if the
69
92
  scanner is joining an existing network.
70
- * __network__: If the scanner is in "Client" mode, this is the name of the
93
+ * `network`: If the scanner is in "Client" mode, this is the name of the
71
94
  network it has joined.
72
- * __ip__: If the scanner is in "Client" mode, this is the IP of the scanner on
95
+ * `ip`: If the scanner is in "Client" mode, this is the IP of the scanner on
73
96
  the network it has joined.
74
97
 
75
- ### GET /hello_extra.json
98
+ ### `GET /hello_extra.json`
76
99
 
77
100
  Returns additional status values. These values are accessed separately from
78
101
  those in `/hello.json` because there can be a delay of several seconds in
@@ -87,12 +110,14 @@ client.hello_extra
87
110
  }
88
111
  ```
89
112
 
90
- * __firmware__: The scanner firmware version.
91
- * __connectedToExternalPower__: Indicates whether the scanner is connected to
113
+ * `firmware`: The scanner firmware version.
114
+ * `connectedToExternalPower`: Indicates whether the scanner is connected to
92
115
  its AC adapter versus running on battery power. This value is not cached, so
93
116
  it immediately reflects any state changes.
94
117
 
95
- ### GET /restart.json
118
+ This method is only available for the original Doxie Go WiFi model.
119
+
120
+ ### `GET /restart.json`
96
121
 
97
122
  Restarts the scanner's Wi-Fi system. The scanner's status light blinks blue
98
123
  during the restart.
@@ -102,7 +127,7 @@ client.restart
102
127
  => true
103
128
  ```
104
129
 
105
- ### GET /scans.json
130
+ ### `GET /scans.json`
106
131
 
107
132
  Returns an array of all scans currently in the scanner’s memory. After scanning
108
133
  a document, the scan will available via the API several second later.
@@ -123,7 +148,7 @@ result, even if there are other scans on the scanner, due to the scanner's
123
148
  memory being in use. Consider retrying if a successful HTTP status code is
124
149
  returned along with a blank body.
125
150
 
126
- ### GET /scans/recent.json
151
+ ### `GET /scans/recent.json`
127
152
 
128
153
  Returns the path to the last scan if available. Monitoring this value for
129
154
  changes provides a simple way to detect new scans without having to fetch the
@@ -136,7 +161,7 @@ client.recent_scans
136
161
  }
137
162
  ```
138
163
 
139
- ### GET /scans/DOXIE/JPEG/IMG_XXXX.JPG
164
+ ### `GET /scans/DOXIE/JPEG/IMG_XXXX.JPG`
140
165
 
141
166
  There are 2 ways to get a scan off your Doxie. The first is to get the raw binary content and then do something with it yourself.
142
167
 
@@ -152,7 +177,7 @@ client.scan "/DOXIE/JPEG/IMG_0001.JPG", 'test.jpg'
152
177
  => true
153
178
  ```
154
179
 
155
- ### GET /thumbnails/DOXIE/JPEG/IMG_XXXX.JPG
180
+ ### `GET /thumbnails/DOXIE/JPEG/IMG_XXXX.JPG`
156
181
 
157
182
  There are 2 ways to get a thumbnail off your Doxie. The first is to get the raw binary content and then do something with it yourself.
158
183
 
@@ -174,7 +199,7 @@ scans are not generated until after the scan has been made available in
174
199
  if the thumbnail has not yet been generated. Retrying after a delay is
175
200
  recommended to handle such cases.
176
201
 
177
- ### DELETE /scans/DOXIE/JPEG/IMG_XXXX.JPG
202
+ ### `DELETE /scans/DOXIE/JPEG/IMG_XXXX.JPG`
178
203
 
179
204
  Deletes the scan at the specified path.
180
205
 
@@ -188,7 +213,9 @@ obtained and released. Deleting may fail if the lock cannot be obtained
188
213
  (e.g., the scanner is busy), so consider retrying on failure conditions. When
189
214
  deleting multiple scans, use `/scans/delete.json` for best performance.
190
215
 
191
- ### POST /scans/delete.json
216
+ This will raise an error if the file is no longer present (`Doxie::Client::Error<Net::HTTPForbidden>`)
217
+
218
+ ### `POST /scans/delete.json`
192
219
 
193
220
  Deletes multiple scans in a single operation. This is much faster than deleting
194
221
  each scan individually.
@@ -198,6 +225,8 @@ client.delete_scans ["/DOXIE/JPEG/IMG_0001.JPG", "/DOXIE/JPEG/IMG_0002.JPG"]
198
225
  => true
199
226
  ```
200
227
 
228
+ This will raise an error if the files are no longer present (`Doxie::Client::Error<Net::HTTPForbidden>`)
229
+
201
230
  ## Contributing
202
231
 
203
232
  1. **Fork** the repo on GitHub
@@ -1,2 +1,3 @@
1
1
  require 'doxie/version'
2
+ require 'doxie/models'
2
3
  require 'doxie/client'
@@ -5,17 +5,19 @@ module Doxie
5
5
  # The client for connecting to a Doxie scanner.
6
6
  #
7
7
  # Use the IP and password to connect as follows:
8
- # Doxie::Client.new(ip: '192.168.1.2', password: 'test')
8
+ # Doxie::Client.new(ip: '192.168.1.2', model: Doxie::Q, password: 'test')
9
9
  class Client
10
10
  class Error < StandardError; end
11
11
 
12
12
  USERNAME = 'doxie'.freeze
13
13
 
14
- attr_accessor :ip, :password
14
+ attr_accessor :ip, :password, :model, :port
15
15
 
16
16
  def initialize(options)
17
17
  @ip = options[:ip] || ''
18
18
  @password = options[:password] || ''
19
+ @model = options[:model] || Doxie::API_V1
20
+ @port = @model == Doxie::API_V1 ? 8080 : 80
19
21
  end
20
22
 
21
23
  def hello
@@ -23,19 +25,25 @@ module Doxie
23
25
  end
24
26
 
25
27
  def hello_extra
28
+ raise Error.new('Method does not exist for this model') if model == Doxie::API_V2
26
29
  get('/hello_extra.json')
27
30
  end
28
31
 
29
32
  def restart
30
- get('/restart.json')
33
+ get('/restart.json') || true
31
34
  end
32
35
 
33
36
  def scans
34
37
  get('/scans.json')
38
+ rescue Doxie::Client::Error => error
39
+ # a 404 is thrown on the Doxie Q and
40
+ # Doxie GO SE when there are no scans
41
+ raise error if model == Doxie::DX250
42
+ []
35
43
  end
36
44
 
37
45
  def recent_scans
38
- get('/scans/recent.json')
46
+ get('/scans/recent.json') || []
39
47
  end
40
48
 
41
49
  def scan(scan_name, file_name = nil)
@@ -47,11 +55,11 @@ module Doxie
47
55
  end
48
56
 
49
57
  def delete_scan(scan_name)
50
- delete("/scans#{scan_name}")
58
+ delete("/scans#{scan_name}") || true
51
59
  end
52
60
 
53
61
  def delete_scans(scan_names)
54
- post('/scans/delete.json', scan_names)
62
+ post('/scans/delete.json', scan_names) || true
55
63
  end
56
64
 
57
65
  private
@@ -76,11 +84,11 @@ module Doxie
76
84
  end
77
85
 
78
86
  def uri_for(path)
79
- URI("https://#{ip}:8080#{path}")
87
+ URI("http://#{ip}:#{port}#{path}")
80
88
  end
81
89
 
82
90
  def request(uri, message)
83
- message.basic_auth USERNAME, password if password
91
+ message.basic_auth USERNAME, password if password && password.length > 0
84
92
  http = Net::HTTP.new(uri.host, uri.port)
85
93
  http.request(message)
86
94
  end
@@ -88,7 +96,7 @@ module Doxie
88
96
  def parse(response)
89
97
  case response
90
98
  when Net::HTTPNoContent
91
- true
99
+ nil
92
100
  when Net::HTTPSuccess
93
101
  parse_json(response)
94
102
  else
@@ -0,0 +1,12 @@
1
+ module Doxie
2
+ API_V1 = 'API_V1'.freeze
3
+ API_V2 = 'API_V2'.freeze
4
+
5
+ DX250 = API_V1
6
+ DX255 = API_V2
7
+ DX300 = API_V2
8
+
9
+ GO = API_V1
10
+ GO_SE = API_V2
11
+ Q = API_V2
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Doxie
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -18,9 +18,22 @@ describe 'Doxie::Client' do
18
18
  @json_response_body = json_response_body('{"key":"value"}')
19
19
  @ip = '192.168.1.1'
20
20
  @base_url = "http://#{@ip}:8080"
21
+ @base_url_v2 = "http://#{@ip}:80"
21
22
  @client = Doxie::Client.new(ip: @ip)
22
23
  end
23
24
 
25
+ describe 'Doxie Models' do
26
+ it 'should assign the right values to each model' do
27
+ assert_equal Doxie::GO, Doxie::API_V1
28
+ assert_equal Doxie::DX250, Doxie::API_V1
29
+
30
+ assert_equal Doxie::Q, Doxie::API_V2
31
+ assert_equal Doxie::GO_SE, Doxie::API_V2
32
+ assert_equal Doxie::DX255, Doxie::API_V2
33
+ assert_equal Doxie::DX300, Doxie::API_V2
34
+ end
35
+ end
36
+
24
37
  describe 'get /hello.json' do
25
38
  it 'should return the result' do
26
39
  stub_request(:get, "#{@base_url}/hello.json")
@@ -35,6 +48,12 @@ describe 'Doxie::Client' do
35
48
  .to_return(@json_response_body)
36
49
  @client.hello_extra.must_equal(@json_response_object)
37
50
  end
51
+
52
+ it 'should error for API V2 models, as the method does not exist' do
53
+ @client = Doxie::Client.new(ip: @ip, model: Doxie::API_V2)
54
+ error = -> { @client.hello_extra }.must_raise(Doxie::Client::Error)
55
+ error.message.must_match "Method does not exist for this model"
56
+ end
38
57
  end
39
58
 
40
59
  describe 'get /restart.json' do
@@ -51,6 +70,13 @@ describe 'Doxie::Client' do
51
70
  .to_return(@json_response_body)
52
71
  @client.scans.must_equal(@json_response_object)
53
72
  end
73
+
74
+ it 'should return an empty array when there are no scans on a V2 model' do
75
+ @client = Doxie::Client.new(ip: @ip, model: Doxie::API_V2)
76
+ stub_request(:get, "#{@base_url_v2}/scans.json")
77
+ .to_return(status: 404)
78
+ @client.scans.must_equal([])
79
+ end
54
80
  end
55
81
 
56
82
  describe 'get /scans/recent.json' do
@@ -59,6 +85,13 @@ describe 'Doxie::Client' do
59
85
  .to_return(@json_response_body)
60
86
  @client.recent_scans.must_equal(@json_response_object)
61
87
  end
88
+
89
+ it 'should return an empty array when there are no scans on a V2 model' do
90
+ @client = Doxie::Client.new(ip: @ip, model: Doxie::API_V2)
91
+ stub_request(:get, "#{@base_url_v2}/scans/recent.json")
92
+ .to_return(status: 204)
93
+ @client.recent_scans.must_equal([])
94
+ end
62
95
  end
63
96
 
64
97
  describe 'get /scans/DOXIE/JPEG/IMG_0001.JPG' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doxie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristiano Betta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-06 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - doxie.gemspec
78
78
  - lib/doxie.rb
79
79
  - lib/doxie/client.rb
80
+ - lib/doxie/models.rb
80
81
  - lib/doxie/version.rb
81
82
  - spec/doxie_spec.rb
82
83
  homepage: https://github.com/cbetta/doxie
@@ -98,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.6.13
102
+ rubygems_version: 3.0.2
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Doxie API Wrapper for getting scans off your Doxie scanner