Savable

public protocol Savable

A type representing a Spotify item that can be saved to the current authenticated user’s Spotify music library.

Types that conform to this protocol provide a set of request factories and convenience methods to either save, remove, or check to see if the user has already saved the item. These types must also contain a valid Spotify ID.

  • id

    The Spotify ID for the item. Required.

    Declaration

    Swift

    var id: String { get }
  • makeSaveToLibraryRequest() Default implementation

    Creates and returns the request used to save the item to the current authenticated user’s Spotify music library.

    Default Implementation

    Declaration

    Swift

    func makeSaveToLibraryRequest() -> SKRequest

    Return Value

    An SKRequest instance with which to perform the API request.

  • makeRemoveFromLibraryRequest() Default implementation

    Creates and returns the request used to remove the item from the current authenticated user’s Spotify music library.

    Default Implementation

    Declaration

    Swift

    func makeRemoveFromLibraryRequest() -> SKRequest

    Return Value

    An SKRequest instance with which to perform the API request.

  • makeSaveStatusRequest() Default implementation

    Creates and returns the request used to check whether the item has been saved to the current authenticated user’s Spotify music library.

    Default Implementation

    Declaration

    Swift

    func makeSaveStatusRequest() -> SKRequest

    Return Value

    An SKRequest instance with which to perform the API request.

  • saveToLibrary(completion:) Default implementation

    Saves the item to the current authenticated user’s Spotify music library.

    Note

    This method uses the SPTAuth default instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.

    Modifying the current user’s Your Music collection requires authorization of the user-library-modify scope. See Using Scopes for more details.

    Default Implementation

    Declaration

    Swift

    func saveToLibrary(completion handler: @escaping SKErrorHandler)

    Parameters

    handler

    The callback handler for the request, providing an error identifying if and why the request failed, or nil if the request was successful.

  • removeFromLibrary(completion:) Default implementation

    Removes the item from the current authenticated user’s Spotify music library.

    Note

    This method uses the SPTAuth default instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.

    Modifying the current user’s Your Music collection requires authorization of the user-library-modify scope. See Using Scopes for more details.

    Default Implementation

    Declaration

    Swift

    func removeFromLibrary(completion handler: @escaping SKErrorHandler)

    Parameters

    handler

    The callback handler for the request, providing an error identifying if and why the request failed, or nil if the request was successful.

  • checkIfSaved(completion:) Default implementation

    Checks whether the item has been saved to the current authenticated user’s Spotify music library.

    Note

    This method uses the SPTAuth default instance session to authenticate the underlying request. If this session does not contain a valid access token, the request will result in an error. The access token must have been issued on behalf of the current user.

    Reading the current user’s Your Music collection requires authorization of the user-library-read scope. See Using Scopes for more details.

    Default Implementation

    Declaration

    Swift

    func checkIfSaved(completion handler: @escaping (Bool?, Error?) -> Void)

    Parameters

    handler

    The callback handler for the request. The parameters for this handler are:

    • isSaved: A Boolean value indicating whether the item has been saved to the current user’s library: true if saved, false otherwise.
    • error: An error identifying if and why the request failed, or nil if the request was successful.