Class: CloudAlly::RequestPagination::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudally/pagination.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_size) ⇒ Pager

Returns a new instance of Pager.



10
11
12
13
14
15
# File 'lib/cloudally/pagination.rb', line 10

def initialize(page_size)
  @page = 1
  @page_size = page_size
  @total = @page + 1
  @next_page = ''
end

Class Method Details

.data(body) ⇒ Object



29
30
31
# File 'lib/cloudally/pagination.rb', line 29

def self.data(body) 
  body['data'] ? body['data'] : body
end

Instance Method Details

#more_pages?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cloudally/pagination.rb', line 32

def more_pages?
  @page < @total
end

#next_page!(data) ⇒ Object



24
25
26
27
28
# File 'lib/cloudally/pagination.rb', line 24

def next_page!(data)
  @page += 1
  @total = data['totalPages'].to_i
  @next_page = data['nextPageToken']
end

#page_optionsObject



16
17
18
19
20
21
22
23
# File 'lib/cloudally/pagination.rb', line 16

def page_options
  following_page = { pageSize: @page_size }
  unless @next_page.empty?
    following_page.merge!({ page: @page, nextPageToken: @next_page }) 
  else
    following_page
  end
end