Class: AlexaWebService::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
# File 'lib/alexa_web_service/response.rb', line 7

def initialize
  @session_attributes = {}
  @speech_type        = "PlainText"
  @spoken_response    = ''
  @reprompt_text      = ''
  @text_type          = "text"
  @end_session        = 'true'
  @card               = nil
  @directives         = []
end

Instance Attribute Details

#cardObject

Returns the value of attribute card.



3
4
5
# File 'lib/alexa_web_service/response.rb', line 3

def card
  @card
end

#directivesObject

Returns the value of attribute directives.



3
4
5
# File 'lib/alexa_web_service/response.rb', line 3

def directives
  @directives
end

#end_sessionObject

Returns the value of attribute end_session.



3
4
5
# File 'lib/alexa_web_service/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_web_service/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_web_service/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_web_service/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_web_service/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_web_service/response.rb', line 3

def text_type
  @text_type
end

Instance Method Details

#add_attribute(key, value) ⇒ Object



18
19
20
# File 'lib/alexa_web_service/response.rb', line 18

def add_attribute(key, value)
  @session_attributes.merge!(key => value)
end

#add_card(card) ⇒ Object



38
39
40
# File 'lib/alexa_web_service/response.rb', line 38

def add_card(card)
  self.card = card
end

#add_directive(directive) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/alexa_web_service/response.rb', line 30

def add_directive(directive)
  if directive[:type] == "Display.RenderTemplate"|| directive[:type] == "Hint"
    self.directives << directive if $display_support == true
  else
    self.directives << directive
  end
end

#append_attribute(key, value) ⇒ Object



26
27
28
# File 'lib/alexa_web_service/response.rb', line 26

def append_attribute(key, value)
  @session_attributes[key] << value if @session_attributes[key] != nil
end

#delete_attribute(key) ⇒ Object



22
23
24
# File 'lib/alexa_web_service/response.rb', line 22

def delete_attribute(key)
  @session_attributes.delete(key)
end

#postObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/alexa_web_service/response.rb', line 42

def post
  {
    "version": "1.0",
    "sessionAttributes": @session_attributes,  
    "response": {
      "outputSpeech": {
        "type": speech_type,
        "#{text_type}": spoken_response
      },
      "card": card,
      "reprompt": {
        "outputSpeech": {
          "type": speech_type,
          "text": reprompt_text
        }
      },
      "directives": @directives,
      "shouldEndSession": end_session
    }
  }.to_json
end