@@ -44,14 +44,22 @@ In order to use the methods in this library, you must create either a `SpotifyAP
4444The SpotifyAPI ` Token ` automatically regenerates when needed.
4545To build it, you must pass the application id and secret.
4646``` kotlin
47- val api = SpotifyAPI .Builder (" application id" , " application secret" ).build()
47+ import com.adamratzman.spotify.main.SpotifyScope
48+ import com.adamratzman.spotify.main.spotifyApi
49+
50+ spotifyApi {
51+ credentials {
52+ clientId = " YOUR_CLIENT_ID"
53+ clientSecret = " YOUR_CLIENT_SECRET"
54+ }
55+ }.buildCredentialed()
4856```
49- * Note:* You are ** unable** to use any clientApi endpoint.
57+ * Note:* You are ** unable** to use any client endpoint without authenticating with the methods below .
5058
5159### SpotifyClientAPI
52- All endpoints inside SpotifyAPI can be accessed within SpotifyClientAPI.
53- The SpotifyClientAPI's automatic refresh is available * only* when building with
54- an authorization code. Otherwise, it will expire in ` Token. expires_in ` seconds after creation.
60+ All endpoints inside ` SpotifyAPI ` can be accessed within the ` SpotifyClientAPI ` .
61+ Its automatic refresh is available * only* when building with
62+ an authorization code or a ` Token ` object . Otherwise, it will expire ` Token# expires_in ` seconds after creation.
5563
5664You have two options when building the Client API.
57651 . You can use [ Implicit Grant access tokens] ( https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow ) with
@@ -76,6 +84,13 @@ provided callback after the provided time. As long as supplier execution is less
7684time, this will likely be accurate within a few milliseconds.
7785- ` asFuture() ` transforms the supplier into a ` CompletableFuture `
7886
87+ ### SpotifyRestPagingAction
88+ Separate from SpotifyRestAction, this specialized implementation of RestActions is
89+ just for [ PagingObject] . This class gives you the same functionality as SpotifyRestAction,
90+ but you also have the ability to retrieve * all* of its items or linked PagingObjects with
91+ a single method call to ` getAllItems() ` or ` getAllPagingObjects() ` respectively
92+
93+
7994## Using the Library
8095### The benefits of LinkedResults, PagingObjects, and Cursor-based Paging Objects
8196Spotify provides these three object models in order to simplify our lives as developers. So let's see what we
@@ -102,26 +117,35 @@ list of objects. With this, we have access to its Spotify API url (with `href`),
102117that url.
103118
104119### Generic Request
105- For obvious reasons, in most cases, asynchronous requests via ` queue ` or ` queueAfter ` are preferred. However,
120+ For obvious reasons, in most cases, making asynchronous requests via ` queue ` or ` queueAfter ` is preferred. However,
106121the synchronous format is also shown.
107122
108123``` kotlin
109- val api = SpotifyAPI .Builder (" appId" , " appSecret" ).build()
110- val trackSearch = api.search.searchTrack(" Si t'étais là" , market = Market .FR )
111- // with optional parameter of market
112-
113- fun blocking () {
114- val trackPaging = trackSearch.complete()
115- println (trackPaging.items.map { it.name })
116- // iterate through, see total found, etc. with the paging object..
117- }
118-
119- fun async () {
120- trackSearch.queueAfter(2 , TimeUnit .SECONDS , { result ->
121- // do whatever with the result.
122- // this will be executed 2000 +- approximately 5 ms after invocation
123- })
124+ import com.adamratzman.spotify.main.SpotifyScope
125+ import com.adamratzman.spotify.main.spotifyApi
126+
127+ val spotifyApi = spotifyApi {
128+ credentials {
129+ clientId = " YOUR_CLIENT_ID"
130+ clientSecret = " YOUR_CLIENT_SECRET"
124131 }
132+ }.buildCredentialed()
133+
134+ // block and print out the names of the twenty most similar songs to the search
135+ spotifyApi.search.searchTrack(" Début de la Suite" ).complete().map { it.name }.joinToString().let { println (it) }
136+
137+ // now, let's do it asynchronously
138+ spotifyApi.search.searchTrack(" Début de la Suite" ).queue { it.map { it.name }.joinToString().let { println (it) } }
139+
140+ // simple, right? what about if we want to print ou the featured playlists message from the "Overview" tab?
141+ spotifyApi.browse.getFeaturedPlaylists().complete().message.let { println (it )}
142+
143+ // easy! let's try something a little harder
144+ // let's find out Bénabar's Spotify ID, find his top tracks, and print them out
145+
146+ spotifyApi.search.searchArtist(" Bénabar" ).complete()[0 ].id.let { id ->
147+ spotifyApi.artists.getArtistTopTracks(id).complete().joinToString { it.name }.let { println (it) }
148+ }
125149```
126150
127151### Track Relinking
@@ -136,8 +160,8 @@ will be populated with the href, uri, and, most importantly, the id of the track
136160You can then use this track in clientApi actions such as playing or saving the track, knowing that it will be playable
137161in your market!
138162
139- ### How to test
140- See [ TESTING .md] ( testing .md)
163+ ### Contributing
164+ See [ CONTRIBUTING .md] ( CONTRIBUTING .md)
141165
142166### Endpoint List
143167#### SpotifyAPI:
0 commit comments