class Bugzilla::User

Bugzilla::User

Bugzilla::User class is to access the Bugzilla::WebService::User API that allows you to create User Accounts and log in/out using an existing account.

Public Instance Methods

get_userinfo(user) click to toggle source

#get_userinfo

# File lib/bugzilla/user.rb, line 94
def get_userinfo(user)
  p = {}
  ids = []
  names = []

  if user.kind_of?(Array) then
    user.each do |u|
      names << u if u.kind_of?(String)
      id << u if u.kind_of?(Integer)
    end
  elsif user.kind_of?(String) then
    names << user
  elsif user.kind_of?(Integer) then
    ids << user
  else
    raise ArgumentError, sprintf("Unknown type of arguments: %s", user.class)
  end

  result = get({'ids'=>ids, 'names'=>names})

  result['users']
end
session(user, password) { || ... } click to toggle source

#session(user, password)

Keeps the bugzilla session during doing something in the block.

# File lib/bugzilla/user.rb, line 45
def session(user, password)
  r = check_version('4.4.3')

  if r[0] then
    key = :token
    fname = File.join(ENV['HOME'], '.ruby-bugzilla-token.yml')
  else
    key = :cookie
    fname = File.join(ENV['HOME'], '.ruby-bugzilla-cookie.yml')
  end
  host = @iface.instance_variable_get(:@xmlrpc).instance_variable_get(:@host)
  val = nil

  if File.exist?(fname) && File.lstat(fname).mode & 0600 == 0600 then
    conf = YAML.load(File.open(fname).read)
    val = conf[host]
  else
    conf = {}
  end
  if !val.nil? then
    if key == :token then
      @iface.token = val
    else
      @iface.cookie = val
    end
    yield
  elsif user.nil? || password.nil? then
    yield
    return
  else
    login({'login'=>user, 'password'=>password, 'remember'=>true})
    yield
  end
  if key == :token then
    conf[host] = @iface.token
  else
    conf[host] = @iface.cookie
  end
  File.open(fname, 'w') {|f| f.chmod(0600); f.write(conf.to_yaml)}

  return key
end

Protected Instance Methods

__create(cmd, *args) click to toggle source
# File lib/bugzilla/user.rb, line 158
def __create(cmd, *args)
  # FIXME
end
__offer_account_by_email(cmd, *args) click to toggle source
# File lib/bugzilla/user.rb, line 154
def __offer_account_by_email(cmd, *args)
  # FIXME
end
__update(cmd, *args) click to toggle source
# File lib/bugzilla/user.rb, line 162
def __update(cmd, *args)
  # FIXME
end
_get(cmd, *args) click to toggle source
# File lib/bugzilla/user.rb, line 166
def _get(cmd, *args)
  raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)

  requires_version(cmd, 3.4)
  res = @iface.call(cmd, args[0])
  # FIXME
end
_login(cmd, *args) click to toggle source

Bugzilla::User#login(params)

Raw Bugzilla API to log into Bugzilla.

See www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/User.html

Bugzilla::User#logout

Raw Bugzilla API to log out the user.

See www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/User.html

# File lib/bugzilla/user.rb, line 139
def _login(cmd, *args)
  raise ArgumentError, "Invalid parameters" unless args[0].kind_of?(Hash)

  res = @iface.call(cmd,args[0])
  unless res['token'].nil? then
    @iface.token = res['token']
  end

  return res
end
_logout(cmd, *args) click to toggle source
# File lib/bugzilla/user.rb, line 150
def _logout(cmd, *args)
  @iface.call(cmd)
end