Class: Gitpic::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/gitpic/auth.rb

Class Method Summary collapse

Class Method Details

.login(email, password) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitpic/auth.rb', line 3

def self.(email, password)
  token = RestClient.post( "#{Gitpic::HOST}/api/tokens", {
    :email => email,
    :password => password
  })

  return false if token.strip == ''

  config_dir = File.expand_path('~/.gitpic')
  Dir.mkdir config_dir unless Dir.exists?(config_dir)

  token_path = config_dir + "/token"
  File.delete token_path if File.exists? token_path

  token_file = File.new(token_path, "w+")
  token_file.write(token)
  token_file.write("\n")
  token_file.close
  true
end

.read_tokenObject



24
25
26
27
28
29
30
31
32
# File 'lib/gitpic/auth.rb', line 24

def self.read_token
  token_path = File.expand_path("~/.gitpic/token")
  if File.exists?(token_path)
    File.new(token_path).read
  else
    puts "Please login with `gitpic login` before attempting to upload"
    false
  end
end