class Mamba::Client

Attributes

accounting[R]
calls[R]

Public Class Methods

new(server,user=nil,password=nil,accounting=false,timeout=30) click to toggle source
# File lib/mamba/client.rb, line 7
def initialize(server,user=nil,password=nil,accounting=false,timeout=30)
  @client = XMLRPC::Client.new2("https://#{server}/rpc/api",nil,timeout)

  if accounting
    @accounting = true
    @calls = Hash.new(0)
  end

  login(user,password) if ! (user.nil? or password.nil?)
end

Public Instance Methods

call(method,*params) click to toggle source
# File lib/mamba/client.rb, line 26
def call(method,*params)
  _call(method,@key,*params)
end
login(user,password) click to toggle source
# File lib/mamba/client.rb, line 18
def login(user,password)
  @key = @client.call('auth.login',user,password)
  _account('auth.login')

  # return true if we were successful
  true
end
logout() click to toggle source
# File lib/mamba/client.rb, line 30
def logout
  _call('auth.logout',@key)
end

Private Instance Methods

_account(call) click to toggle source
# File lib/mamba/client.rb, line 40
def _account(call)
  @calls[call.to_sym]+=1 if @accounting

  # always return true
  return true
end
_call(*params) click to toggle source
# File lib/mamba/client.rb, line 35
def _call(*params)
  _account(params[0])
  @client.call(*params)
end