doxie 1.0.0 → 2.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
2
  SHA1:
3
- metadata.gz: 906660de3417d7d30e3a74d18dde7de388b4425d
4
- data.tar.gz: ee590fbfbefa0d0c685399f3461c5b5b3aecb06d
3
+ metadata.gz: b397c377274d4870e902d85ae5e2b58045f35816
4
+ data.tar.gz: 9b8346d5b0e6420622ca033ca9341c101b2feeca
5
5
  SHA512:
6
- metadata.gz: 169c926ac7383ad8c3f09cb662d78eded14c0c78533a9c8faf8565ac2fc032113406972cd6177650fde442adf1d481b3c0672ed7f414a2f427d94ca2794db525
7
- data.tar.gz: d64a1da4878d1297749f3207283487985083d6a1e53133147d89e9beca3eec2ccd865f9364017c6db9aab32b22c96898ed86c3ea04bca914cbd641376ad94dae
6
+ metadata.gz: 43c469dfc64dea3f032ad43743406fdc3bcc464b55b1f742e26b48d9557bc1df13f1af769b84dd823facb08f11d41bbdc5a623949522bfb12618acf1c6fbf9aa
7
+ data.tar.gz: 9b0bfcdb9a2ad6df382fbeaa3950b257d631fb3369491432e7619f03194317f092c9ac2c197c26ecb5b78ca897bdeb93a27e2c54d72f6341c2a4a27362cc0279
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Doxie Ruby API Wrapper
1
+ # Ruby API library for Doxie Go Wifi
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
 
@@ -10,7 +10,7 @@ Either install directly or via bundler.
10
10
 
11
11
  ```rb
12
12
  gem 'doxie'
13
- gem 'doxie_scanner' # optional if your Doxie is not on a fixed IP
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 'doxie_scanner'
24
- DoxieScanner.ips
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 livrary](https://github.com/Nexmo/nexmo-ruby) which helped me remember how to nicely wrap the Doxie API.
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).
@@ -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 = "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"]
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}/**/*') + %w(LICENSE README.md doxie.gemspec)
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'
@@ -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 options
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 scan_name, file_name = nil
41
+ def scan(scan_name, file_name = nil)
41
42
  file "/scans#{scan_name}", file_name
42
43
  end
43
44
 
44
- def thumbnail scan_name, file_name = nil
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 scan_name
49
+ def delete_scan(scan_name)
49
50
  delete("/scans#{scan_name}")
50
51
  end
51
52
 
52
- def delete_scans scan_names
53
- post("/scans/delete.json", scan_names)
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 path
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 path, params
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 path
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 response
88
+ def parse(response)
89
89
  case response
90
90
  when Net::HTTPNoContent
91
- return true
91
+ true
92
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}"
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
- raise Error, "#{response.code} response from #{ip}"
103
+ response.body
106
104
  end
107
105
  end
108
106
 
109
- def file scan_name, file_name
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) }
@@ -1,3 +1,3 @@
1
1
  module Doxie
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -5,11 +5,16 @@ require 'doxie'
5
5
 
6
6
  describe 'Doxie::Client' do
7
7
  def json_response_body(content)
8
- {headers: {'Content-Type' => 'application/json;charset=utf-8'}, body: content}
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').must_equal(@json_response_object)
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').must_equal(@json_response_object)
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']).must_equal(true)
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::AuthenticationError)
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::ClientError)
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::ServerError)
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: 1.0.0
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: 2016-05-30 00:00:00.000000000 Z
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.5.1
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