Class: Doxie::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/doxie/client.rb

Overview

The client for connecting to a Doxie scanner.

Use the IP and password to connect as follows:

Doxie::Client.new(ip: '192.168.1.2', model: Doxie::Q, password: 'test')

Defined Under Namespace

Classes: Error

Constant Summary collapse

USERNAME =
'doxie'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
# File 'lib/doxie/client.rb', line 18

def initialize(options)
  @ip = options[:ip] || ''
  @password = options[:password] || ''
  @model = options[:model] || Doxie::API_V1
  @port = @model == Doxie::API_V1 ? 8080 : 80
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



16
17
18
# File 'lib/doxie/client.rb', line 16

def ip
  @ip
end

#modelObject

Returns the value of attribute model.



16
17
18
# File 'lib/doxie/client.rb', line 16

def model
  @model
end

#passwordObject

Returns the value of attribute password.



16
17
18
# File 'lib/doxie/client.rb', line 16

def password
  @password
end

#portObject

Returns the value of attribute port.



16
17
18
# File 'lib/doxie/client.rb', line 16

def port
  @port
end

Instance Method Details

#delete_scan(scan_name) ⇒ Object



63
64
65
# File 'lib/doxie/client.rb', line 63

def delete_scan(scan_name)
  delete("/scans#{scan_name}") || true
end

#delete_scans(scan_names) ⇒ Object



67
68
69
# File 'lib/doxie/client.rb', line 67

def delete_scans(scan_names)
  post('/scans/delete.json', scan_names) || true
end

#helloObject



25
26
27
# File 'lib/doxie/client.rb', line 25

def hello
  get('/hello.json')
end

#hello_extraObject



29
30
31
32
33
34
35
# File 'lib/doxie/client.rb', line 29

def hello_extra
  if model == Doxie::API_V2
    raise Doxie::Client::Error, 'Method does not exist for this model'
  end

  get('/hello_extra.json')
end

#recent_scansObject



51
52
53
# File 'lib/doxie/client.rb', line 51

def recent_scans
  get('/scans/recent.json') || []
end

#restartObject



37
38
39
# File 'lib/doxie/client.rb', line 37

def restart
  get('/restart.json') || true
end

#scan(scan_name, file_name = nil) ⇒ Object



55
56
57
# File 'lib/doxie/client.rb', line 55

def scan(scan_name, file_name = nil)
  file "/scans#{scan_name}", file_name
end

#scansObject



41
42
43
44
45
46
47
48
49
# File 'lib/doxie/client.rb', line 41

def scans
  get('/scans.json')
rescue Doxie::Client::Error => e
  # a 404 is thrown on the Doxie Q and
  # Doxie GO SE when there are no scans
  raise e if model == Doxie::API_V1

  []
end

#thumbnail(scan_name, file_name = nil) ⇒ Object



59
60
61
# File 'lib/doxie/client.rb', line 59

def thumbnail(scan_name, file_name = nil)
  file "/thumbnails#{scan_name}", file_name
end