Class: Poms::Api::PaginationClient::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/poms/api/pagination_client.rb

Overview

Keep track of number of items and how many have been retrieved

Instance Method Summary collapse

Constructor Details

#initialize(uri, offset = 0) ⇒ Page



36
37
38
39
# File 'lib/poms/api/pagination_client.rb', line 36

def initialize(uri, offset = 0)
  uri.query_values = { offset: offset }
  @uri = uri
end

Instance Method Details

#executeObject



53
54
55
# File 'lib/poms/api/pagination_client.rb', line 53

def execute
  @response = yield uri
end

#final?Boolean



45
46
47
# File 'lib/poms/api/pagination_client.rb', line 45

def final?
  next_index >= response['total']
end

#itemsObject



49
50
51
# File 'lib/poms/api/pagination_client.rb', line 49

def items
  response['items']
end

#next_pageObject



41
42
43
# File 'lib/poms/api/pagination_client.rb', line 41

def next_page
  self.class.new(uri, next_index)
end