doxie 1.0.0 → 2.0.0
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 +4 -4
- data/README.md +5 -5
- data/doxie.gemspec +5 -4
- data/lib/doxie/client.rb +27 -29
- data/lib/doxie/version.rb +1 -1
- data/spec/doxie_spec.rb +16 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b397c377274d4870e902d85ae5e2b58045f35816
|
4
|
+
data.tar.gz: 9b8346d5b0e6420622ca033ca9341c101b2feeca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c469dfc64dea3f032ad43743406fdc3bcc464b55b1f742e26b48d9557bc1df13f1af769b84dd823facb08f11d41bbdc5a623949522bfb12618acf1c6fbf9aa
|
7
|
+
data.tar.gz: 9b0bfcdb9a2ad6df382fbeaa3950b257d631fb3369491432e7619f03194317f092c9ac2c197c26ecb5b78ca897bdeb93a27e2c54d72f6341c2a4a27362cc0279
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Ruby API library for Doxie Go Wifi
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/doxie) [](https://travis-ci.org/cbetta/doxie)
|
4
4
|
|
@@ -10,7 +10,7 @@ Either install directly or via bundler.
|
|
10
10
|
|
11
11
|
```rb
|
12
12
|
gem 'doxie'
|
13
|
-
gem '
|
13
|
+
gem 'doxie-scanner' # optional if your Doxie is not on a fixed IP
|
14
14
|
```
|
15
15
|
|
16
16
|
## Usage
|
@@ -20,8 +20,8 @@ gem 'doxie_scanner' # optional if your Doxie is not on a fixed IP
|
|
20
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.
|
21
21
|
|
22
22
|
```rb
|
23
|
-
require '
|
24
|
-
|
23
|
+
require 'doxie/scanner'
|
24
|
+
Doxie::Scanner.ips
|
25
25
|
=> [
|
26
26
|
[0] "192.168.1.2"
|
27
27
|
]
|
@@ -214,6 +214,6 @@ client.delete_scans ["/DOXIE/JPEG/IMG_0001.JPG", "/DOXIE/JPEG/IMG_0002.JPG"]
|
|
214
214
|
|
215
215
|
## Credits and License
|
216
216
|
|
217
|
-
Thanks to [@timcraft](https://github.com/timcraft) for the excellent [Nexmo Ruby
|
217
|
+
Thanks to [@timcraft](https://github.com/timcraft) for the excellent [Nexmo Ruby library](https://github.com/Nexmo/nexmo-ruby) which helped me remember how to nicely wrap the Doxie API.
|
218
218
|
|
219
219
|
This library is released under the [MIT License](LICENSE).
|
data/doxie.gemspec
CHANGED
@@ -3,11 +3,12 @@ require File.expand_path('lib/doxie/version', File.dirname(__FILE__))
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'doxie'
|
5
5
|
s.version = Doxie::VERSION
|
6
|
-
s.summary =
|
7
|
-
s.description =
|
8
|
-
s.authors = [
|
6
|
+
s.summary = 'Doxie API Wrapper for getting scans off your Doxie scanner'
|
7
|
+
s.description = 'Doxie API Wrapper for getting scans off your Doxie scanner'
|
8
|
+
s.authors = ['Cristiano Betta']
|
9
9
|
s.email = 'cbetta@gmail.com'
|
10
|
-
s.files = Dir.glob('{lib,spec}/**/*') +
|
10
|
+
s.files = Dir.glob('{lib,spec}/**/*') +
|
11
|
+
%w[LICENSE README.md doxie.gemspec]
|
11
12
|
s.homepage = 'https://github.com/cbetta/doxie'
|
12
13
|
s.license = 'MIT'
|
13
14
|
s.require_path = 'lib'
|
data/lib/doxie/client.rb
CHANGED
@@ -2,17 +2,18 @@ require 'net/http'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module Doxie
|
5
|
+
# The client for connecting to a Doxie scanner.
|
6
|
+
#
|
7
|
+
# Use the IP and password to connect as follows:
|
8
|
+
# Doxie::Client.new(ip: '192.168.1.2', password: 'test')
|
5
9
|
class Client
|
6
10
|
class Error < StandardError; end
|
7
|
-
class ClientError < Error; end
|
8
|
-
class ServerError < Error; end
|
9
|
-
class AuthenticationError < ClientError; end
|
10
11
|
|
11
12
|
USERNAME = 'doxie'.freeze
|
12
13
|
|
13
14
|
attr_accessor :ip, :password
|
14
15
|
|
15
|
-
def initialize
|
16
|
+
def initialize(options)
|
16
17
|
@ip = options[:ip] || ''
|
17
18
|
@password = options[:password] || ''
|
18
19
|
end
|
@@ -37,45 +38,44 @@ module Doxie
|
|
37
38
|
get('/scans/recent.json')
|
38
39
|
end
|
39
40
|
|
40
|
-
def scan
|
41
|
+
def scan(scan_name, file_name = nil)
|
41
42
|
file "/scans#{scan_name}", file_name
|
42
43
|
end
|
43
44
|
|
44
|
-
def thumbnail
|
45
|
+
def thumbnail(scan_name, file_name = nil)
|
45
46
|
file "/thumbnails#{scan_name}", file_name
|
46
47
|
end
|
47
48
|
|
48
|
-
def delete_scan
|
49
|
+
def delete_scan(scan_name)
|
49
50
|
delete("/scans#{scan_name}")
|
50
51
|
end
|
51
52
|
|
52
|
-
def delete_scans
|
53
|
-
post(
|
53
|
+
def delete_scans(scan_names)
|
54
|
+
post('/scans/delete.json', scan_names)
|
54
55
|
end
|
55
56
|
|
56
57
|
private
|
57
58
|
|
58
|
-
def get
|
59
|
+
def get(path)
|
59
60
|
uri = uri_for(path)
|
60
61
|
message = Net::HTTP::Get.new(uri.request_uri)
|
61
62
|
parse(request(uri, message))
|
62
63
|
end
|
63
64
|
|
64
|
-
def post
|
65
|
+
def post(path, params)
|
65
66
|
uri = uri_for(path)
|
66
67
|
message = Net::HTTP::Post.new(uri.request_uri)
|
67
68
|
message.body = JSON.generate(params)
|
68
69
|
parse(request(uri, message))
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
-
def delete path
|
72
|
+
def delete(path)
|
73
73
|
uri = uri_for(path)
|
74
74
|
message = Net::HTTP::Delete.new(uri.request_uri)
|
75
75
|
parse(request(uri, message))
|
76
76
|
end
|
77
77
|
|
78
|
-
def uri_for
|
78
|
+
def uri_for(path)
|
79
79
|
URI("https://#{ip}:8080#{path}")
|
80
80
|
end
|
81
81
|
|
@@ -85,28 +85,26 @@ module Doxie
|
|
85
85
|
http.request(message)
|
86
86
|
end
|
87
87
|
|
88
|
-
def parse
|
88
|
+
def parse(response)
|
89
89
|
case response
|
90
90
|
when Net::HTTPNoContent
|
91
|
-
|
91
|
+
true
|
92
92
|
when Net::HTTPSuccess
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
when Net::HTTPServerError
|
103
|
-
raise ServerError, "#{response.code} response from #{ip}"
|
93
|
+
parse_json(response)
|
94
|
+
else
|
95
|
+
raise Error, response
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse_json(response)
|
100
|
+
if response['Content-Type'].split(';').first == 'application/json'
|
101
|
+
JSON.parse(response.body)
|
104
102
|
else
|
105
|
-
|
103
|
+
response.body
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
|
-
def file
|
107
|
+
def file(scan_name, file_name)
|
110
108
|
body = get(scan_name)
|
111
109
|
if file_name
|
112
110
|
File.open(file_name, 'wb') { |file| file.write(body) }
|
data/lib/doxie/version.rb
CHANGED
data/spec/doxie_spec.rb
CHANGED
@@ -5,11 +5,16 @@ require 'doxie'
|
|
5
5
|
|
6
6
|
describe 'Doxie::Client' do
|
7
7
|
def json_response_body(content)
|
8
|
-
{
|
8
|
+
{
|
9
|
+
headers: {
|
10
|
+
'Content-Type' => 'application/json;charset=utf-8'
|
11
|
+
},
|
12
|
+
body: content
|
13
|
+
}
|
9
14
|
end
|
10
15
|
|
11
16
|
before do
|
12
|
-
@json_response_object = {'key' => 'value'}
|
17
|
+
@json_response_object = { 'key' => 'value' }
|
13
18
|
@json_response_body = json_response_body('{"key":"value"}')
|
14
19
|
@ip = '192.168.1.1'
|
15
20
|
@base_url = "http://#{@ip}:8080"
|
@@ -74,7 +79,8 @@ describe 'Doxie::Client' do
|
|
74
79
|
it 'should return the result' do
|
75
80
|
stub_request(:get, "#{@base_url}/thumbnails/DOXIE/JPEG/IMG_0001.JPG")
|
76
81
|
.to_return(@json_response_body)
|
77
|
-
@client.thumbnail('/DOXIE/JPEG/IMG_0001.JPG')
|
82
|
+
@client.thumbnail('/DOXIE/JPEG/IMG_0001.JPG')
|
83
|
+
.must_equal(@json_response_object)
|
78
84
|
end
|
79
85
|
|
80
86
|
it 'should write to file' do
|
@@ -88,7 +94,8 @@ describe 'Doxie::Client' do
|
|
88
94
|
it 'should return the result' do
|
89
95
|
stub_request(:delete, "#{@base_url}/scans/DOXIE/JPEG/IMG_0001.JPG")
|
90
96
|
.to_return(@json_response_body)
|
91
|
-
@client.delete_scan('/DOXIE/JPEG/IMG_0001.JPG')
|
97
|
+
@client.delete_scan('/DOXIE/JPEG/IMG_0001.JPG')
|
98
|
+
.must_equal(@json_response_object)
|
92
99
|
end
|
93
100
|
end
|
94
101
|
|
@@ -96,25 +103,26 @@ describe 'Doxie::Client' do
|
|
96
103
|
it 'should return the result' do
|
97
104
|
stub_request(:post, "#{@base_url}/scans/delete.json")
|
98
105
|
.to_return(status: 204)
|
99
|
-
@client.delete_scans(['/DOXIE/JPEG/IMG_0001.JPG'])
|
106
|
+
@client.delete_scans(['/DOXIE/JPEG/IMG_0001.JPG'])
|
107
|
+
.must_equal(true)
|
100
108
|
end
|
101
109
|
end
|
102
110
|
|
103
111
|
it 'raises an authentication error exception if the response code is 401' do
|
104
112
|
stub_request(:get, "#{@base_url}/hello.json")
|
105
113
|
.to_return(status: 401)
|
106
|
-
proc { @client.hello }.must_raise(Doxie::Client::
|
114
|
+
proc { @client.hello }.must_raise(Doxie::Client::Error)
|
107
115
|
end
|
108
116
|
|
109
117
|
it 'raises a client error exception if the response code is 4xx' do
|
110
118
|
stub_request(:get, "#{@base_url}/hello.json")
|
111
119
|
.to_return(status: 400)
|
112
|
-
proc { @client.hello }.must_raise(Doxie::Client::
|
120
|
+
proc { @client.hello }.must_raise(Doxie::Client::Error)
|
113
121
|
end
|
114
122
|
|
115
123
|
it 'raises a server error exception if the response code is 5xx' do
|
116
124
|
stub_request(:get, "#{@base_url}/hello.json")
|
117
125
|
.to_return(status: 500)
|
118
|
-
proc { @client.hello }.must_raise(Doxie::Client::
|
126
|
+
proc { @client.hello }.must_raise(Doxie::Client::Error)
|
119
127
|
end
|
120
128
|
end
|
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:
|
4
|
+
version: 2.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:
|
11
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.6.13
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Doxie API Wrapper for getting scans off your Doxie scanner
|