Class: OEHClient::Meta::Session

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



3
4
5
# File 'lib/oehclient/meta/session.rb', line 3

def cookies
  @cookies
end

#spaceObject

Returns the value of attribute space.



3
4
5
# File 'lib/oehclient/meta/session.rb', line 3

def space
  @space
end

Class Method Details

.attach(space) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/oehclient/meta/session.rb', line 5

def self.attach(space)
  # post the login request
  response = OEHClient.post(space., nil, :payload => space.meta_credentials)
  # create a new session object
  session_instance = OEHClient::Meta::Session.new()
  # assign the space object
  session_instance.space     = space
  # store the cookies if they are returned in the response
  session_instance.cookies   = response[:cookies]  if (response.has_key?(:cookies))
  # return the session instance
  session_instance
end

Instance Method Details

#detachObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/oehclient/meta/session.rb', line 18

def detach()
  # construct a header object, merging cookies (if present) wit the default JSON header
  header = Hash.new
  header.merge!(:cookies => @cookies)                unless (@cookies.blank?)
  header.merge!(OEHClient::Helper::Request.default_JSON_header)
  # post the logout request
  OEHClient.post(@space.logout_url, nil, :header => header)
  # remove the cookies if the logout is posted successfully
  @cookies = nil 
end

#workspace(site_key) ⇒ Object

retrieve the workspace meta-data object from the thinstance in realtime



30
31
32
33
# File 'lib/oehclient/meta/session.rb', line 30

def workspace(site_key)
  # get the workspace object using the site key, the host value, and the exisitng cookies 
  OEHClient::Meta::Workspace.find_by_key(self, site_key)
end