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(params = {}) ⇒ Response
constructor
A new instance of Response.
- #link_card ⇒ Object
- #to_hash(with_card = false) ⇒ Object
- #to_json(with_card = false) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ 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(params={}) @session_attributes = params[:session_attributes] || {} @speech_type = params[:speech_type] || "PlainText" @spoken_response = params[:spoken_response] || nil @card_title = params[:card_title] || nil @card_content = params[:card_content] || nil @reprompt_text = params[:reprompt_text] || nil @text_type = params[:text_type] || "text" @end_session = params[: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
51 52 53 |
# File 'lib/alexa_objects/response.rb', line 51 def link_card self.hash(true).tap { |hs| hs["response"]["card"] = {"type" => "LinkAccount"} } end |
#to_hash(with_card = false) ⇒ 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 48 49 |
# File 'lib/alexa_objects/response.rb', line 24 def to_hash(with_card=false) hash = { "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 } } return with_card ? hash : hash.tap { |hs| hs["response"].delete("card") } end |
#to_json(with_card = false) ⇒ Object
55 56 57 |
# File 'lib/alexa_objects/response.rb', line 55 def to_json(with_card=false) return self.to_hash(with_card).to_json end |