Class: AmazonEcho

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

Defined Under Namespace

Classes: IntentRequest, LaunchRequest, Request, Response, SessionEndedRequest

Constant Summary collapse

VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request: nil, response: {}) ⇒ AmazonEcho

Returns a new instance of AmazonEcho.



11
12
13
14
# File 'lib/amazon_echo.rb', line 11

def initialize(request: nil, response: {})
  @request  = build_request(request)
  @response = Response.new(response)
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#build_request(request) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/amazon_echo.rb', line 20

def build_request(request)
  if request && request["request"]
    case request["request"].fetch("type")
    when "LaunchRequest"
      AmazonEcho::LaunchRequest
    when "IntentRequest"
      AmazonEcho::IntentRequest
    when "SessionEndedRequest"
      AmazonEcho::SessionEndedRequest
    end.new(request)
  else
    "Invalid request"
  end
end

#say(output_speech) ⇒ Object



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

def say(output_speech)
  response.say(output_speech)
end