collectAllItems

suspend fun <TPage, TItem> collectAllItems(firstPageResponse: SpotifyResult<TPage>, nextUrlSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<TPage>, maxPages: Int = 1000): SpotifyResult<List<TItem>>

Fetches subsequent pages starting from an already-retrieved first page and flattens all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

Return

The API response including status code and parsed Spotify payload; on the first error response, that error is returned as-is instead of the collected items.

Parameters

firstPageResponse

The already-fetched first page response.

nextUrlSelector

Extracts the next page URL from a page payload.

itemsSelector

Extracts the list of items from a page payload.

fetchNextPage

Fetches the next page for the given PagingOptions.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.


suspend fun <T> collectAllItems(firstPageResponse: SpotifyResult<Paging<T>>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, maxPages: Int = 1000): SpotifyResult<List<T>>

Fetches subsequent pages starting from an already-retrieved first Paging page and flattens all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

Return

The API response including status code and parsed Spotify payload; on the first error response, that error is returned as-is instead of the collected items.

Parameters

firstPageResponse

The already-fetched first page response.

fetchNextPage

Fetches the next page for the given PagingOptions.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.


suspend fun <TPage, TItem> collectAllItems(initialPagingOptions: PagingOptions = PagingOptions(), fetchFirstPage: suspend (PagingOptions) -> SpotifyResult<TPage>, nextUrlSelector: (TPage) -> String?, itemsSelector: (TPage) -> List<TItem>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<TPage>, maxPages: Int = 1000): SpotifyResult<List<TItem>>

Fetches the first page and then all subsequent pages, flattening all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

Return

The API response including status code and parsed Spotify payload; on an error response, that error is returned as-is instead of the collected items.

Parameters

initialPagingOptions

Paging options used to fetch the first page.

fetchFirstPage

Fetches the first page for the given PagingOptions.

nextUrlSelector

Extracts the next page URL from a page payload.

itemsSelector

Extracts the list of items from a page payload.

fetchNextPage

Fetches the next page for the given PagingOptions.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.


suspend fun <T> collectAllItems(initialPagingOptions: PagingOptions = PagingOptions(), fetchFirstPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, fetchNextPage: suspend (PagingOptions) -> SpotifyResult<Paging<T>>, maxPages: Int = 1000): SpotifyResult<List<T>>

Fetches the first Paging page and then all subsequent pages, flattening all items into a single list, following Spotify's next URL until it runs out or maxPages is reached.

Return

The API response including status code and parsed Spotify payload; on an error response, that error is returned as-is instead of the collected items.

Parameters

initialPagingOptions

Paging options used to fetch the first page.

fetchFirstPage

Fetches the first page for the given PagingOptions.

fetchNextPage

Fetches the next page for the given PagingOptions.

maxPages

Maximum number of pages to fetch, including the first page.

Throws

IllegalArgumentException

if maxPages is less than 1.