Class: AlexaToolbox::Request
- Inherits:
-
Object
- Object
- AlexaToolbox::Request
- Defined in:
- lib/alexa_toolbox/request.rb
Overview
Echo can send 3 types of requests
-
LaunchRequest: The app was launched using phrasing such as ‘Alexa open __’.
-
IntentRequest: An intent was requested.
-
SessionEndedRequest: Session was closed either by user or timeout.
Instance Attribute Summary collapse
-
#audioplayer ⇒ Object
readonly
Returns the value of attribute audioplayer.
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#intent ⇒ Object
readonly
Returns the value of attribute intent.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json_request, options = {}) ⇒ Request
constructor
A new instance of Request.
- #user_terminated? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(json_request, options = {}) ⇒ Request
Returns a new instance of Request.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/alexa_toolbox/request.rb', line 21 def initialize(json_request, = {}) @options = if .key?(:application_id) @request_id = json_request[:request][:requestId] raise ArgumentError, 'Request ID not present' if @request_id.nil? @version = json_request.key?(:version) ? json_request[:version] : "" @locale = json_request.key?(:request) && json_request[:request].key?(:locale) ? json_request[:request][:locale] : "" @error = json_request.key?(:request) && json_request[:request].key?(:error) ? json_request[:request][:error] : "" @cause = json_request.key?(:request) && json_request[:request].key?(:cause) ? json_request[:request][:cause] : "" @json = json_request @type = json_request[:request][:type][0..10] == "AudioPlayer" ? "AudioPlayer" : json_request[:request][:type] @intent = @type == "IntentRequest" ? AlexaToolbox::Intent.new(json_request[:request][:intent]) : nil @audioplayer = @type == "AudioPlayer" ? AlexaToolbox::AudioPlayer.new(json_request[:request]) : nil @session = json_request.key?(:session) ? AlexaToolbox::Session.new(json_request[:session]) : nil @context = json_request.key?(:context) ? AlexaToolbox::Context.new(json_request[:context]) : nil end |
Instance Attribute Details
#audioplayer ⇒ Object (readonly)
Returns the value of attribute audioplayer.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def audioplayer @audioplayer end |
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def cause @cause end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def context @context end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def error @error end |
#intent ⇒ Object (readonly)
Returns the value of attribute intent.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def intent @intent end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def json @json end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def locale @locale end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def @options end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def request_id @request_id end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def session @session end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/alexa_toolbox/request.rb', line 13 def version @version end |
Class Method Details
.default_options ⇒ Object
15 16 17 18 19 |
# File 'lib/alexa_toolbox/request.rb', line 15 def self. @default_options ||= { :application_id => '' } end |
Instance Method Details
#user_terminated? ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/alexa_toolbox/request.rb', line 43 def user_terminated? if self.type != "SessionEndedRequest" return nil end return self.json[:request][:reason] == "USER_INITIATED" end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/alexa_toolbox/request.rb', line 39 def valid? self.[:application_id] && ((!self.session.nil? && self.[:application_id] == self.session.application_id) || (!self.context.nil? && self.[:application_id] == self.context.application_id)) end |