Class: Bugzilla::User

Inherits:
APITemplate show all
Defined in:
lib/bugzilla/user.rb

Overview

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.

Instance Method Summary collapse

Methods inherited from APITemplate

#initialize, #method_missing

Methods inherited from Skeleton

#initialize, #method_missing

Constructor Details

This class inherits a constructor from Bugzilla::APITemplate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bugzilla::APITemplate

Instance Method Details

#get_userinfo(user) ⇒ Object

Bugzilla::User#get_userinfo(params)



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/bugzilla/user.rb', line 97

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) ⇒ Object

Bugzilla::User#session(user, password)

Keeps the bugzilla session during doing something in the block.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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
     ({'login'=>user, 'token'=>val}) or val = nil
  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'=>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