Class: AlexaRuby::BaseRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa_ruby/request/base_request.rb

Overview

Amazon Alexa web service request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ BaseRequest

Initialize new request object


10
11
12
13
14
15
16
17
18
19
# File 'lib/alexa_ruby/request/base_request.rb', line 10

def initialize(request)
  @req = request
  @version = @req[:version]
  @session = parse_session unless @type == :audio_player
  @context = parse_context unless @req[:context].nil?
  @id = nil
  @timestamp = nil
  @locale = nil
  parse_base_params(@req[:request])
end

Instance Attribute Details

#certificates_chain_urlObject

Returns the value of attribute certificates_chain_url


5
6
7
# File 'lib/alexa_ruby/request/base_request.rb', line 5

def certificates_chain_url
  @certificates_chain_url
end

#contextObject (readonly)

Returns the value of attribute context


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def context
  @context
end

#idObject (readonly)

Returns the value of attribute id


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def id
  @id
end

#localeObject (readonly)

Returns the value of attribute locale


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def locale
  @locale
end

#sessionObject (readonly)

Returns the value of attribute session


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def session
  @session
end

#signatureObject

Returns the value of attribute signature


5
6
7
# File 'lib/alexa_ruby/request/base_request.rb', line 5

def signature
  @signature
end

#timestampObject (readonly)

Returns the value of attribute timestamp


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version


4
5
6
# File 'lib/alexa_ruby/request/base_request.rb', line 4

def version
  @version
end

Instance Method Details

#jsonString

Return JSON representation of given request


32
33
34
# File 'lib/alexa_ruby/request/base_request.rb', line 32

def json
  Oj.to_json(@req)
end

#valid?Boolean

Check if it is a valid Amazon request


24
25
26
27
# File 'lib/alexa_ruby/request/base_request.rb', line 24

def valid?
  validator = Validator.new(certificates_chain_url, signature, @req)
  validator.valid_request?
end