class Equitrac::Connection

The Equitrac server definition, handling communication with the server. @since 0.1.0

@note If the password is define in the object, it will be included automatically into the options. @note You can also use environment variables to initialize your server.

@!attribute [r] eqcmd_path

@return [String] The path where Equitrac utilities is installed

@!attribute [r] service_name

@return [String] The name of the Equitrac service.

Attributes

eqcmd_path[R]
service_name[R]

Public Class Methods

new( host=ENV['EQUITRAC_HOST'], user=ENV['EQUITRAC_USER'], service_name=ENV['EQUITRAC_SERVICE_NAME'], host_password=ENV['EQUITRAC_HOST_PASSWORD'], eqcmd_path='C:\Program Files\Equitrac\Express\Tools\EQCmd.exe' ) click to toggle source

@note Host, User and Service name are required @param host [String] The server hostname. @param user [String] The user that ssh gonna use. @param service_name [String] The name of the Equitrac service. @param host_password [String] The password used for authentification. @param eqcmd_path [String] The path where Equitrac utilities is installed

# File lib/equitrac/connection.rb, line 23
def initialize(
    host=ENV['EQUITRAC_HOST'],
    user=ENV['EQUITRAC_USER'],
    service_name=ENV['EQUITRAC_SERVICE_NAME'],
    host_password=ENV['EQUITRAC_HOST_PASSWORD'],
    eqcmd_path='C:\Program Files\Equitrac\Express\Tools\EQCmd.exe'
  )

  raise ArgumentError, 'host is missing' if host.nil? or host.empty?
  raise ArgumentError, 'user is missing' if user.nil? or user.empty?
  raise ArgumentError, 'service_name is missing' if service_name.nil? or service_name.empty?

  @host = host
  @user = user
  @host_password = host_password
  @service_name = service_name
  @eqcmd_path = eqcmd_path
end

Public Instance Methods

execute(command, options={}) click to toggle source

Execute a command on the remote server via SSH.

@param command [String] the command that need to be executed. @param options [Hash] options for ssh. @return [String] the result from the ssh command

# File lib/equitrac/connection.rb, line 47
def execute(command, options={})
  options[:password] = @host_password if @host_password
  session = Net::SSH.start(@host, @user, options)

  result = session.exec! "#{self.eqcmd_path} -s#{self.service_name} #{command}"

  session.close

  return clean_up_output(result)
end

Private Instance Methods

clean_up_output(string) click to toggle source

Clean return from ssh execution

@param string [String] the string that need to be clean @return [String] the clean string

# File lib/equitrac/connection.rb, line 64
def clean_up_output(string)
  string.gsub("\u0000",'').gsub(/\\/,'')
end