Class: DotPlan::Command::Auth

Inherits:
Object
  • Object
show all
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(options)
  raise "Must provide a username".red unless options[:username]
  raise "Must provide a password".red  unless options[:password]
  begin
    response = RestClient.get("#{DotPlan::DOTPLAN_URL}/user/#{options[:username]}/auth", :Password => options[:password])
  rescue => e
    response = JSON.parse(e.response)
    raise response["error"].red
  end
  credentials = JSON.parse(response.body)
  credentials
end

.loginObject



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.
  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)
  
end