Class: ConstantContact::Auth::Session

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Create and initialize the session



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/constantcontact/auth/session_data_store.rb', line 13

def initialize
  cgi = CGI.new('html4')

  # We make sure to delete an old session if one exists,
  # not just to free resources, but to prevent the session
  # from being maliciously hijacked later on.
  begin
    @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => false)
    @session.delete
  rescue ArgumentError # if no old session
  end
  @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => true)
  @session['datastore'] = {}
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session



10
11
12
# File 'lib/constantcontact/auth/session_data_store.rb', line 10

def session
  @session
end

Instance Method Details

#add_user(username, params) ⇒ Object

Add a new user to the data store

Parameters:

  • username (String)
    • Constant Contact username

  • params (Hash)
    • additional parameters

Returns:



32
33
34
# File 'lib/constantcontact/auth/session_data_store.rb', line 32

def add_user(username, params)
  @session['datastore'][username] = params
end

#closeObject

Close current session

Returns:



62
63
64
# File 'lib/constantcontact/auth/session_data_store.rb', line 62

def close
  @session.close
end

#delete_user(username) ⇒ Object

Delete an existing user from the data store

Parameters:

  • username (String)
    • Constant Contact username

Returns:



56
57
58
# File 'lib/constantcontact/auth/session_data_store.rb', line 56

def delete_user(username)
  @session['datastore'][username] = nil
end

#get_user(username) ⇒ String

Get an existing user from the data store

Parameters:

  • username (String)
    • Constant Contact username key

Returns:

  • (String)

    The username value



39
40
41
# File 'lib/constantcontact/auth/session_data_store.rb', line 39

def get_user(username)
  @session['datastore'].has_key?(username) ? @session['datastore'][username] : false
end

#update_user(username, params) ⇒ Object

Update an existing user in the data store

Parameters:

  • username (String)
    • Constant Contact username

  • params (Hash)
    • additional parameters

Returns:



47
48
49
50
51
# File 'lib/constantcontact/auth/session_data_store.rb', line 47

def update_user(username, params)
  if @session['datastore'].has_key?(username)
    @session['datastore'][username] = params
  end
end