Class: AlexaRubykit::Session

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

Overview

Handles the session object in request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Session

Returns a new instance of Session.

Raises:

  • (ArgumentError)

5
6
7
8
9
10
11
# File 'lib/alexa_rubykit/session.rb', line 5

def initialize (session)
  raise ArgumentError, 'Invalid Session' if session.nil? || session['new'].nil? || session['sessionId'].nil?
  @new = session['new']
  @session_id = session['sessionId']
  session['attributes'].nil? ? @attributes = Hash.new  : @attributes = session['attributes']
  @user = session['user']
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes


4
5
6
# File 'lib/alexa_rubykit/session.rb', line 4

def attributes
  @attributes
end

#newObject

Returns the value of attribute new


4
5
6
# File 'lib/alexa_rubykit/session.rb', line 4

def new
  @new
end

#session_idObject

Returns the value of attribute session_id


4
5
6
# File 'lib/alexa_rubykit/session.rb', line 4

def session_id
  @session_id
end

#userObject

Returns the value of attribute user


4
5
6
# File 'lib/alexa_rubykit/session.rb', line 4

def user
  @user
end

Instance Method Details

#access_tokenObject


28
29
30
# File 'lib/alexa_rubykit/session.rb', line 28

def access_token
  @user['accessToken'] if @user
end

#has_attributes?Boolean

Check to see if attributes are present.

Returns:

  • (Boolean)

33
34
35
# File 'lib/alexa_rubykit/session.rb', line 33

def has_attributes?
  !@attributes.empty?
end

#new?Boolean

Returns whether this is a new session or not.

Returns:

  • (Boolean)

14
15
16
# File 'lib/alexa_rubykit/session.rb', line 14

def new?
  !!@new
end

#user_defined?Boolean

Returns true if a user is defined.

Returns:

  • (Boolean)

19
20
21
# File 'lib/alexa_rubykit/session.rb', line 19

def user_defined?
  !@user.nil? || !@user['userId'].nil?
end

#user_idObject

Returns the user_id.


24
25
26
# File 'lib/alexa_rubykit/session.rb', line 24

def user_id
  @user['userId'] if @user
end