Class: Ubcbooker::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ubcbooker/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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



10
11
12
13
14
# File 'lib/ubcbooker/config.rb', line 10

def initialize
  @keyring = Keyring.new
  @win_username = ""
  @win_password = ""
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/ubcbooker/config.rb', line 3

def 
  @account
end

Instance Method Details

#askObject



16
17
18
19
20
21
22
23
24
# 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?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/ubcbooker/config.rb', line 76

def defined?
  return !!(get_username && get_password)
end

#delete_credentialsObject

Delete stored user credentials Used in specs



50
51
52
53
54
55
56
57
58
# 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_passwordObject



68
69
70
71
72
73
74
# 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_usernameObject



60
61
62
63
64
65
66
# 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?Boolean

True if user is on windows platform

Returns:

  • (Boolean)


44
45
46
# File 'lib/ubcbooker/config.rb', line 44

def is_windows?
  return Gem.win_platform?
end


36
37
38
39
40
41
# File 'lib/ubcbooker/config.rb', line 36

def print_supported_departments
  puts "Supported department options in #{Ubcbooker::VERSION}:"
  BOOKING_URL.keys.each do |d|
    puts "    -  #{d}"
  end
end

#save_credentials(username, password) ⇒ Object



26
27
28
29
30
31
32
33
34
# 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