class Ubcbooker::Config

Attributes

account[RW]

Public Class Methods

new() click to toggle source

We use system keyring for storing cwl credentials askubuntu.com/questions/32164/what-does-a-keyring-do

since the keyring gem doesn't suppot Windows, we ask for cred each time if the user is on OSX or Linux, username and password will be stored in keyring

# File lib/ubcbooker/config.rb, line 10
def initialize
  @keyring = Keyring.new
  @win_username = ""
  @win_password = ""
end

Public Instance Methods

ask() click to toggle source
# File lib/ubcbooker/config.rb, line 16
def ask
  print "Your CWL username: "
  username = gets.chomp
  print "Your CWL password: "
  # Hide the password input
  password = STDIN.noecho(&:gets).chomp
  save_credentials(username, password)
  puts
end
defined?() click to toggle source
# File lib/ubcbooker/config.rb, line 76
def defined?
  return !!(get_username && get_password)
end
delete_credentials() click to toggle source

Delete stored user credentials Used in specs

# File lib/ubcbooker/config.rb, line 50
def delete_credentials
  if is_windows?
    @win_username = ""
    @win_password = ""
  else
    @keyring.delete_password("ubcbooker", "username")
    @keyring.delete_password("ubcbooker", "password")
  end
end
get_password() click to toggle source
# File lib/ubcbooker/config.rb, line 68
def get_password
  if is_windows?
    return @win_pasword
  else
    return @keyring.get_password("ubcbooker", "password")
  end
end
get_username() click to toggle source
# File lib/ubcbooker/config.rb, line 60
def get_username
  if is_windows?
    return @win_username
  else
    return @keyring.get_password("ubcbooker", "username")
  end
end
is_windows?() click to toggle source

True if user is on windows platform

# File lib/ubcbooker/config.rb, line 44
def is_windows?
  return Gem.win_platform?
end
print_supported_departments() click to toggle source
save_credentials(username, password) click to toggle source
# File lib/ubcbooker/config.rb, line 26
def save_credentials(username, password)
  if is_windows?
    @win_username = username
    @win_pasword = password
  else
    @keyring.set_password("ubcbooker", "username", username)
    @keyring.set_password("ubcbooker", "password", password)
  end
end