summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2016-10-13 17:52:21 +0200
committerRobert Schilling <rschilling@student.tugraz.at>2016-10-13 19:22:34 +0200
commite836b904b77e857ad2e1a0bc65129380d5f0e6dc (patch)
tree55f15961d6474f971eea626e97a34bfcbda06f80
parent4b889dbb3cbe0eb3ab639ca68bbe6e71abec711c (diff)
downloadgitlab-ce-grapify-system-hooks.tar.gz
Grapify system hooks APIgrapify-system-hooks
-rw-r--r--lib/api/system_hooks.rb60
1 files changed, 29 insertions, 31 deletions
diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb
index 22b8f90dc5c..2e76b91051f 100644
--- a/lib/api/system_hooks.rb
+++ b/lib/api/system_hooks.rb
@@ -7,38 +7,36 @@ module API
end
resource :hooks do
- # Get the list of system hooks
- #
- # Example Request:
- # GET /hooks
+ desc 'Get the list of system hooks' do
+ success Entities::Hook
+ end
get do
- @hooks = SystemHook.all
- present @hooks, with: Entities::Hook
+ hooks = SystemHook.all
+ present hooks, with: Entities::Hook
end
- # Create new system hook
- #
- # Parameters:
- # url (required) - url for system hook
- # Example Request
- # POST /hooks
+ desc 'Create a new system hook' do
+ success Entities::Hook
+ end
+ params do
+ requires :url, type: String, desc: 'The URL for the system hook'
+ end
post do
- attrs = attributes_for_keys [:url]
- required_attributes! [:url]
- @hook = SystemHook.new attrs
- if @hook.save
- present @hook, with: Entities::Hook
+ hook = SystemHook.new declared(params).to_h
+
+ if hook.save
+ present hook, with: Entities::Hook
else
not_found!
end
end
- # Test a hook
- #
- # Example Request
- # GET /hooks/:id
+ desc 'Test a hook'
+ params do
+ requires :id, type: Integer, desc: 'The ID of the system hook'
+ end
get ":id" do
- @hook = SystemHook.find(params[:id])
+ hook = SystemHook.find(params[:id])
data = {
event_name: "project_create",
name: "Ruby",
@@ -47,20 +45,20 @@ module API
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
- @hook.execute(data, 'system_hooks')
+ hook.execute(data, 'system_hooks')
data
end
- # Delete a hook. This is an idempotent function.
- #
- # Parameters:
- # id (required) - ID of the hook
- # Example Request:
- # DELETE /hooks/:id
+ desc 'Delete a hook' do
+ success Entities::Hook
+ end
+ params do
+ requires :id, type: Integer, desc: 'The ID of the system hook'
+ end
delete ":id" do
begin
- @hook = SystemHook.find(params[:id])
- @hook.destroy
+ hook = SystemHook.find(params[:id])
+ present hook.destroy, with: Entities::Hook
rescue
# SystemHook raises an Error if no hook with id found
end