Class: DotPlan::Command::Auth
- Inherits:
-
Object
- Object
- DotPlan::Command::Auth
- Defined in:
- lib/dotplan/command/auth.rb
Class Method Summary collapse
Class Method Details
.authenticate(options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dotplan/command/auth.rb', line 31 def self.authenticate() raise "Must provide a username".red unless [:username] raise "Must provide a password".red unless [:password] begin response = RestClient.get("#{DotPlan::DOTPLAN_URL}/user/#{[:username]}/auth", :Password => [:password]) rescue => e response = JSON.parse(e.response) raise response["error"].red end credentials = JSON.parse(response.body) credentials end |
.login ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dotplan/command/auth.rb', line 11 def self.login print "Username: " username = $stdin.gets.chomp print "Password: " system "stty -echo" password = $stdin.gets.chomp system "stty echo" print "\n" begin credentials = authenticate(:username => username, :password => password) write_credentials(credentials) puts "Saved to #{DotPlan::CREDENTIALS_PATH}.".green rescue => e puts e end end |
.run(*args) ⇒ Object
7 8 9 |
# File 'lib/dotplan/command/auth.rb', line 7 def self.run(*args) login end |