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
Tatuya Kamada
gitlab-ce
Commits
0678b8a4
Commit
0678b8a4
authored
Oct 29, 2013
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 'Link' header for API response
parent
ff7073ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
lib/api/helpers.rb
lib/api/helpers.rb
+18
-2
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+6
-0
No files found.
lib/api/helpers.rb
View file @
0678b8a4
...
...
@@ -51,8 +51,12 @@ module API
end
end
def
paginate
(
object
)
object
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
].
to_i
)
def
paginate
(
relation
)
per_page
=
params
[
:per_page
].
to_i
paginated
=
relation
.
page
(
params
[
:page
]).
per
(
per_page
)
add_pagination_headers
(
paginated
,
per_page
)
paginated
end
def
authenticate!
...
...
@@ -129,6 +133,18 @@ module API
private
def
add_pagination_headers
(
paginated
,
per_page
)
request_url
=
request
.
url
.
split
(
'?'
).
first
links
=
[]
links
<<
%(<#{request_url}?page=#{paginated.current_page - 1}&per_page=#{per_page}>; rel="prev")
unless
paginated
.
first_page?
links
<<
%(<#{request_url}?page=#{paginated.current_page + 1}&per_page=#{per_page}>; rel="next")
unless
paginated
.
last_page?
links
<<
%(<#{request_url}?page=1&per_page=#{per_page}>; rel="first")
links
<<
%(<#{request_url}?page=#{paginated.total_pages}&per_page=#{per_page}>; rel="last")
header
'Link'
,
links
.
join
(
', '
)
end
def
abilities
@abilities
||=
begin
abilities
=
Six
.
new
...
...
spec/requests/api/issues_spec.rb
View file @
0678b8a4
...
...
@@ -25,6 +25,12 @@ describe API::API do
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
issue
.
title
end
it
"should add pagination headers"
do
get
api
(
"/issues?per_page=3"
,
user
)
response
.
headers
[
'Link'
].
should
==
'<http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="first", <http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="last"'
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