Module: AlexaToolbox

Defined in:
lib/alexa_toolbox.rb,
lib/alexa_toolbox/intent.rb,
lib/alexa_toolbox/address.rb,
lib/alexa_toolbox/context.rb,
lib/alexa_toolbox/request.rb,
lib/alexa_toolbox/session.rb,
lib/alexa_toolbox/version.rb,
lib/alexa_toolbox/response.rb,
lib/alexa_toolbox/audioplayer.rb,
lib/alexa_toolbox/display_directive.rb,
lib/alexa_toolbox/display_directive_image.rb,
lib/alexa_toolbox/display_directive_template.rb,
lib/alexa_toolbox/display_directive_text_content.rb

Defined Under Namespace

Classes: Address, AudioPlayer, Context, DisplayDirective, DisplayDirectiveImage, DisplayDirectiveTemplate, DisplayDirectiveTextContent, Intent, Request, Response, Session

Constant Summary collapse

VERSION =
'1.0.5'

Class Method Summary collapse

Class Method Details

.build_request(json_request, application_id = "") ⇒ Object

Builds a new request for Alexa, primarily for testing purposes

Raises:

  • (ArgumentError)


52
53
54
55
56
# File 'lib/alexa_toolbox/request.rb', line 52

def self.build_request(json_request, application_id = "")
  json_request = self.transform_keys_to_symbols(json_request)
  raise ArgumentError, 'Invalid Alexa Request. Missing session, request, version, or application id.' unless AlexaToolbox.valid_alexa?(json_request)
  Request.new(json_request,{ :application_id => application_id })
end

Prints a JSON object.



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

def self.print_json(json)
  p json
end

Prints the Gem version.



14
15
16
# File 'lib/alexa_toolbox.rb', line 14

def self.print_version
  p AlexaToolbox::VERSION
end

.transform_keys_to_symbols(input) ⇒ Object

Take keys of hash and transform those to a symbols



24
25
26
27
28
# File 'lib/alexa_toolbox.rb', line 24

def self.transform_keys_to_symbols(input)
  return input if not input.is_a?(Hash)
  hash = input.inject({}){|store,(key,val)| store[key.to_sym] = self.transform_keys_to_symbols(val); store}
  return hash
end

.valid_alexa?(request_json) ⇒ Boolean

Returns true if all the Alexa objects are set.

Returns:

  • (Boolean)


19
20
21
# File 'lib/alexa_toolbox.rb', line 19

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