Class: CloudPrint::Printer
- Inherits:
-
Object
- Object
- CloudPrint::Printer
show all
- Defined in:
- lib/cloudprint/printer.rb
Constant Summary
collapse
- CONNECTION_STATUSES =
%w{ONLINE UNKNOWN OFFLINE DORMANT}
- CONFIG_OPTS =
[:id, :status, :name, :tags, :display_name, :client, :connection_status, :description, :capabilities]
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Printer
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/cloudprint/printer.rb', line 8
def initialize(options = {})
@client = options[:client]
@id = options[:id]
@status = options[:status]
@name = options[:name]
@display_name = options[:display_name]
@tags = options[:tags] || {}
@connection_status = options[:connection_status] || 'UNKNOWN'
@description = options[:description]
@capabilities = options[:capabilities]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/cloudprint/printer.rb', line 28
def method_missing(meth, *args, &block)
if CONNECTION_STATUSES.map{ |s| s.downcase + '?' }.include?(meth.to_s)
connection_status.downcase == meth.to_s.chop
else
super
end
end
|
Instance Method Details
#print(options) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/cloudprint/printer.rb', line 20
def print(options)
content = options[:content]
method = content.is_a?(IO) || content.is_a?(StringIO) || content.is_a?(Tempfile) ? :multipart_post : :post
response = client.connection.send(method, '/submit', :printerid => self.id, :title => options[:title], :content => options[:content], :ticket => options[:ticket].to_json, :contentType => options[:content_type]) || {}
return nil if response.nil? || response["job"].nil?
client.print_jobs.new_from_response response["job"]
end
|