Class: Ubcbooker::Config
- Inherits:
-
Object
- Object
- Ubcbooker::Config
- Defined in:
- lib/ubcbooker/config.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
Instance Method Summary collapse
- #ask ⇒ Object
- #defined? ⇒ Boolean
-
#delete_credentials ⇒ Object
Delete stored user credentials Used in specs.
- #get_password ⇒ Object
- #get_username ⇒ Object
-
#initialize ⇒ Config
constructor
We use system keyring for storing cwl credentials askubuntu.com/questions/32164/what-does-a-keyring-do.
-
#is_windows? ⇒ Boolean
True if user is on windows platform.
- #print_supported_departments ⇒ Object
- #save_credentials(username, password) ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/ubcbooker/config.rb', line 3 def account @account end |
Instance Method Details
#ask ⇒ Object
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
76 77 78 |
# File 'lib/ubcbooker/config.rb', line 76 def defined? return !!(get_username && get_password) end |
#delete_credentials ⇒ Object
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_password ⇒ Object
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_username ⇒ Object
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
44 45 46 |
# File 'lib/ubcbooker/config.rb', line 44 def is_windows? return Gem.win_platform? end |
#print_supported_departments ⇒ Object
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 |