Sha256: 10ca74d0562a0ad227153d00367072b3b4039c65680ccb7d337b80d8f8ee451b

Contents?: true

Size: 1003 Bytes

Versions: 4

Compression:

Stored size: 1003 Bytes

Contents

module AlexaSkillsRuby
  module JsonObjects
    class BaseRequest < JsonObject
      attributes :type, :request_id, :timestamp, :locale

      def self.new(*args, &block)
        json = args.first
        subclass = case
                     when self != BaseRequest
                       nil
                     when json.nil?
                        nil
                      when json['type'] == 'LaunchRequest'
                        LaunchRequest
                      when json['type'] == 'IntentRequest'
                        IntentRequest
                      when json['type'] == 'SessionEndedRequest'
                        SessionEndedRequest
                      else
                        nil
                   end

        if subclass
          subclass.new(*args, &block)
        else
          super
        end
      end

      def intent_name
        if self.is_a? IntentRequest
          self.intent.name
        else
          nil
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alexa_skills_ruby-1.1.0 lib/alexa_skills_ruby/json_objects/base_request.rb
alexa_skills_ruby-1.0.0 lib/alexa_skills_ruby/json_objects/base_request.rb
alexa_skills_ruby-0.0.7 lib/alexa_skills_ruby/json_objects/base_request.rb
alexa_skills_ruby-0.0.6 lib/alexa_skills_ruby/json_objects/base_request.rb