Class: Api::V2::WebhooksController
- Inherits:
-
V2::BaseController
- Object
- V2::BaseController
- Api::V2::WebhooksController
- Includes:
- Api::Version2, ForemanWebhooks::Controller::Parameters::Webhook
- Defined in:
- app/controllers/api/v2/webhooks_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #events ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #test ⇒ Object
- #update ⇒ Object
Methods included from ForemanWebhooks::Controller::Parameters::Webhook
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
65 66 67 |
# File 'app/controllers/api/v2/webhooks_controller.rb', line 65 def destroy process_response @webhook.destroy end |
#events ⇒ Object
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 |
#index ⇒ Object
14 15 16 |
# File 'app/controllers/api/v2/webhooks_controller.rb', line 14 def index @webhooks = resource_scope_for_index end |
#show ⇒ Object
20 |
# File 'app/controllers/api/v2/webhooks_controller.rb', line 20 def show; end |
#test ⇒ Object
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 |
#update ⇒ Object
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 |