class Ralyxa::ResponseEntities::Response

Attributes

response[R]

Public Class Methods

as_hash(output_speech: false, reprompt: false, session_attributes: {}, end_session: false, start_over: false, card: false, directives: false) click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 26
def self.as_hash(output_speech: false, reprompt: false, session_attributes: {}, end_session: false, start_over: false, card: false, directives: false)
  new(output_speech, reprompt, session_attributes, end_session, start_over, card, directives).to_h
end
new(output_speech, reprompt, session_attributes, end_session, start_over, card, directives) click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 8
def initialize(output_speech, reprompt, session_attributes, end_session, start_over, card, directives)
  @output_speech      = output_speech
  @reprompt           = reprompt
  @session_attributes = session_attributes
  @end_session        = end_session
  @start_over         = start_over
  @card               = card
  @directives         = directives
end

Public Instance Methods

to_h() click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 18
def to_h
  {}.tap do |response|
    add_version(response)
    add_session_attributes(response)
    add_response(response)
  end
end

Private Instance Methods

add_response(response) click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 43
def add_response(response)
  response[:response] = {}.tap do |response_object|
    response_object[:outputSpeech]     = @output_speech if @output_speech
    response_object[:reprompt]         = @reprompt      if @reprompt
    response_object[:card]             = @card          if @card
    response_object[:directives]       = @directives    if @directives
    response_object[:shouldEndSession] = @end_session
  end
end
add_session_attributes(response) click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 38
def add_session_attributes(response)
  return response[:sessionAttributes] = {} if @start_over
  response[:sessionAttributes] = @session_attributes unless @session_attributes.empty?
end
add_version(response) click to toggle source
# File lib/ralyxa/response_entities/response.rb, line 34
def add_version(response)
  response[:version] = '1.0'
end