Class: AlexaToolbox::Session

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

Overview

Handles the session object in requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Session

Returns a new instance of Session.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/alexa_toolbox/session.rb', line 6

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

Instance Attribute Details

#application_idObject (readonly)

Returns the value of attribute application_id.



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

def application_id
  @application_id
end

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#deviceObject (readonly)

Returns the value of attribute device.



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

def device
  @device
end

#newObject (readonly)

Returns the value of attribute new.



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

def new
  @new
end

#session_idObject (readonly)

Returns the value of attribute session_id.



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

def session_id
  @session_id
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#access_tokenObject

Returns user’s access token if provided



36
37
38
# File 'lib/alexa_toolbox/session.rb', line 36

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

#access_token?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/alexa_toolbox/session.rb', line 31

def access_token?
  @user.key?(:accessToken) && !@user[:accessToken].empty?
end


44
45
46
# File 'lib/alexa_toolbox/session.rb', line 44

def consent_token
  @user[:permissions][:consentToken] if @user && @user.key?(:permissions) && @user[:permissions].key?(:consentToken)
end

Returns:

  • (Boolean)


40
41
42
# File 'lib/alexa_toolbox/session.rb', line 40

def consent_token?
  @user.key?(:permissions) && @user[:permissions].key?(:consentToken) && !@user[:permissions][:consentToken].empty?
end

#device_idObject



48
49
50
# File 'lib/alexa_toolbox/session.rb', line 48

def device_id
  @device[:deviceId]
end

#has_attributes?Boolean

Check to see if attributes are present.

Returns:

  • (Boolean)


57
58
59
# File 'lib/alexa_toolbox/session.rb', line 57

def has_attributes?
  !@attributes.empty?
end

#new?Boolean

Checks whether this is a new session

Returns:

  • (Boolean)


17
18
19
# File 'lib/alexa_toolbox/session.rb', line 17

def new?
  @new
end

#supported_interfacesObject



52
53
54
# File 'lib/alexa_toolbox/session.rb', line 52

def supported_interfaces
  @device[:supportedInterfaces]
end

#user_defined?Boolean

Checks if user is defined

Returns:

  • (Boolean)


22
23
24
# File 'lib/alexa_toolbox/session.rb', line 22

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

#user_idObject

Returns user’s id



27
28
29
# File 'lib/alexa_toolbox/session.rb', line 27

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