docbrown/app/controllers/api/v0/webhooks_controller.rb
rhymes 676cf002bd Webhooks: API fixes and docs (#3901)
* Fix webhook API and add POST /api/webhooks docs

* Document GET /api/webhooks/:id

* Fix DELETE /api/webhooks/{id} and document it

* Add proper 404 specs
2019-09-03 10:41:23 -04:00

31 lines
718 B
Ruby

module Api
module V0
class WebhooksController < ApiController
respond_to :json
before_action :authenticate!
skip_before_action :verify_authenticity_token, only: %w[create destroy]
def create
@webhook = @user.webhook_endpoints.create!(webhook_params)
render "show", status: :created
end
def show
@webhook = @user.webhook_endpoints.find(params[:id])
end
def destroy
webhook = @user.webhook_endpoints.find(params[:id])
webhook.destroy!
head :no_content
end
private
def webhook_params
params.require(:webhook_endpoint).permit(:target_url, :source, events: [])
end
end
end
end