2017-02-06 13:47:56 +00:00
|
|
|
module Gitlab
|
|
|
|
module Serializer
|
|
|
|
class Pagination
|
2017-03-01 11:00:37 +00:00
|
|
|
InvalidResourceError = Class.new(StandardError)
|
2017-02-06 13:47:56 +00:00
|
|
|
include ::API::Helpers::Pagination
|
|
|
|
|
|
|
|
def initialize(request, response)
|
|
|
|
@request = request
|
|
|
|
@response = response
|
|
|
|
end
|
|
|
|
|
2017-02-06 14:07:13 +00:00
|
|
|
def paginate(resource)
|
|
|
|
if resource.respond_to?(:page)
|
|
|
|
super(resource)
|
|
|
|
else
|
|
|
|
raise InvalidResourceError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-06 13:47:56 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
# Methods needed by `API::Helpers::Pagination`
|
|
|
|
#
|
|
|
|
|
|
|
|
attr_reader :request
|
|
|
|
|
|
|
|
def params
|
|
|
|
@request.query_parameters
|
|
|
|
end
|
|
|
|
|
|
|
|
def header(header, value)
|
|
|
|
@response.headers[header] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|