Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
0d67f209
Commit
0d67f209
authored
Jun 29, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor API and improve docs
parent
84a3f8fc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
53 deletions
+89
-53
lib/api.rb
lib/api.rb
+3
-53
lib/api/projects.rb
lib/api/projects.rb
+50
-0
lib/api/users.rb
lib/api/users.rb
+36
-0
No files found.
lib/api.rb
View file @
0d67f209
require
'api/entities'
require
'api/helpers'
Dir
[
"
#{
Rails
.
root
}
/lib/api/*.rb"
].
each
{
|
file
|
require
file
}
module
Gitlab
class
API
<
Grape
::
API
format
:json
helpers
APIHelpers
# Users API
resource
:users
do
before
{
authenticate!
}
# GET /users
get
do
@users
=
User
.
all
present
@users
,
:with
=>
Entities
::
User
end
# GET /users/:id
get
":id"
do
@user
=
User
.
find
(
params
[
:id
])
present
@user
,
:with
=>
Entities
::
User
end
end
# GET /user
get
"/user"
do
authenticate!
present
@current_user
,
:with
=>
Entities
::
User
end
# Projects API
resource
:projects
do
before
{
authenticate!
}
# GET /projects
get
do
@projects
=
current_user
.
projects
present
@projects
,
:with
=>
Entities
::
Project
end
# GET /projects/:id
get
":id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
,
:with
=>
Entities
::
Project
end
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
ProjectRepositoryBranches
end
# GET /projects/:id/repository/tags
get
":id/repository/tags"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
ProjectRepositoryTags
end
end
mount
Users
mount
Projects
end
end
lib/api/projects.rb
0 → 100644
View file @
0d67f209
module
Gitlab
# Projects API
class
Projects
<
Grape
::
API
before
{
authenticate!
}
resource
:projects
do
# Get a projects list for authenticated user
#
# Example Request:
# GET /projects
get
do
@projects
=
current_user
.
projects
present
@projects
,
:with
=>
Entities
::
Project
end
# Get a single project
#
# Parameters:
# id (required) - The code of a project
# Example Request:
# GET /projects/:id
get
":id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
,
:with
=>
Entities
::
Project
end
# Get a project repository branches
#
# Parameters:
# id (required) - The code of a project
# Example Request:
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
ProjectRepositoryBranches
end
# Get a project repository tags
#
# Parameters:
# id (required) - The code of a project
# Example Request:
# GET /projects/:id/repository/tags
get
":id/repository/tags"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
ProjectRepositoryTags
end
end
end
end
lib/api/users.rb
0 → 100644
View file @
0d67f209
module
Gitlab
# Users API
class
Users
<
Grape
::
API
before
{
authenticate!
}
resource
:users
do
# Get a users list
#
# Example Request:
# GET /users
get
do
@users
=
User
.
all
present
@users
,
:with
=>
Entities
::
User
end
# Get a single user
#
# Parameters:
# id (required) - The ID of a user
# Example Request:
# GET /users/:id
get
":id"
do
@user
=
User
.
find
(
params
[
:id
])
present
@user
,
:with
=>
Entities
::
User
end
end
# Get currently authenticated user
#
# Example Request:
# GET /user
get
"/user"
do
present
@current_user
,
:with
=>
Entities
::
User
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment