Class: ElephantInTheRoom::TheOneApiSdk::Pipeline::Paginate

Inherits:
Object
  • Object
show all
Defined in:
lib/elephant_in_the_room/the_one_api_sdk/pipeline/paginate.rb

Overview

Pipeline stage that adds pagination parameters and adds pagination details into response

Instance Method Summary collapse

Constructor Details

#initialize(next_pipeline_stage, limit: nil, page: nil, offset: nil) ⇒ Paginate

Returns a new instance of Paginate.



7
8
9
10
11
12
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/paginate.rb', line 7

def initialize(next_pipeline_stage, limit: nil, page: nil, offset: nil)
  @next_pipeline_stage = next_pipeline_stage
  @limit = limit
  @page = page
  @offset = offset
end

Instance Method Details

#execute_http_request(request_details) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/paginate.rb', line 14

def execute_http_request(request_details)
  request_details[:query_parameters] = {} unless request_details.key?(:query_parameters)
  request_details[:query_parameters]["limit"] = @limit unless @limit.nil?
  request_details[:query_parameters]["page"] = @page unless @page.nil?
  request_details[:query_parameters]["offset"] = @offset unless @offset.nil?

  @next_pipeline_stage.execute_http_request(request_details)
end

#result_hashObject



23
24
25
26
27
28
29
30
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/paginate.rb', line 23

def result_hash
  next_result = @next_pipeline_stage.result_hash

  {
    items: next_result[:docs],
    pagination: next_result.slice(:total, :limit, :offset, :page, :pages),
  }
end