class Bugzilla::User
rdoc
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
rdoc
Bugzilla::User#get_userinfo(params)
¶ ↑
# File lib/bugzilla/user.rb, line 78 def get_userinfo(user) p = {} ids = [] names = [] if user.is_a?(Array) user.each do |u| names << u if u.is_a?(String) id << u if u.is_a?(Integer) end elsif user.is_a?(String) names << user elsif user.is_a?(Integer) ids << user else raise ArgumentError, format('Unknown type of arguments: %s', user.class) end result = get('ids' => ids, 'names' => names) result['users'] end
session(user, password) { || ... }
click to toggle source
rdoc
Bugzilla::User#session
(user, password)¶ ↑
Keeps the bugzilla session during doing something in the block.
# File lib/bugzilla/user.rb, line 41 def session(user, password) key, fname = authentication_method # TODO # make those variables available host = @iface.instance_variable_get(:@xmlrpc).instance_variable_get(:@host) conf = load_authentication_token(fname) val = conf.fetch(host, nil) if !val.nil? if key == :token @iface.token = val else @iface.cookie = val end yield elsif user.nil? || password.nil? yield return else login('login' => user, 'password' => password, 'remember' => true) yield end conf[host] = @iface.send(key) if %i[token cookie].include? key save_authentication_token(fname, conf) key end
Protected Instance Methods
__create(cmd, *args)
click to toggle source
# File lib/bugzilla/user.rb, line 166 def __create(cmd, *args) # FIXME end
__offer_account_by_email(cmd, *args)
click to toggle source
# File lib/bugzilla/user.rb, line 162 def __offer_account_by_email(cmd, *args) # FIXME end
__update(cmd, *args)
click to toggle source
# File lib/bugzilla/user.rb, line 170 def __update(cmd, *args) # FIXME end
_get(cmd, *args)
click to toggle source
# File lib/bugzilla/user.rb, line 174 def _get(cmd, *args) raise ArgumentError, 'Invalid parameters' unless args[0].is_a?(Hash) requires_version(cmd, 3.4) res = @iface.call(cmd, args[0]) # FIXME end
_login(cmd, *args)
click to toggle source
# File lib/bugzilla/user.rb, line 149 def _login(cmd, *args) raise ArgumentError, 'Invalid parameters' unless args[0].is_a?(Hash) res = @iface.call(cmd, args[0]) @iface.token = res['token'] unless res['token'].nil? res end
_logout(cmd, *_args)
click to toggle source
# File lib/bugzilla/user.rb, line 158 def _logout(cmd, *_args) @iface.call(cmd) end
authentication_method()
click to toggle source
it returns an array with authentication type and the name of the storage
# File lib/bugzilla/user.rb, line 140 def authentication_method # if version supported, use token, otherwise cookie if is_token_supported? [:token, File.join(ENV['HOME'], '.ruby-bugzilla-token.yml')] else [:cookie, File.join(ENV['HOME'], '.ruby-bugzilla-cookie.yml')] end end
is_token_supported?()
click to toggle source
# File lib/bugzilla/user.rb, line 133 def is_token_supported? check_version('4.4.3')[0] == true rescue StandardError false end
load_authentication_token(fname)
click to toggle source
rdoc
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 121 def load_authentication_token(fname) if File.exist?(fname) && File.lstat(fname).mode & 0o600 == 0o600 YAML.safe_load(File.open(fname).read) else {} end end
save_authentication_token(fname, conf)
click to toggle source
# File lib/bugzilla/user.rb, line 129 def save_authentication_token(fname, conf) File.open(fname, 'w') { |f| f.chmod(0o600); f.write(conf.to_yaml) } end