Class: Api::Paging::RestPagedResponseBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/api/paging/rest_paged_response_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(pager, request, allowed_params = nil) ⇒ RestPagedResponseBuilder

Returns a new instance of RestPagedResponseBuilder.


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/api/paging/rest_paged_response_builder.rb', line 6

def initialize(pager, request, allowed_params=nil)
  @pager = pager
  @base_url = request.original_url.split("?").first if request
  @query_parameters = if allowed_params
                        allowed_params
                      elsif request&.query_parameters
                        request&.query_parameters
                      else
                        {}
                      end
end

Instance Method Details

#responseObject


18
19
20
21
22
23
# File 'lib/api/paging/rest_paged_response_builder.rb', line 18

def response
  {
    links: navigation_builder,
    data:  @pager.page_data
  }
end