Sha256: 904feb361ab7c9a1cbcd55398c2650f56b12c94af3276a54ec52854505d3c427

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

require_dependency "sipgate_io/application_controller"

module SipgateIo
  class EventsController < ApplicationController
    skip_before_action :verify_authenticity_token, raise: false

    def create
      event_type = params[:event]
      case event_type
      when "newCall"
        event = NewCall.new(params)
      when "answer"
        event = Answer.new(params)
      when "hangup"
        event = Hangup.new(params)
      when "dtmf"
        event = Dtmf.new(params)
      else
        head 500 and return
      end
      (head 500 and return) if event.invalid?

      answer = process_event event
      render xml: answer
    end

    private

    delegate :processor_class, :processor_method, to: :sipgate_io_configuration

    def process_event(event)
      processor_class.new(event).public_send(processor_method)
    end

    def sipgate_io_configuration
      SipgateIo.configuration
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sipgate_io-0.3.0 app/controllers/sipgate_io/events_controller.rb
sipgate_io-0.2.0 app/controllers/sipgate_io/events_controller.rb
sipgate_io-0.1.6 app/controllers/sipgate_io/events_controller.rb