Class: ZapierRestHooks::HooksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/zapier_rest_hooks/hooks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
# File 'app/controllers/zapier_rest_hooks/hooks_controller.rb', line 5

def create
  hook = Hook.new(hook_params)
  render nothing: true, status: 500 && return unless hook.save
  Rails.logger.info "Created REST hook: #{hook.inspect}"
  # The Zapier documentation says to return 201 - Created.
  render json: hook.to_json(only: :id), status: 201
end

#destroyObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/zapier_rest_hooks/hooks_controller.rb', line 13

def destroy
  hook = Hook.find(params[:id]) if params[:id]
  if hook.nil? && params[:subscription_url]
    hook = Hook.find_by_subscription_url(params[:subscription_url]).destroy
  end
  Rails.logger.info "Destroying REST hook: #{hook.inspect}"
  hook.destroy
  head :ok
end