Class: AmazonEcho::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(response: {}) ⇒ Response

Returns a new instance of Response.



2
3
4
5
6
# File 'lib/amazon_echo/response.rb', line 2

def initialize(response: {})
  @version              = response[:version]
  @session_attributes   = response[:session_attributes]
  @output_speech        = 'OK, done'
end

Instance Method Details

#responseObject



45
46
47
48
49
50
51
# File 'lib/amazon_echo/response.rb', line 45

def response
  {
    'version' => version,
    'sessionAttributes' => session_attributes,
    'response' => response_hash,
  }
end

#response_cardObject



33
34
35
# File 'lib/amazon_echo/response.rb', line 33

def response_card
  { 'type' => 'Simple', 'title' => 'Amazon Echo gem', 'content' => 'Response from amazon echo gem' }
end

#response_end_sessionObject



41
42
43
# File 'lib/amazon_echo/response.rb', line 41

def response_end_session
  true
end

#response_hashObject



21
22
23
24
25
26
27
# File 'lib/amazon_echo/response.rb', line 21

def response_hash
  { 'outputSpeech' => response_output_speech,
    'card' => response_card,
    'reprompt' => response_reprompt,
    'shouldEndSession' => response_end_session
  }
end

#response_output_speechObject



29
30
31
# File 'lib/amazon_echo/response.rb', line 29

def response_output_speech
  { 'type' => 'PlainText', 'text' => @output_speech }
end

#response_repromptObject



37
38
39
# File 'lib/amazon_echo/response.rb', line 37

def response_reprompt
  { 'outputSpeech' => { 'type' => 'PlainText', 'text' => 'Try again' }}
end

#say(output_speech = nil) ⇒ Object



8
9
10
11
# File 'lib/amazon_echo/response.rb', line 8

def say(output_speech=nil)
  @output_speech = output_speech if output_speech
  response
end

#session_attributesObject



17
18
19
# File 'lib/amazon_echo/response.rb', line 17

def session_attributes
  {}  || @session_attributes
end

#versionObject



13
14
15
# File 'lib/amazon_echo/response.rb', line 13

def version
  '1.0' || @version
end