Module: AlexaRubykit

Defined in:
lib/alexa_rubykit/session_ended_request.rb,
lib/alexa_rubykit.rb,
lib/alexa_rubykit/request.rb,
lib/alexa_rubykit/session.rb,
lib/alexa_rubykit/version.rb,
lib/alexa_rubykit/response.rb,
lib/alexa_rubykit/intent_request.rb,
lib/alexa_rubykit/launch_request.rb,
lib/alexa_rubykit/response/dialog.rb

Overview

Session end request class.

Defined Under Namespace

Classes: Dialog, IntentRequest, LaunchRequest, Request, Response, Session, SessionEndedRequest, Slot

Constant Summary collapse

VERSION =
'1.3.1'

Class Method Summary collapse

Class Method Details

.build_request(json_request) ⇒ Object

Builds a new request for Alexa.

Raises:

  • (ArgumentError)

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/alexa_rubykit/request.rb', line 25

def self.build_request(json_request)
  raise ArgumentError, 'Invalid Alexa Request.' unless AlexaRubykit.valid_alexa?(json_request)
  @request = nil
  case json_request['request']['type']
    when /Launch/
      @request = LaunchRequest.new(json_request)
    when /Intent/
      @request = IntentRequest.new(json_request)
    when /SessionEnded/
      @request = SessionEndedRequest.new(json_request)
    else
      raise ArgumentError, 'Invalid Request Type.'
  end
  @request
end

Prints a JSON object.


10
11
12
# File 'lib/alexa_rubykit.rb', line 10

def self.print_json(json)
  p json
end

Prints the Gem version.


15
16
17
# File 'lib/alexa_rubykit.rb', line 15

def self.print_version
  p AlexaRubykit::VERSION
end

.transform_keys_to_symbols(value) ⇒ Object

Take keys of hash and transform those to a symbols


42
43
44
45
46
# File 'lib/alexa_rubykit/request.rb', line 42

def self.transform_keys_to_symbols(value)
  return value if not value.is_a?(Hash)
  hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = self.transform_keys_to_symbols(v); memo}
  return hash
end

.valid_alexa?(request_json) ⇒ Boolean

Returns true if all the Alexa request objects are set.

Returns:

  • (Boolean)

20
21
22
23
# File 'lib/alexa_rubykit.rb', line 20

def self.valid_alexa?(request_json)
  !request_json.nil? && !request_json['session'].nil? &&
      !request_json['version'].nil? && !request_json['request'].nil?
end