SPTListPage Class Reference
Inherits from | NSObject |
Conforms to | SPTTrackProvider |
Declared in | SPTListPage.h |
Overview
This class represents a page within a paginated list.
For the sake of conserving resources, lists that have the potential to be very large (such as search results, a playlist or album’s tracks, etc) are not delivered as a whole from the Spotify backend - instead, such lists are paginated. This class allows you to work with those pages.
API Model: https://developer.spotify.com/web-api/object-model/#paging-object
Tasks
Properties
-
range
property -
totalListLength
property -
hasNextPage
property -
hasPreviousPage
property -
nextPageURL
property -
previousPageURL
property -
isComplete
property -
items
property
API Request Factories
-
– createRequestForNextPageWithAccessToken:error:
-
– createRequestForPreviousPageWithAccessToken:error:
API Response Parsers
-
+ listPageFromData:withResponse:expectingPartialChildren:rootObjectKey:error:
-
+ listPageFromDecodedJSON:expectingPartialChildren:rootObjectKey:error:
Navigation and Manipulation
Properties
hasNextPage
Returns YES
if there is at least one page in the source list after the receiver, otherwise NO
.
@property (nonatomic, readonly) BOOL hasNextPage
Declared In
SPTListPage.h
hasPreviousPage
Returns YES
if there is at least one page in the source list before the receiver, otherwise NO
.
@property (nonatomic, readonly) BOOL hasPreviousPage
Declared In
SPTListPage.h
isComplete
Returns YES
if the page contains every single item in the source list, otherwise NO
.
@property (nonatomic, readonly) BOOL isComplete
Declared In
SPTListPage.h
items
The items contained in the page the receiver represents.
@property (nonatomic, readonly, copy) NSArray *items
Declared In
SPTListPage.h
nextPageURL
Returns the API url to the next page of items if it exist, otherwise nil
.
@property (nonatomic, readonly, copy) NSURL *nextPageURL
Declared In
SPTListPage.h
previousPageURL
Returns the API url to the previous page of items if it exist, otherwise nil
.
@property (nonatomic, readonly, copy) NSURL *previousPageURL
Declared In
SPTListPage.h
Class Methods
listPageFromData:withResponse:expectingPartialChildren:rootObjectKey:error:
Create a SPTListPage from a API response
+ (instancetype)listPageFromData:(NSData *)data withResponse:(NSURLResponse *)response expectingPartialChildren:(BOOL)hasPartialChildren rootObjectKey:(NSString *)rootObjectKey error:(NSError **)error
Parameters
- data
The API Response data
- response
The API Response object
- hasPartialChildren
True if api response provides partial entities, not full ones.
- rootObjectKey
The name of the entity with the actual content, or
nil
if the same as the root.
- error
An optional pointer to a
NSError
object that will be set if an error occured.
Return Value
A SPTListPage
, or nil if an error occured.
Declared In
SPTListPage.h
listPageFromDecodedJSON:expectingPartialChildren:rootObjectKey:error:
Create a SPTListPage from a decoded JSON structure
+ (instancetype)listPageFromDecodedJSON:(id)decodedObject expectingPartialChildren:(BOOL)hasPartialChildren rootObjectKey:(NSString *)rootObjectKey error:(NSError **)error
Parameters
- decodedObject
The JSON root entity
- hasPartialChildren
True if api response provides partial entities, not full ones.
- rootObjectKey
The name of the entity with the actual content, or
nil
if the same as the root.
- error
An optional pointer to a
NSError
object that will be set if an error occured.
Return Value
A SPTListPage
, or nil if an error occured.
Declared In
SPTListPage.h
Instance Methods
createRequestForNextPageWithAccessToken:error:
Create a request for fetching the next page in the source list.
- (NSURLRequest *)createRequestForNextPageWithAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- accessToken
An authenticated access token. Must be valid and authorized.
- error
An optional
NSError
that will be set if an error occured.
Declared In
SPTListPage.h
createRequestForPreviousPageWithAccessToken:error:
Create a request for fetching the previous page in the source list.
- (NSURLRequest *)createRequestForPreviousPageWithAccessToken:(NSString *)accessToken error:(NSError **)error
Parameters
- accessToken
An authenticated access token. Must be valid and authorized.
- error
An optional
NSError
that will be set if an error occured.
Declared In
SPTListPage.h
pageByAppendingPage:
Create a new page by adding a page to the receiver.
- (instancetype)pageByAppendingPage:(SPTListPage *)nextPage
Parameters
- nextPage
The page to add to the receiver.
Return Value
A new SPTListPage
containing the union of the receiver and nextPage.
Discussion
Warning: The added page must start immediately after the receiver - that is,
nextPage.
range.location
must equal self.
range.location + self.
range.length
.
Declared In
SPTListPage.h
requestNextPageWithAccessToken:callback:
Request the next page in the source list.
- (void)requestNextPageWithAccessToken:(NSString *)accessToken callback:(SPTRequestCallback)block
Parameters
- accessToken
An authenticated access token. Must be valid and authorized.
- block
The block to be called when the operation is complete. This block will pass an error if the operation failed, otherwise the next
SPTListPage
in the source list.
Declared In
SPTListPage.h
requestPreviousPageWithAccessToken:callback:
Request the previous page in the source list.
- (void)requestPreviousPageWithAccessToken:(NSString *)accessToken callback:(SPTRequestCallback)block
Parameters
- accessToken
An authenticated access token. Must be valid and authorized.
- block
The block to be called when the operation is complete. This block will pass an error if the operation failed, otherwise the previous
SPTListPage
in the source list.
Declared In
SPTListPage.h