Module: MyShows::Auth
- Included in:
- CLI
- Defined in:
- lib/my_shows/auth.rb
Instance Method Summary collapse
- #ask ⇒ Object
- #ask_for_and_save_credentials ⇒ Object
- #ask_for_credentials ⇒ Object
- #ask_for_password ⇒ Object
- #check ⇒ Object
- #credentials ⇒ Object
- #delete_credentials ⇒ Object
- #echo_off ⇒ Object
- #echo_on ⇒ Object
- #host ⇒ Object
- #netrc ⇒ Object
- #read_credentials ⇒ Object
- #with_tty(&block) ⇒ Object
- #write_credentials ⇒ Object
Instance Method Details
#ask ⇒ Object
3 4 5 |
# File 'lib/my_shows/auth.rb', line 3 def ask $stdin.gets.to_s.strip end |
#ask_for_and_save_credentials ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/my_shows/auth.rb', line 38 def ask_for_and_save_credentials begin @credentials = ask_for_credentials write_credentials check rescue Exception => e delete_credentials raise e end @credentials end |
#ask_for_credentials ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/my_shows/auth.rb', line 61 def ask_for_credentials puts "Enter your Heroku credentials." print "Email: " user = ask print "Password (typing will be hidden): " password = ask_for_password [user, password] end |
#ask_for_password ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/my_shows/auth.rb', line 73 def ask_for_password echo_off password = ask puts echo_on return password end |
#check ⇒ Object
85 86 87 88 |
# File 'lib/my_shows/auth.rb', line 85 def check client = SidereelClient.new *self.credentials client.tracked_tv_shows end |
#credentials ⇒ Object
30 31 32 |
# File 'lib/my_shows/auth.rb', line 30 def credentials @credentials ||= (read_credentials || ask_for_and_save_credentials) end |
#delete_credentials ⇒ Object
50 51 52 53 54 |
# File 'lib/my_shows/auth.rb', line 50 def delete_credentials netrc.delete(host) netrc.save @credentials = nil end |
#echo_off ⇒ Object
14 15 16 17 18 |
# File 'lib/my_shows/auth.rb', line 14 def echo_off with_tty do system "stty -echo" end end |
#echo_on ⇒ Object
20 21 22 23 24 |
# File 'lib/my_shows/auth.rb', line 20 def echo_on with_tty do system "stty echo" end end |
#host ⇒ Object
81 82 83 |
# File 'lib/my_shows/auth.rb', line 81 def host 'sidereel.com' end |
#netrc ⇒ Object
26 27 28 |
# File 'lib/my_shows/auth.rb', line 26 def netrc @netrc ||= Netrc.read end |
#read_credentials ⇒ Object
34 35 36 |
# File 'lib/my_shows/auth.rb', line 34 def read_credentials netrc[host] end |
#with_tty(&block) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/my_shows/auth.rb', line 7 def with_tty(&block) return unless $stdin.isatty yield rescue logger.warn 'with_tty faild' end |
#write_credentials ⇒ Object
56 57 58 59 |
# File 'lib/my_shows/auth.rb', line 56 def write_credentials netrc[host] = self.credentials netrc.save end |