summaryrefslogtreecommitdiff
path: root/lib/api/variables.rb
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2015-12-31 15:19:13 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2015-12-31 16:26:54 +0100
commitea4777ff501e370a39ae30e76a955136afe3c1fa (patch)
tree51edc60d0f03ec2fa2dd9dbb802182cc73c9c6a6 /lib/api/variables.rb
parent2c1f8e2d157554b12845ee7ecea1abff10dcf7cb (diff)
downloadgitlab-ce-ea4777ff501e370a39ae30e76a955136afe3c1fa.tar.gz
Add features for list and show details of variables in API
Diffstat (limited to 'lib/api/variables.rb')
-rw-r--r--lib/api/variables.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/api/variables.rb b/lib/api/variables.rb
new file mode 100644
index 00000000000..6517150f6f4
--- /dev/null
+++ b/lib/api/variables.rb
@@ -0,0 +1,43 @@
+module API
+ # Projects variables API
+ class Variables < Grape::API
+ before { authenticate! }
+ before { authorize_admin_project }
+
+ resource :projects do
+ # Get project variables
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # page (optional) - The page number for pagination
+ # per_page (optional) - The value of items per page to show
+ # Example Request:
+ # GET /projects/:id/variables
+ get ':id/variables' do
+ variables = user_project.variables
+ present paginate(variables), with: Entities::Variable
+ end
+
+ # Get specifica bariable of a project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # variable_id (required) - The ID OR `key` of variable to show; if variable_id contains only digits it's treated
+ # as ID other ways it's treated as `key`
+ # Example Reuest:
+ # GET /projects/:id/variables/:variable_id
+ get ':id/variables/:variable_id' do
+ variable_id = params[:variable_id]
+ variables = user_project.variables
+ variables =
+ if variable_id.match(/^\d+$/)
+ variables.where(id: variable_id.to_i)
+ else
+ variables.where(key: variable_id)
+ end
+
+ present variables.first, with: Entities::Variable
+ end
+ end
+ end
+end