Class: AlexaObjects::Response
- Inherits:
-
Object
- Object
- AlexaObjects::Response
- Defined in:
- lib/alexa_objects/response.rb
Instance Attribute Summary collapse
-
#card_content ⇒ Object
Returns the value of attribute card_content.
-
#card_title ⇒ Object
Returns the value of attribute card_title.
-
#end_session ⇒ Object
Returns the value of attribute end_session.
-
#reprompt_text ⇒ Object
Returns the value of attribute reprompt_text.
-
#session_attributes ⇒ Object
Returns the value of attribute session_attributes.
-
#speech_type ⇒ Object
Returns the value of attribute speech_type.
-
#spoken_response ⇒ Object
Returns the value of attribute spoken_response.
-
#text_type ⇒ Object
Returns the value of attribute text_type.
Instance Method Summary collapse
- #add_attribute(key, value) ⇒ Object
- #append_attribute(key, value) ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #link_card ⇒ Object
- #with_card ⇒ Object
- #without_card ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/alexa_objects/response.rb', line 5 def initialize @session_attributes = {} @speech_type = "PlainText" @spoken_response = nil @card_title = nil @card_content = nil @reprompt_text = nil @text_type = "text" @end_session = true end |
Instance Attribute Details
#card_content ⇒ Object
Returns the value of attribute card_content.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def card_content @card_content end |
#card_title ⇒ Object
Returns the value of attribute card_title.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def card_title @card_title end |
#end_session ⇒ Object
Returns the value of attribute end_session.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def end_session @end_session end |
#reprompt_text ⇒ Object
Returns the value of attribute reprompt_text.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def reprompt_text @reprompt_text end |
#session_attributes ⇒ Object
Returns the value of attribute session_attributes.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def session_attributes @session_attributes end |
#speech_type ⇒ Object
Returns the value of attribute speech_type.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def speech_type @speech_type end |
#spoken_response ⇒ Object
Returns the value of attribute spoken_response.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def spoken_response @spoken_response end |
#text_type ⇒ Object
Returns the value of attribute text_type.
3 4 5 |
# File 'lib/alexa_objects/response.rb', line 3 def text_type @text_type end |
Instance Method Details
#add_attribute(key, value) ⇒ Object
16 17 18 |
# File 'lib/alexa_objects/response.rb', line 16 def add_attribute(key, value) @session_attributes.merge!(key => value) end |
#append_attribute(key, value) ⇒ Object
20 21 22 |
# File 'lib/alexa_objects/response.rb', line 20 def append_attribute(key, value) @session_attributes[key] << value if @session_attributes[key] end |
#link_card ⇒ Object
49 50 51 |
# File 'lib/alexa_objects/response.rb', line 49 def link_card self.with_card.tap { |hs| hs[:response][:card] = {"type" => "LinkAccount"} } end |
#with_card ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/alexa_objects/response.rb', line 24 def with_card { "version" => "2.0", "sessionAttributes" => @session_attributes, "response" => { "outputSpeech" => { "type" => speech_type, "#{text_type}" => spoken_response }, "card" => { "type" => "Simple", "title" => card_title, "content" => card_content }, "reprompt" => { "outputSpeech" => { "type" => speech_type, "text" => reprompt_text } }, "shouldEndSession" => end_session } } end |
#without_card ⇒ Object
53 54 55 |
# File 'lib/alexa_objects/response.rb', line 53 def without_card self.with_card.tap { |hs| hs[:response].delete(:card) } end |