class PrintNode::PrintJob

An object for printjob creation. @author Jake Torrance @author PrintNode

Attributes

content[RW]
content_type[RW]
printer_id[RW]
source[RW]
title[RW]

Public Class Methods

new(printer_id, title, content_type, content, source) click to toggle source

Initializes the object with the variables required.

# File lib/printnode/printjob.rb, line 15
def initialize(printer_id, title, content_type, content, source)
  @printer_id = printer_id
  @title = title
  @content_type = content_type
  @content = content
  @source = source
end

Public Instance Methods

content_is_existing_file?() click to toggle source
# File lib/printnode/printjob.rb, line 45
def content_is_existing_file?
    begin
        File.exist?(@content)
    rescue
        false
    end
end
load_content() click to toggle source
# File lib/printnode/printjob.rb, line 34
def load_content
  # Used to be, we only supported file names for Base64, but it's actually better
  # to allow the user to send us a data string if they desire.  Testing the
  # content to see if it's a path allows for backwards compatibility
  if @content_type.match('base64$') && content_is_existing_file?
    Base64.encode64(IO.read(@content))
  else
    @content
  end
end
to_hash() click to toggle source

Maps the object into a hash ready for JSON Encoding.

# File lib/printnode/printjob.rb, line 24
def to_hash
  {
      'printerId' => @printer_id,
      'title' => @title,
      'contentType' => @content_type,
      'content' => load_content,
      'source' => @source
  }
end