Class: DeployGate::API::V1::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/api/v1/session.rb

Constant Summary collapse

ENDPOINT =
'/sessions'

Class Method Summary collapse

Class Method Details

.check(name, token) ⇒ Boolean

Parameters:

  • name (String)
  • token (String)

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/deploygate/api/v1/session.rb', line 21

def check(name, token)
  results = show(token)
  return false if results.nil?

  name == results['name']
end

.login(email, password) ⇒ Hash

Parameters:

  • email (String)
  • password (String)

Returns:

  • (Hash)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/deploygate/api/v1/session.rb', line 31

def (email, password)
  res = Base.new().post(ENDPOINT, {:email => email, :password => password})

   = {
      :error => res['error'],
      :message => res['because']
  }

  results = res['results']
  unless results.nil?
    .merge!({
                             :name => results['name'],
                             :token => results['api_token']
                         })
  end

  
end

.show(token) ⇒ Hash

Parameters:

  • token (String)

Returns:

  • (Hash)


11
12
13
14
15
16
# File 'lib/deploygate/api/v1/session.rb', line 11

def show(token)
  res = Base.new(token).get(ENDPOINT + '/user', {})
  return nil if res['error']

  res['results']
end