module AlexaRuby

AlexaRuby implements a back-end service for interaction with Amazon Alexa API

Session end request class.

Constants

VERSION

Public Class Methods

new(request, opts = {}) click to toggle source

Validate HTTP/S request body and initialize new Alexa Assistant

@param request [Object] request from Amazon Alexa web service,

can be hash or JSON encoded string

@param opts [Hash] additional options:

:disable_validations [Boolean] disables request validation if true
:certificates_chain_url [String] URL of Amazon SSL certificates chain
:request_signature [String] Base64-encoded request signature

@return [Object] new Request object instance @raise [ArgumentError] if given object isn't a valid JSON object

# File lib/alexa_ruby.rb, line 40
def new(request, opts = {})
  obj = build_json(request)
  Alexa.new(obj, opts)
end

Private Class Methods

build_json(obj) click to toggle source

Build JSON from received request

@param obj [Object] request from Amazon Alexa web service,

can be hash or JSON encoded string

@return [Hash] valid builded JSON @raise [ArgumentError] if given object isn't a valid JSON object

# File lib/alexa_ruby.rb, line 53
def build_json(obj)
  obj = Oj.generate(obj) if hash?(obj)
  Oj.load(obj, symbol_keys: true)
rescue StandardError
  raise ArgumentError, 'Request must be a valid JSON object'
end
hash?(obj) click to toggle source

Check if object is a Hash or not

@param obj [Object] some object @return [Boolean]

# File lib/alexa_ruby.rb, line 64
def hash?(obj)
  obj.is_a? Hash
end