Class: Skykick::RequestPagination::ODataPagination

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

Overview

Handles OData pagination. This class maintains pagination state, including the offset, limit (page size), and total results. Since skipping pages isn't allowed by Skykick, the pagination assumes a simplified logic with a single page.

Examples:

Pagination Initialization

paginator = Skykick::RequestPagination::ODataPagination.new(100)
options = paginator.page_options

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_size) ⇒ ODataPagination

Initializes the pagination object with the specified page size. Assumes that pagination starts at the first page (offset 0).

Parameters:

  • page_size (Integer)

    Number of results per page



31
32
33
34
35
36
# File 'lib/skykick/pagination.rb', line 31

def initialize(page_size)
  @offset = 0
  @limit = page_size
  # Assume we have at least one page initially
  @total = @limit
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



25
26
27
# File 'lib/skykick/pagination.rb', line 25

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



25
26
27
# File 'lib/skykick/pagination.rb', line 25

def offset
  @offset
end

#totalObject (readonly)

Returns the value of attribute total.



25
26
27
# File 'lib/skykick/pagination.rb', line 25

def total
  @total
end

Class Method Details

.data(body) ⇒ Hash, ...

Processes the API response body and returns it unchanged. This method can be overridden to handle specific response parsing needs.

Parameters:

  • body (Hash, Array, String)

    The response body from the API

Returns:

  • (Hash, Array, String)

    Processed data (unchanged)



66
67
68
# File 'lib/skykick/pagination.rb', line 66

def self.data(body)
  body
end

Instance Method Details

#more_pages?Boolean

Checks if more pages are available. Since Skykick's API supports only a single page (no $skip), this method returns true only if the offset is at its initial value (indicating the first page).

Returns:

  • (Boolean)

    true if more pages are available, false otherwise



75
76
77
# File 'lib/skykick/pagination.rb', line 75

def more_pages?
  @offset.zero?
end

#next_page!(data) ⇒ Object

Updates the pagination state for the next page based on the current page's data. Skykick's API does not allow skipping, so the offset and total are adjusted based on the size of the current data.

Parameters:

  • data (Array)

    The data array from the current page



51
52
53
54
55
56
57
58
59
# File 'lib/skykick/pagination.rb', line 51

def next_page!(data)
  # Update the total number of results based on the size of the current data set.
  if data.count
    @total = data.count
  else
    @total = 1
  end
  @offset += @limit
end

#page_optionsHash<Symbol, Integer>

Returns the pagination options to be sent as query parameters. Due to Skykick's limitation, only the $top parameter is included.

Returns:

  • (Hash<Symbol, Integer>)

    Query parameters for pagination



42
43
44
# File 'lib/skykick/pagination.rb', line 42

def page_options
  { '$top': @limit }
end