Class: DTK::Client::Session

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/core.rb

Overview

Session Singleton we will use to hold connection instance, just a singleton wrapper. During shell input it will be needed only once, so singleton was obvious solution.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



283
284
285
# File 'lib/core.rb', line 283

def initialize
  @conn = DTK::Client::Conn.new
end

Instance Attribute Details

#connObject

Returns the value of attribute conn.



281
282
283
# File 'lib/core.rb', line 281

def conn
  @conn
end

Class Method Details

.connection_usernameObject



291
292
293
# File 'lib/core.rb', line 291

def self.connection_username
  Session.instance.conn.get_username
end

.get_connectionObject



287
288
289
# File 'lib/core.rb', line 287

def self.get_connection
  Session.instance.conn
end

.logoutObject



301
302
303
304
# File 'lib/core.rb', line 301

def self.logout
  # from this point @conn is not valid, since there are no cookies set
  Session.instance.conn.logout
end

.post(route, body, opts = {}) ⇒ Object

opts can have key

:command_class


308
309
310
311
312
# File 'lib/core.rb', line 308

def self.post(route, body, opts = {})
  command_class = opts[:command_class] || Class
  conn = Session.instance.conn
  conn.post(command_class, conn.rest_url(route), body)
end

.re_initializeObject



295
296
297
298
299
# File 'lib/core.rb', line 295

def self.re_initialize
  Session.instance.conn = nil
  Session.instance.conn = DTK::Client::Conn.new
  Session.instance.conn.cookies
end