Class: Dx::Auth

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

Class Method Summary collapse

Class Method Details

.login(email, password) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dx/auth.rb', line 8

def self.(email,password)
  payload = {
    user: {
      email: email,
      password: password
    }
  }
  http = Curl.post('http://localhost:5000/login.json', payload.to_json ) do |curl|
    curl.headers['Content-Type']  = 'application/json'
    curl.headers['Accept']        = '*/*'
  end
  return parse(email,JSON.parse(http.body_str))
end

.parse(email, auth) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dx/auth.rb', line 22

def self.parse(email,auth)
  begin
    if auth['email'] == email && auth['token']
      open("#{ENV['HOME']}/deemx.token", 'w') { |f| f << auth['token'] }
      return true
    else
      return false
    end
  rescue JSON::ParserError => e
    return false
  end
end