Class: DeployGate::Session

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

Defined Under Namespace

Modules: ENVKey Classes: LoginError

Constant Summary collapse

@@login =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeployGate::Session



16
17
18
# File 'lib/deploygate/session.rb', line 16

def initialize
  load_setting
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/deploygate/session.rb', line 6

def name
  @name
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/deploygate/session.rb', line 6

def token
  @token
end

Class Method Details

.deletevoid

This method returns an undefined value.



54
55
56
57
# File 'lib/deploygate/session.rb', line 54

def self.delete
  save('', '') # delete config values
  @@login = false
end

.login(email, password) ⇒ void

This method returns an undefined value.

Parameters:

  • email (String)
  • password (String)

Raises:



32
33
34
35
36
37
38
39
40
# File 'lib/deploygate/session.rb', line 32

def self.(email, password)
  data = API::V1::Session.(email, password)
  raise LoginError, data[:message] if data[:error]

  name = data[:name]
  token = data[:token]
  save(name, token)
  @@login = true
end

.save(name, token) ⇒ void

This method returns an undefined value.

Parameters:

  • name (String)
  • token (String)


45
46
47
48
49
50
51
# File 'lib/deploygate/session.rb', line 45

def self.save(name, token)
  settings = {
      :name => name,
      :token => token
  }
  Config::Credential.write(settings)
end

Instance Method Details

#login?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/deploygate/session.rb', line 21

def login?
  @@login = @@login.nil? ? API::V1::Session.check(@name, @token) : @@login
end

#show_login_userObject



25
26
27
# File 'lib/deploygate/session.rb', line 25

def 
  API::V1::Session.show(@token)
end