Class: CloudPrint::PrinterCollection
- Inherits:
-
Object
- Object
- CloudPrint::PrinterCollection
show all
- Defined in:
- lib/cloudprint/printer_collection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PrinterCollection.
6
7
8
|
# File 'lib/cloudprint/printer_collection.rb', line 6
def initialize client
@client = client
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/cloudprint/printer_collection.rb', line 27
def method_missing(meth, *args, &block)
if meth =~ /^search_(#{Printer::CONNECTION_STATUSES.map(&:downcase).join('|')}|all)$/
search args[0], connection_status: $1.upcase
else
super
end
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4
5
6
|
# File 'lib/cloudprint/printer_collection.rb', line 4
def client
@client
end
|
Instance Method Details
#all ⇒ Object
16
17
18
|
# File 'lib/cloudprint/printer_collection.rb', line 16
def all
search_all
end
|
#find(printer_id) ⇒ Object
10
11
12
13
14
|
# File 'lib/cloudprint/printer_collection.rb', line 10
def find(printer_id)
response = client.connection.get('/printer', :printerid => printer_id, :printer_connection_status => true)
first_printer_hash = response['printers'].first
new_printer_from_hash(first_printer_hash)
end
|
#new(opts) ⇒ Object
35
36
37
|
# File 'lib/cloudprint/printer_collection.rb', line 35
def new opts
Printer.new(opts.merge(client: client))
end
|
#new_printer_from_hash(hash) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/cloudprint/printer_collection.rb', line 39
def new_printer_from_hash(hash)
Printer.new(
client: client,
id: hash['id'],
status: hash['status'],
name: hash['name'],
display_name: hash['displayName'],
tags: hash['tags'],
connection_status: hash['connectionStatus'],
description: hash['description'],
capabilities: hash['capabilities']
)
end
|
#search(query = nil, conditions = {}) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/cloudprint/printer_collection.rb', line 20
def search(query = nil, conditions = {})
conditions[:q] = query unless query.nil?
response = client.connection.get('/search', conditions)
response['printers'].map { |p| new_printer_from_hash(p) }
end
|