Class: AlexaToolbox::Session
- Inherits:
-
Object
- Object
- AlexaToolbox::Session
- Defined in:
- lib/alexa_toolbox/session.rb
Overview
Handles the session object in requests.
Instance Attribute Summary collapse
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#new ⇒ Object
readonly
Returns the value of attribute new.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#access_token ⇒ Object
Returns user’s access token if provided.
- #access_token? ⇒ Boolean
- #consent_token ⇒ Object
- #consent_token? ⇒ Boolean
- #device_id ⇒ Object
-
#has_attributes? ⇒ Boolean
Check to see if attributes are present.
-
#initialize(session) ⇒ Session
constructor
A new instance of Session.
-
#new? ⇒ Boolean
Checks whether this is a new session.
- #supported_interfaces ⇒ Object
-
#user_defined? ⇒ Boolean
Checks if user is defined.
-
#user_id ⇒ Object
Returns user’s id.
Constructor Details
#initialize(session) ⇒ Session
Returns a new instance of Session.
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_id ⇒ Object (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 |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/alexa_toolbox/session.rb', line 4 def attributes @attributes end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
4 5 6 |
# File 'lib/alexa_toolbox/session.rb', line 4 def device @device end |
#new ⇒ Object (readonly)
Returns the value of attribute new.
4 5 6 |
# File 'lib/alexa_toolbox/session.rb', line 4 def new @new end |
#session_id ⇒ Object (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 |
#user ⇒ Object (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_token ⇒ Object
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
31 32 33 |
# File 'lib/alexa_toolbox/session.rb', line 31 def access_token? @user.key?(:accessToken) && !@user[:accessToken].empty? end |
#consent_token ⇒ Object
44 45 46 |
# File 'lib/alexa_toolbox/session.rb', line 44 def @user[:permissions][:consentToken] if @user && @user.key?(:permissions) && @user[:permissions].key?(:consentToken) end |
#consent_token? ⇒ Boolean
40 41 42 |
# File 'lib/alexa_toolbox/session.rb', line 40 def @user.key?(:permissions) && @user[:permissions].key?(:consentToken) && !@user[:permissions][:consentToken].empty? end |
#device_id ⇒ Object
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.
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
17 18 19 |
# File 'lib/alexa_toolbox/session.rb', line 17 def new? @new end |
#supported_interfaces ⇒ Object
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
22 23 24 |
# File 'lib/alexa_toolbox/session.rb', line 22 def user_defined? !@user.nil? || !@user[:userId].nil? end |
#user_id ⇒ Object
Returns user’s id
27 28 29 |
# File 'lib/alexa_toolbox/session.rb', line 27 def user_id @user[:userId] if @user end |