Class: AlexaRubykit::Request
- Inherits:
-
Object
- Object
- AlexaRubykit::Request
- Defined in:
- lib/alexa_rubykit/request.rb
Overview
-
SessionEndedRequest: Session has ended.
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
-
#session_attributes ⇒ Object
Returns the value of attribute session_attributes.
-
#should_end_session ⇒ Object
Returns the value of attribute should_end_session.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#build_response ⇒ Object
Builds a response.
-
#initialize(json_request) ⇒ Request
constructor
A new instance of Request.
-
#say_response(speech) ⇒ Object
Creates a outputspeech JSON object for responding with voice.
Constructor Details
#initialize(json_request) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/alexa_rubykit/request.rb', line 13 def initialize(json_request) halt 500 if json_request.nil? @request = json_request case @request['type'] when /Launch/ @type = 'LAUNCH' when /Intent/ @type = 'INTENT' when /SessionEnded/ @type = 'SESSIONENDED' else halt 500 end end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/alexa_rubykit/request.rb', line 9 def response @response end |
#session_attributes ⇒ Object
Returns the value of attribute session_attributes.
9 10 11 |
# File 'lib/alexa_rubykit/request.rb', line 9 def session_attributes @session_attributes end |
#should_end_session ⇒ Object
Returns the value of attribute should_end_session.
9 10 11 |
# File 'lib/alexa_rubykit/request.rb', line 9 def should_end_session @should_end_session end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/alexa_rubykit/request.rb', line 9 def version @version end |
Instance Method Details
#build_response ⇒ Object
Builds a response.
29 30 31 32 33 34 35 36 37 |
# File 'lib/alexa_rubykit/request.rb', line 29 def build_response # Need to set all 3 parameters or the response is invalid halt 500 if @version.nil? || @response.nil? || @should_end_session.nil? response = Hash.new response[:version] = @version response[:response] = @response response[:should_end_session] = @should_end_session response.to_json end |
#say_response(speech) ⇒ Object
Creates a outputspeech JSON object for responding with voice. Data type: “outputSpeech”:
"type": "string",
"text": "string"
45 46 47 48 |
# File 'lib/alexa_rubykit/request.rb', line 45 def say_response(speech) output_speech = { :type => 'string', :text => speech } @response = { :outputSpeech => output_speech } end |