Commit 0c5e5569 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1360 from NARKOZ/api

API pagination
parents cc03600b 76e4d94d
...@@ -198,7 +198,7 @@ GEM ...@@ -198,7 +198,7 @@ GEM
httparty (0.8.3) httparty (0.8.3)
multi_json (~> 1.0) multi_json (~> 1.0)
multi_xml multi_xml
i18n (0.6.0) i18n (0.6.1)
journey (1.0.4) journey (1.0.4)
jquery-rails (2.0.2) jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0) railties (>= 3.2.0, < 5.0)
...@@ -206,11 +206,10 @@ GEM ...@@ -206,11 +206,10 @@ GEM
jquery-ui-rails (0.5.0) jquery-ui-rails (0.5.0)
jquery-rails jquery-rails
railties (>= 3.1.0) railties (>= 3.1.0)
json (1.7.4) json (1.7.5)
kaminari (0.13.0) kaminari (0.14.0)
actionpack (>= 3.0.0) actionpack (>= 3.0.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
railties (>= 3.0.0)
kgio (2.7.4) kgio (2.7.4)
launchy (2.1.0) launchy (2.1.0)
addressable (~> 2.2.6) addressable (~> 2.2.6)
...@@ -348,7 +347,7 @@ GEM ...@@ -348,7 +347,7 @@ GEM
daemons (>= 1.0.9) daemons (>= 1.0.9)
eventmachine (>= 0.12.6) eventmachine (>= 0.12.6)
rack (>= 1.0.0) rack (>= 1.0.0)
thor (0.15.4) thor (0.16.0)
tilt (1.3.3) tilt (1.3.3)
treetop (1.4.10) treetop (1.4.10)
polyglot polyglot
......
Kaminari.configure do |config|
config.default_per_page = 20
config.max_per_page = 100
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
...@@ -23,6 +23,13 @@ GET http://example.com/api/v2/projects?private_token=QVy1PB7sTxfy4pqfZM1U ...@@ -23,6 +23,13 @@ GET http://example.com/api/v2/projects?private_token=QVy1PB7sTxfy4pqfZM1U
The API uses JSON to serialize data. You don't need to specify `.json` at the end of API URL. The API uses JSON to serialize data. You don't need to specify `.json` at the end of API URL.
#### Pagination
When listing resources you can pass the following parameters:
+ `page` (default: `1`) - page number
+ `per_page` (default: `20`, max: `100`) - how many items to list per page
## Contents ## Contents
+ [Users](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/users.md) + [Users](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/users.md)
......
...@@ -14,6 +14,10 @@ module Gitlab ...@@ -14,6 +14,10 @@ module Gitlab
@project @project
end end
def paginate(object)
object.page(params[:page]).per(params[:per_page].to_i)
end
def authenticate! def authenticate!
error!({'message' => '401 Unauthorized'}, 401) unless current_user error!({'message' => '401 Unauthorized'}, 401) unless current_user
end end
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /issues # GET /issues
get do get do
present current_user.issues, with: Entities::Issue present paginate(current_user.issues), with: Entities::Issue
end end
end end
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects/:id/issues # GET /projects/:id/issues
get ":id/issues" do get ":id/issues" do
present user_project.issues, with: Entities::Issue present paginate(user_project.issues), with: Entities::Issue
end end
# Get a single project issue # Get a single project issue
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects/:id/milestones # GET /projects/:id/milestones
get ":id/milestones" do get ":id/milestones" do
present user_project.milestones, with: Entities::Milestone present paginate(user_project.milestones), with: Entities::Milestone
end end
# Get a single project milestone # Get a single project milestone
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects # GET /projects
get do get do
@projects = current_user.projects @projects = paginate current_user.projects
present @projects, with: Entities::Project present @projects, with: Entities::Project
end end
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /users # GET /users
get do get do
@users = User.all @users = paginate User
present @users, with: Entities::User present @users, with: Entities::User
end end
......
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