Class: AlexaObjects::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa_objects/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

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_contentObject

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_titleObject

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_sessionObject

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_textObject

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_attributesObject

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_typeObject

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_responseObject

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_typeObject

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


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_cardObject



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_cardObject



53
54
55
# File 'lib/alexa_objects/response.rb', line 53

def without_card
  self.with_card.tap { |hs| hs["response"].delete("card") }
end