class Evolis::PremiumSdk::Supervision

Constants

ERROR_EVENTS

All error events with description

OFF_EVENTS

All off events with description

READY_EVENTS

All ready events with description

WARNING_EVENTS

All warning events with description

Public Class Methods

new(host, port) click to toggle source

Initializes the class and sets SDK host and port

@param host [String] host or IP for SDK @param port [String, Fixnum] port for SDK

Calls superclass method Evolis::PremiumSdk::SdkBase::new
# File lib/evolis/premium_sdk/supervision.rb, line 11
def initialize(host, port)
  super(host, port, 'SUPERVISION')
end

Public Instance Methods

add_device(device) click to toggle source

Subscribes a new device to the notification service

@param device [String] printer name @return [true] on successful add

# File lib/evolis/premium_sdk/supervision.rb, line 34
def add_device(device)
  call_rpc('AddDevice', {
      device: device
  })
end
get_event(device) click to toggle source

Returns the notification of an unexpected event, as well as the list of actions for a device

@param device [String] printer name @return [Array] minor state of printer, with actions if available

# File lib/evolis/premium_sdk/supervision.rb, line 64
def get_event(device)
  resp = call_rpc('GetEvent', {
      device: device
  })

  if resp.include?(':')
    event, actions = resp.split(':')
    actions = actions.include?(',') ? actions.split(',') : [actions]
    return event, actions
  else
    return [resp]
  end
end
get_state(device) click to toggle source

Requests the state of a device

@param device [String] printer name @return [Array] major and minor state in array

# File lib/evolis/premium_sdk/supervision.rb, line 54
def get_state(device)
  call_rpc('GetState', {
      device: device
  }).split(',')
end
list(type_of_device, level = 2) click to toggle source

List all subscribed devices

@param type_of_device [String] type of printer to list @param level [Fixnum] state level to list, printername, major and minor (0, 1, 2). Level 2 lists all states. @return [Array] list of printers and states @raise [Error::InvalidStateLevelError] if level not valid

# File lib/evolis/premium_sdk/supervision.rb, line 21
def list(type_of_device, level = 2)
  raise Error::InvalidStateLevelError.new level unless (0..2).cover?(level)

  call_rpc('List', {
      device: type_of_device,
      level:  String(level)
  }).split(';')
end
list_states() click to toggle source

@return [Hash] list all possible minor states with grouping

# File lib/evolis/premium_sdk/supervision.rb, line 97
def list_states
  return {
      ERROR: ERROR_EVENTS,
      WARNING: WARNING_EVENTS,
      READY: READY_EVENTS,
      OFF: OFF_EVENTS
  }
end
print_event(event) click to toggle source

@return [Array] of descriptions for all minor state @raise [Error::InvalidEventError] if no minor state (event) is not found

remove_device(device) click to toggle source

Unsubscribes a new device to the notification service

@param device [String] printer name @return [true] on successful removal

# File lib/evolis/premium_sdk/supervision.rb, line 44
def remove_device(device)
  call_rpc('RemoveDevice', {
      device: device
  })
end
set_event(device, event, action) click to toggle source

Executes an action when an unexpected event is notified on a device during printing

@param device [String] printer name @param event [String] minor state of printer @param action [String] action to apply to minor state @return [true] if action successful @raise [Error::InvalidEventError] if event is invalid @raise [Error::InvalidActionError] if action is invalid

# File lib/evolis/premium_sdk/supervision.rb, line 86
def set_event(device, event, action)
  raise Error::InvalidEventError.new event unless validate_event?(event.upcase)
  raise Error::InvalidActionError.new action unless %w[CANCEL OK RETRY].include?(action.upcase)

  call_rpc('SetEvent', {
      action: "#{event}:#{action}",
      device: device
  })
end
validate_event?(event) click to toggle source

@return [true, false] true if event exist, false if not

# File lib/evolis/premium_sdk/supervision.rb, line 117
def validate_event?(event)
  return ERROR_EVENTS.merge(WARNING_EVENTS).has_key?(event.to_sym)
end