class Evolis::PremiumSdk::SdkBase
Constants
- SETTINGS
Settings and their values allowed to be used when getting and setting settings for print
Attributes
@return [String] returns the active session
Public Class Methods
Initalizes the class, sets default options
@param host [String] host or ip to Premium SDK API @param port [String, Fixnum] port to Premium SDK API @param service [String] servicename, used only internally (e.g. CMD or PRINT)
# File lib/evolis/premium_sdk/sdk_base.rb, line 14 def initialize(host, port, service) @rpc = RpcClient.new(host, port) @service = service end
Public Instance Methods
Checks if there is an active session @return [true, false] true if exist, false if not
# File lib/evolis/premium_sdk/sdk_base.rb, line 249 def active_session? return false unless self.active_session return false if self.active_session == nil return false unless self.active_session.is_a?(String) return false if self.active_session.empty? return true end
Makes the call to the API and returns results
@param method [String] method name for the service @param args [String] arguments and parameters to send to service @return [String] returns result parameter from the response @return [true] if result is “OK”
# File lib/evolis/premium_sdk/sdk_base.rb, line 25 def call_rpc(method, args) method = sanitize_parameters(method) args = sanitize_parameters(args) resp = @rpc.call("#{@service}.#{method}", args) return true if resp == 'OK' return resp end
@return [Hash] of settings with descriptions
# File lib/evolis/premium_sdk/sdk_base.rb, line 232 def list_settings return SETTINGS.map{ |key, value| [key, value[:description]] }.to_h end
@return [String] string of description or false if setting does not exist @raise [Error::InvalidPrintSettingError] on invalid print setting
# File lib/evolis/premium_sdk/sdk_base.rb, line 226 def print_setting(setting) return SETTINGS[setting.to_sym][:description] if SETTINGS.has_key?(setting.to_sym) raise Error::InvalidPrintSettingError.new setting end
Method to lookup the full request @return [Hash] full json request @return (nil) before first request
# File lib/evolis/premium_sdk/sdk_base.rb, line 44 def request @rpc.request end
Method to lookup the full response @return [Hash] full json response @return [nil] before first response
# File lib/evolis/premium_sdk/sdk_base.rb, line 37 def response @rpc.response end
Sanitizes parameters so they're not anything other than a String
@param param [Any type] parameters to be sanitized @return [Hash, Array, String] Hash and Array get sanitized and returned as Hash and Array,
everything else becomes a String
# File lib/evolis/premium_sdk/sdk_base.rb, line 263 def sanitize_parameters(param) return param.map { |p| String(p) } if param.is_a?(Array) return param.map { |k, v| [String(k), String(v)] }.to_h if param.is_a?(Hash) return String(param) end
Basic checking for valid base64 string, as used in the SDK
@param string [String] the base64 encoded data @return [true, false] true if valid base64 string, false if not
# File lib/evolis/premium_sdk/sdk_base.rb, line 240 def valid_base64?(string) return false unless string.is_a?(String) return false unless string.start_with?('base64:') return true end
Checks if settings supplied are valid
@param settings [String, Array] setting and value,
as "setting=value;setting2=value2" or ["setting=value","setting2=value2"]
@param key_only [true, false] used for checking if only setting without value. Set to true for setting only. @return [true, false] true if valid settings, false if not
# File lib/evolis/premium_sdk/sdk_base.rb, line 198 def valid_settings?(settings, key_only = false) settings = settings.split(';') if settings.include?(';') settings = [settings] unless settings.is_a?(Array) settings.each do |pair| if key_only setting = pair else return false unless pair.include?('=') setting, value = pair.split('=') end return false unless SETTINGS.has_key?(setting.to_sym) unless key_only return false if !value return false if value.is_a?(String) && value.empty? return false if SETTINGS[setting.to_sym][:validation].is_a?(Array) && !SETTINGS[setting.to_sym][:validation].include?(value) return false if SETTINGS[setting.to_sym][:validation].is_a?(Class) && !value.is_a?(SETTINGS[setting.to_sym][:validation]) return false if SETTINGS[setting.to_sym][:validation].is_a?(Regexp) && value.is_a?(String) && value !~ SETTINGS[setting.to_sym][:validation] end return true end end