Class: Sophos::RequestPagination::PagesPagination
- Inherits:
-
Object
- Object
- Sophos::RequestPagination::PagesPagination
- Defined in:
- lib/sophos/pagination.rb
Overview
Sophos uses different pagination for global api and tenant api
response structure: { “pages”: {
"current": 1, # page no - not laways present
"size": 50,
"total": 3, # not always present - pages
"items": 123, # not always present - records
"maxSize": 100
},
“items”: []
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page_size) ⇒ PagesPagination
constructor
A new instance of PagesPagination.
-
#more_pages? ⇒ Boolean
only single page available.
- #next_page!(data) ⇒ Object
- #page_info(body) ⇒ Object
- #page_options ⇒ Object
Constructor Details
#initialize(page_size) ⇒ PagesPagination
Returns a new instance of PagesPagination.
23 24 25 26 27 28 |
# File 'lib/sophos/pagination.rb', line 23 def initialize(page_size) # ignore page size @page_size = page_size @total = @current = 1 @nextKey = nil end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
21 22 23 |
# File 'lib/sophos/pagination.rb', line 21 def current @current end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
21 22 23 |
# File 'lib/sophos/pagination.rb', line 21 def page_size @page_size end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
21 22 23 |
# File 'lib/sophos/pagination.rb', line 21 def total @total end |
Class Method Details
.data(body) ⇒ Object
57 58 59 |
# File 'lib/sophos/pagination.rb', line 57 def self.data(body) body['items'] ? body['items'] : body end |
Instance Method Details
#more_pages? ⇒ Boolean
only single page available
62 63 64 |
# File 'lib/sophos/pagination.rb', line 62 def more_pages? @current <= @total end |
#next_page!(data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sophos/pagination.rb', line 36 def next_page!(data) pages = page_info(data) if pages @total = pages['total'].to_i if pages['current'] @current = pages['current'].to_i + 1 else @current += 1 end @nextKey = pages['nextKey'] if pages['nextKey'] else # no page info so assume single page request @total = 0 end end |
#page_info(body) ⇒ Object
53 54 55 |
# File 'lib/sophos/pagination.rb', line 53 def page_info(body) body['pages'] end |
#page_options ⇒ Object
30 31 32 33 34 |
# File 'lib/sophos/pagination.rb', line 30 def = { 'page': @current, 'pageSize': @page_size, 'pageTotal': true } = .merge({ 'pageFromKey': @nextKey }) if @current > 1 end |