Class: CloudPrint::Printer
- Inherits:
-
Object
- Object
- CloudPrint::Printer
- 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
-
#initialize(options = {}) ⇒ Printer
constructor
A new instance of Printer.
- #method_missing(meth, *args, &block) ⇒ Object
- #print(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Printer
Returns a new instance of Printer.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cloudprint/printer.rb', line 8 def initialize( = {}) @client = [:client] @id = [:id] @status = [:status] @name = [:name] @display_name = [:display_name] @tags = [:tags] || {} @connection_status = [:connection_status] || 'UNKNOWN' @description = [:description] @capabilities = [:capabilities] 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.rb', line 27 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 |
# File 'lib/cloudprint/printer.rb', line 20 def print() method = [:content].is_a?(IO) ? :multipart_post : :post response = client.connection.send(method, '/submit', :printerid => self.id, :title => [:title], :content => [:content], :ticket => [:ticket].to_json, :contentType => [:content_type]) || {} return nil if response.nil? || response["job"].nil? client.print_jobs.new_from_response response["job"] end |