about summary refs log tree commit diff
path: root/app/controllers/api_controller.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-09 17:48:44 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-09 17:48:44 +0100
commitb13e7dda1f33be43d1667b754b67df71f3187a5c (patch)
tree62f451e95bb93846744f7bcdc58fcf8dc8d6d6f9 /app/controllers/api_controller.rb
parent8d7fc5da6c880e356e6861b5c5bd564c242c7991 (diff)
API pagination for all collections using Link header
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r--app/controllers/api_controller.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index db4035a96..5243f7d7b 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -1,4 +1,7 @@
 class ApiController < ApplicationController
+  DEFAULT_STATUSES_LIMIT = 20
+  DEFAULT_ACCOUNTS_LIMIT = 40
+
   protect_from_forgery with: :null_session
 
   skip_before_action :verify_authenticity_token
@@ -54,6 +57,13 @@ class ApiController < ApplicationController
     response.headers['Access-Control-Allow-Headers']  = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
   end
 
+  def set_pagination_headers(next_path = nil, prev_path = nil)
+    links = []
+    links << [next_path, [['rel', 'next']]] if next_path
+    links << [prev_path, [['rel', 'prev']]] if prev_path
+    response.headers['Link'] = LinkHeader.new(links)
+  end
+
   def current_resource_owner
     User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
   end