Class: Api::V2::WebhooksController

Inherits:
V2::BaseController
  • Object
show all
Includes:
Api::Version2, ForemanWebhooks::Controller::Parameters::Webhook
Defined in:
app/controllers/api/v2/webhooks_controller.rb

Instance Method Summary collapse

Methods included from ForemanWebhooks::Controller::Parameters::Webhook

#webhook_params

Instance Method Details

#createObject



50
51
52
53
# File 'app/controllers/api/v2/webhooks_controller.rb', line 50

def create
  @webhook = Webhook.new(webhook_params)
  process_response @webhook.save
end

#destroyObject



65
66
67
# File 'app/controllers/api/v2/webhooks_controller.rb', line 65

def destroy
  process_response @webhook.destroy
end

#eventsObject



70
71
72
# File 'app/controllers/api/v2/webhooks_controller.rb', line 70

def events
  render json: Webhook.available_events.sort.map { |e| e.delete_suffix(Webhook::EVENT_POSTFIX) }.to_json
end

#indexObject



14
15
16
# File 'app/controllers/api/v2/webhooks_controller.rb', line 14

def index
  @webhooks = resource_scope_for_index
end

#showObject



20
# File 'app/controllers/api/v2/webhooks_controller.rb', line 20

def show; end

#testObject



77
78
79
80
81
82
83
84
# File 'app/controllers/api/v2/webhooks_controller.rb', line 77

def test
  result = @webhook.test(payload: params[:payload])
  if result[:status] == :success
    respond_with @webhook, responder: ApiResponder, status: :ok
  else
    render_error('custom_error', status: :unprocessable_entity, locals: { message: result[:message] })
  end
end

#updateObject



58
59
60
61
# File 'app/controllers/api/v2/webhooks_controller.rb', line 58

def update
  @webhook = Webhook.find(params[:id])
  process_response @webhook.update(webhook_params)
end