Followable
public protocol Followable
A type representing a Spotify item that can be followed or unfollowed by the current authenticated user.
Types that conform to this protocol provide a set of request factories and convenience methods to either follow, unfollow, or check to see if the current authenticated user is already following the item. These types must also contain a valid Spotify ID.
Note
Although a Spotify playlist is technically afollowablecatalog item, the method declarations and implementations for following playlists differ from those defined here. Thus, the
SKPlaylist
type does not conform to this protocol, but instead provides its own comparable methods and request factories.
-
The Spotify ID for the item. Required.
Declaration
Swift
var id: String { get }
-
makeFollowRequest()
Default implementation -
makeUnfollowRequest()
Default implementation -
makeFollowStatusRequest()
Default implementation -
follow(completion:)
Default implementationAdds the current authenticated user as a follower of the item.
Note
This method uses theSPTAuth
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 list of items that the current authenticated user follows also requires authorization of the
user-follow-modify
scope. See Using Scopes for more details.Default Implementation
Declaration
Swift
func follow(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. -
unfollow(completion:)
Default implementationRemoves the current authenticated user as a follower of the item.
Note
This method uses theSPTAuth
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 list of items that the current authenticated user follows also requires authorization of the
user-follow-modify
scope. See Using Scopes for more details.Default Implementation
Declaration
Swift
func unfollow(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. -
checkIfFollowing(completion:)
Default implementationChecks whether the current authenticated user is following the item.
Note
This method uses theSPTAuth
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 list of items that the current authenticated user follows also requires authorization of the
user-follow-read
scope. See Using Scopes for more details.Default Implementation
Declaration
Swift
func checkIfFollowing(completion handler: @escaping (Bool?, Error?) -> Void)
Parameters
handler
The callback handler for the request. The parameters for this handler are:
isFollowing
: A Boolean value indicating whether the current authenticated user is following the item:true
if following,false
otherwise.error
: An error identifying if and why the request failed, ornil
if the request was successful.