Commit f0b42c10 authored by Robert Schilling's avatar Robert Schilling

Grapify subscription API

parent c392b0cc
...@@ -9,23 +9,20 @@ module API ...@@ -9,23 +9,20 @@ module API
'labels' => proc { |id| find_project_label(id) }, 'labels' => proc { |id| find_project_label(id) },
} }
params do
requires :id, type: String, desc: 'The ID of a project'
requires :subscribable_id, type: String, desc: 'The ID of a resource'
end
resource :projects do resource :projects do
subscribable_types.each do |type, finder| subscribable_types.each do |type, finder|
type_singularized = type.singularize type_singularized = type.singularize
type_id_str = :"#{type_singularized}_id"
entity_class = Entities.const_get(type_singularized.camelcase) entity_class = Entities.const_get(type_singularized.camelcase)
# Subscribe to a resource desc 'Subscribe to a resource' do
# success entity_class
# Parameters: end
# id (required) - The ID of a project post ":id/#{type}/:subscribable_id/subscription" do
# subscribable_id (required) - The ID of a resource resource = instance_exec(params[:subscribable_id], &finder)
# Example Request:
# POST /projects/:id/labels/:subscribable_id/subscription
# POST /projects/:id/issues/:subscribable_id/subscription
# POST /projects/:id/merge_requests/:subscribable_id/subscription
post ":id/#{type}/:#{type_id_str}/subscription" do
resource = instance_exec(params[type_id_str], &finder)
if resource.subscribed?(current_user) if resource.subscribed?(current_user)
not_modified! not_modified!
...@@ -35,17 +32,11 @@ module API ...@@ -35,17 +32,11 @@ module API
end end
end end
# Unsubscribe from a resource desc 'Unsubscribe from a resource' do
# success entity_class
# Parameters: end
# id (required) - The ID of a project delete ":id/#{type}/:subscribable_id/subscription" do
# subscribable_id (required) - The ID of a resource resource = instance_exec(params[:subscribable_id], &finder)
# Example Request:
# DELETE /projects/:id/labels/:subscribable_id/subscription
# DELETE /projects/:id/issues/:subscribable_id/subscription
# DELETE /projects/:id/merge_requests/:subscribable_id/subscription
delete ":id/#{type}/:#{type_id_str}/subscription" do
resource = instance_exec(params[type_id_str], &finder)
if !resource.subscribed?(current_user) if !resource.subscribed?(current_user)
not_modified! not_modified!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment