class Evolis::PremiumSdk::Setting

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/setting.rb, line 11
def initialize(host, port)
  super(host, port, 'SETTING')
end

Public Instance Methods

begin(device) click to toggle source

Starts a configuration session

@param device [String] printer name @return [String] session id

# File lib/evolis/premium_sdk/setting.rb, line 19
def begin(device)
  self.active_session = call_rpc('Begin', {
      device: device
  })
end
end() click to toggle source

Ends the session

@return [true] if ended session @raise [Error::NoActiveSessionError] if no active session

# File lib/evolis/premium_sdk/setting.rb, line 105
def end
  raise Error::NoActiveSessionError.new unless active_session?

  call_rpc('End', {
      session: self.active_session
  })
end
export(format = 'printer') click to toggle source

Exports parameters

@param format [String] format to export settings, `printer`, `text` or `xml` @return [true] on success with format `printer` @return [Array] of setting=value pairs on format `text` @return [String] base64 encoded xml @raise [Error::NoActiveSessionError] if no active session @raise [Error::InvalidExportFormatError] when format is invalid

# File lib/evolis/premium_sdk/setting.rb, line 33
def export(format = 'printer')
  raise Error::NoActiveSessionError.new            unless active_session?
  raise Error::InvalidExportFormatError.new format unless %w[printer text xml].include?(format.downcase)

  resp = call_rpc('Export', {
      session: self.active_session,
      format:  format
  })

  return resp.split(';') if format == 'text'
  return resp
end
get(key) click to toggle source

Gets the value of a parameter

@param key [String] setting to read @return [String] value of setting @raise [Error::NoActiveSessionError] if no active session @raise [Error::InvalidPrintSettingError] on invalid key

# File lib/evolis/premium_sdk/setting.rb, line 74
def get(key)
  raise Error::NoActiveSessionError.new         unless active_session?
  raise Error::InvalidPrintSettingError.new key unless valid_settings?(key, true)

  call_rpc('Get', {
      session: self.active_session,
      data:    key
  })
end
import(format = 'printer', data = nil) click to toggle source

Imports parameters

@param format [String] format to import settings, `printer`, `default` or `xml` @param data [nil, String] base64 encoded xml on format `xml` @return [true] on successful import @raise [Error::NoActiveSessionError] if no active session @raise [Error::InvalidImportFormatError] when format is invalid @raise [Error::Base64FormatError] on format `xml` and invalid base64 data

# File lib/evolis/premium_sdk/setting.rb, line 54
def import(format = 'printer', data = nil)
  raise Error::NoActiveSessionError.new            unless active_session?
  raise Error::InvalidImportFormatError.new format unless %w[printer default xml].include?(format.downcase)
  raise Error::Base64FormatError.new data          if format == 'xml'

  params = {
      session: self.active_session,
      format:  format
  }
  params[:data] = data if format == 'xml'

  call_rpc('Import', params)
end
set(key, value) click to toggle source

Edits the value of a parameter

@param key [String] setting to set @param value [String] value for setting @return [true] if set successful @raise [Error::NoActiveSessionError] if no active session @raise [Error::InvalidPrintSettingError] if key=value pair does not validate

# File lib/evolis/premium_sdk/setting.rb, line 91
def set(key, value)
  raise Error::NoActiveSessionError.new unless active_session?
  raise Error::InvalidPrintSettingError.new key unless valid_settings?("#{key}=#{value}")

  call_rpc('Set', {
      session: self.active_session,
      data:    "#{key}=#{value}"
  })
end