Class: CoreLibrary::PaginationStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/pagination/pagination_strategy.rb

Overview

Abstract base class for implementing pagination strategies.

Provides methods to initialize with pagination metadata, apply pagination logic to request builders, and update request builders with new pagination parameters based on JSON pointers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata_wrapper) ⇒ PaginationStrategy

Initializes the PaginationStrategy with the provided metadata wrapper.

Parameters:

  • metadata_wrapper (Object)

    An object containing pagination metadata. Must not be nil.

Raises:

  • (ArgumentError)

    If metadata_wrapper is nil.



13
14
15
16
17
# File 'lib/apimatic-core/pagination/pagination_strategy.rb', line 13

def initialize()
  raise ArgumentError, 'Metadata wrapper for the pagination cannot be nil' if .nil?

   = 
end

Instance Attribute Details

#metadata_wrapperObject (readonly)

Returns the value of attribute metadata_wrapper.



7
8
9
# File 'lib/apimatic-core/pagination/pagination_strategy.rb', line 7

def 
  
end

Instance Method Details

#applicable?(response) ⇒ boolean

Checks whether the pagination strategy is a valid candidate based on the given HTTP response.

Parameters:

  • response (HttpResponse)

    The response data from the previous API call.

Returns:

  • (boolean)

    True if this strategy is valid based on the given HTTP response..

Raises:

  • (NotImplementedError)

    This method must be implemented in a subclass.



24
25
26
# File 'lib/apimatic-core/pagination/pagination_strategy.rb', line 24

def applicable?(response)
  raise NotImplementedError, 'Subclasses must implement #is_applicable'
end

#apply(paginated_data) ⇒ Object

Modifies the request builder to fetch the next page of results based on the provided paginated data.

Parameters:

  • paginated_data (Object)

    The response data from the previous API call.

Returns:

  • (Object)

    An updated request builder configured for the next page request.

Raises:

  • (NotImplementedError)

    This method must be implemented in a subclass.



33
34
35
# File 'lib/apimatic-core/pagination/pagination_strategy.rb', line 33

def apply(paginated_data)
  raise NotImplementedError, 'Subclasses must implement #apply'
end

#apply_metadata_wrapper(paged_response) ⇒ Object

Processes the paged API response using the metadata wrapper.

Parameters:

  • paged_response (Object)

    The response object containing paginated data.

Returns:

  • (Object)

    The processed response with applied pagination metadata.

Raises:

  • (NotImplementedError)

    This method must be implemented in a subclass.



42
43
44
# File 'lib/apimatic-core/pagination/pagination_strategy.rb', line 42

def (paged_response)
  raise NotImplementedError, 'Subclasses must implement #apply_metadata_wrapper'
end