Class: Evolis::PremiumSdk::Setting

Inherits:
SdkBase
  • Object
show all
Defined in:
lib/evolis/premium_sdk/setting.rb

Constant Summary

Constants inherited from SdkBase

Evolis::PremiumSdk::SdkBase::SETTINGS

Instance Attribute Summary

Attributes inherited from SdkBase

#active_session

Instance Method Summary collapse

Methods inherited from SdkBase

#active_session?, #call_rpc, #list_settings, #print_setting, #request, #response, #sanitize_parameters, #valid_base64?, #valid_settings?

Constructor Details

#initialize(host, port) ⇒ Setting

Initializes the class and sets SDK host and port

Parameters:

  • host (String)

    host or IP for SDK

  • port (String, Fixnum)

    port for SDK



11
12
13
# File 'lib/evolis/premium_sdk/setting.rb', line 11

def initialize(host, port)
  super(host, port, 'SETTING')
end

Instance Method Details

#begin(device) ⇒ String

Starts a configuration session

Parameters:

  • device (String)

    printer name

Returns:

  • (String)

    session id



19
20
21
22
23
# File 'lib/evolis/premium_sdk/setting.rb', line 19

def begin(device)
  self.active_session = call_rpc('Begin', {
      device: device
  })
end

#endtrue

Ends the session

Returns:

  • (true)

    if ended session

Raises:



105
106
107
108
109
110
111
# 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') ⇒ true, ...

Exports parameters

Parameters:

  • format (String) (defaults to: 'printer')

    format to export settings, ‘printer`, `text` or `xml`

Returns:

  • (true)

    on success with format ‘printer`

  • (Array)

    of setting=value pairs on format ‘text`

  • (String)

    base64 encoded xml

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ String

Gets the value of a parameter

Parameters:

  • key (String)

    setting to read

Returns:

  • (String)

    value of setting

Raises:



74
75
76
77
78
79
80
81
82
# 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) ⇒ true

Imports parameters

Parameters:

  • format (String) (defaults to: 'printer')

    format to import settings, ‘printer`, `default` or `xml`

  • data (nil, String) (defaults to: nil)

    base64 encoded xml on format ‘xml`

Returns:

  • (true)

    on successful import

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
# 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) ⇒ true

Edits the value of a parameter

Parameters:

  • key (String)

    setting to set

  • value (String)

    value for setting

Returns:

  • (true)

    if set successful

Raises:



91
92
93
94
95
96
97
98
99
# 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