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
Initializes the class and sets SDK host and port
@param host [String] host or IP for SDK @param port [String, Fixnum] port for SDK
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
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
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
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 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
@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
@return [Array] of descriptions for all minor state @raise [Error::InvalidEventError] if no minor state (event) is not found
# File lib/evolis/premium_sdk/supervision.rb, line 108 def print_event(event) list_states.each do |status, events| return events[event.to_sym] if events.has_key?(event.to_sym) end raise Error::InvalidEventError.new event end
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
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
@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