diff --git a/app/controllers/clova_controller.rb b/app/controllers/clova_controller.rb new file mode 100644 index 0000000..d296832 --- /dev/null +++ b/app/controllers/clova_controller.rb @@ -0,0 +1,46 @@ +class ClovaController < ApplicationController + def index + clova_request = Clova::Request.parse_request_from(request.body.read) + case + when clova_request.event? + case clova_request.name + when "AudioPlayer.PlayStarted" + # noop + else + # noop + end + when clova_request.intent? + case clova_request.name + when "ReadlistsIntent" + # noop + when "ReadTasksIntent" + # noop + when "StartCheckIntent" + # noop + when "EndCheckIntent" + # noop + when "CheckIntent" + # noop + when "SetDueIntent" + # noop + when "NextIntent" + # noop + when "PrevIntent" + # noop + when "GuideIntent" + # noop + else + # noop + end + when clova_request.launch? + # noop + when clova_request.session_ended? + # noop + else + # something wrong? + # noop + end + + render json: {} + end +end diff --git a/app/helpers/clova_helper.rb b/app/helpers/clova_helper.rb new file mode 100644 index 0000000..38ae9f8 --- /dev/null +++ b/app/helpers/clova_helper.rb @@ -0,0 +1,2 @@ +module ClovaHelper +end diff --git a/app/models/clova/request.rb b/app/models/clova/request.rb index 9ba2363..ccbba4e 100644 --- a/app/models/clova/request.rb +++ b/app/models/clova/request.rb @@ -1,7 +1,12 @@ +require 'forwardable' + module Clova class Request + extend ::Forwardable attr_accessor :context, :request, :session, :version + def_delegators :@request, :event?, :intent?, :launch?, :session_ended?, :name, :slots, :payload + class Context attr_accessor :audio_player, :system @@ -113,6 +118,38 @@ def initialize(json) self.event = Event.new(json&.[]("event")) self.intent = Intent.new(json&.[]("intent")) end + + def event? + self.type == "EventRequest" + end + + def intent? + self.type == "IntentRequest" + end + + def launch? + self.type == "LaunchRequest" + end + + def session_ended? + self.type == "SessionEndedRequest" + end + + def name + case + when event? then "#{self.event.namespace}.#{self.event.name}" + when intent? then self.intent&.name + else "" + end + end + + def slots + self.intent&.slots + end + + def payload + self.event&.payload + end end # Request class Session diff --git a/app/views/clova/index.html.erb b/app/views/clova/index.html.erb new file mode 100644 index 0000000..db657e1 --- /dev/null +++ b/app/views/clova/index.html.erb @@ -0,0 +1,2 @@ +

Clova#index

+

Find me in app/views/clova/index.html.erb

diff --git a/config/routes.rb b/config/routes.rb index dc98ff5..2d2d018 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + post '/clova', to: 'clova#index' resources :lists do resources :tasks do patch 'complete', on: :member diff --git a/test/controllers/clova_controller_test.rb b/test/controllers/clova_controller_test.rb new file mode 100644 index 0000000..784fa21 --- /dev/null +++ b/test/controllers/clova_controller_test.rb @@ -0,0 +1,56 @@ +require 'test_helper' + +class ClovaControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + post(clova_url, params: <