|
6 | 6 |
|
7 | 7 | This is the [Kotlin](https://kotlinlang.org/) implementation of the [Spotify Web API](https://developer.spotify.com/web-api/)
|
8 | 8 |
|
9 |
| -### Have a question? |
10 |
| -If you have a question, you can: |
11 |
| - |
12 |
| -1. Create an [issue](https://github.com/adamint/spotify-web-api-kotlin/issues) |
13 |
| -2. Join our [Discord server](https://discord.gg/G6vqP3S) |
14 |
| -3. Contact me using **Adam#9261** on [Discord](https://discordapp.com) or by sending me an email |
15 |
| - |
16 |
| -## Contents |
17 |
| - 1. **[Downloading](#downloading)** |
18 |
| - 2. **[Documentation](#documentation)** |
19 |
| - 2. **[Creating a SpotifyApi or SpotifyClientApi object](#creating-a-spotifyapi-or-spotifyclientapi-object)** |
20 |
| - 3. **[What is the SpotifyRestAction class?](#what-is-the-spotifyrestaction-class?)** |
21 |
| - 4. **[Using the Library](#using-the-library)** |
22 |
| - |
23 |
| -## Downloading |
24 |
| -This library is available via Maven Central [here](https://search.maven.org/artifact/com.adamratzman/spotify-api-kotlin). |
| 9 | +## Install it |
| 10 | +This library is available via JCenter [here](https://search.maven.org/artifact/com.adamratzman/spotify-api-kotlin). |
25 | 11 |
|
26 | 12 | ### Gradle
|
27 | 13 | ```
|
@@ -72,39 +58,91 @@ The `spotify-web-api-kotlin` JavaDocs are hosted at https://adamint.github.io/sp
|
72 | 58 | ## Samples
|
73 | 59 | Samples for all APIs are located in the `samples` directory
|
74 | 60 |
|
75 |
| -## Creating a SpotifyApi or SpotifyClientApi object |
76 |
| -In order to use the methods in this library, you must create either a `SpotifyApi` or `SpotifyClientApi` object using their respective exposed builders. Client-specific methods are unable to be accessed with the generic SpotifyApi, rather you must create an instance of the Client API. |
| 61 | +## Have a question? |
| 62 | +If you have a question, you can: |
77 | 63 |
|
78 |
| -### SpotifyApi |
79 |
| -By default, the SpotifyApi `Token` automatically regenerates when needed. This can be changed |
80 |
| -through the `automaticRefresh` parameter in all builders. |
| 64 | +1. Create an [issue](https://github.com/adamint/spotify-web-api-kotlin/issues) |
| 65 | +2. Join our [Discord server](https://discord.gg/G6vqP3S) |
| 66 | +3. Contact me using **Adam#9261** on [Discord](https://discordapp.com) |
81 | 67 |
|
82 |
| -To build a new `SpotifyApi`, you must pass the application id and secret. |
| 68 | +## Creating a new api instance |
| 69 | +To decide which api you need (SpotifyAppApi, SpotifyClientApi, SpotifyImplicitGrantApi), please refer to |
| 70 | +https://developer.spotify.com/documentation/general/guides/authorization-guide/. In general: |
| 71 | +- If you don't need client resources, use SpotifyAppApi |
| 72 | +- If you're using the api in a backend application, use SpotifyClientApi |
| 73 | +- If you're using the api in a frontend application, use SpotifyImplicitGrantApi |
83 | 74 |
|
84 |
| -```kotlin |
85 |
| -import com.adamratzman.spotify.SpotifyApi.Companion.spotifyAppApi |
| 75 | +### SpotifyAppApi |
| 76 | +This provides access only to public Spotify endpoints. By default, the SpotifyApi `Token` automatically regenerates when needed. This can be changed |
| 77 | +through the `automaticRefresh` parameter in all builders. |
86 | 78 |
|
87 |
| -val api = spotifyAppApi( |
88 |
| - System.getenv("SPOTIFY_CLIENT_ID"), |
89 |
| - System.getenv("SPOTIFY_CLIENT_SECRET") |
90 |
| -).build() |
91 |
| -``` |
| 79 | +There are four exposed builders, depending on the level of control you need over api creation. |
| 80 | +Please see the [spotifyAppApi builder docs]() for a full list of available builders, or the app api [samples](). |
| 81 | + |
92 | 82 |
|
93 |
| -*Note:* You are **unable** to use any client endpoint without authenticating with the client methods below. |
| 83 | +### SpotifyClientApi |
| 84 | +The `SpotifyClientApi` is a superset of `SpotifyApi`; thus, you have access to all `SpotifyApi` methods in `SpotifyClientApi`. |
| 85 | +This library does not provide a method to retrieve the code from your callback url; you must implement that with a web server. |
94 | 86 |
|
95 |
| -#### SpotifyClientApi |
96 |
| -The `SpotifyClientApi` is a superset of `SpotifyApi`; thus, you have access to all `SpotifyApi` methods in `SpotifyClientApi`. |
| 87 | +Make sure your application has requested the proper [Scopes](https://developer.spotify.com/web-api/using-spotifyScopes/) in order to |
| 88 | +ensure proper function of this library. |
97 | 89 |
|
98 | 90 | Its automatic refresh ability is available *only* when building with
|
99 | 91 | an authorization code or a `Token` object. Otherwise, it will expire `Token.expiresIn` seconds after creation.
|
100 | 92 |
|
101 |
| -You have two options when building the Client API. |
102 |
| -1. You can use [Implicit Grant access tokens](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow) by |
103 |
| -setting the value of `tokenString` in the builder `authentication` block. However, this is a one-time token that cannot be refreshed. |
104 |
| -2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) by |
105 |
| -setting the value of `authorizationCode` in a builder. You may generate an authentication flow url allowing you to request specific |
106 |
| -Spotify scopes using the `getAuthorizationUrl` method in any builder. This library does not provide a method to retrieve the code from your |
107 |
| -callback url; you must implement that with a web server. |
| 93 | +Please see the [spotifyClientApi builder docs]() for a full list of available builders, or the client [samples](). |
| 94 | + |
| 95 | +### SpotifyImplicitGrantApi |
| 96 | +Instantiate this api only if you are using the Spotify implicit grant flow. It is a superset of `SpotifyClientApi`. |
| 97 | +Please see the [spotifyImplicitGrantApi builder docs]() for a full list of available builders, or the implicit grant [samples](). |
| 98 | + |
| 99 | +### SpotifyApiBuilder Block & setting API options |
| 100 | +There are three pluggable blocks in each api's corresponding builder |
| 101 | + |
| 102 | +1. `credentials` lets you set the client id, client secret, and redirect uri |
| 103 | +2. `authorization` lets you set the type of api authorization you are using. |
| 104 | +Acceptable types include: an authorization code, a `Token` object, a Token's access code string, and an optional refresh token string |
| 105 | +3. `options` lets you configure API options to your own specific needs |
| 106 | + |
| 107 | +#### API options |
| 108 | +This library does not attempt to be prescriptivist. |
| 109 | +All API options are located in `SpotifyApiOptions` and their default values can be overridden; however, use caution in doing so, as |
| 110 | +most of the default values either allow for significant performance or feature enhancements to the API instance. |
| 111 | + |
| 112 | +- `useCache`: Set whether to cache requests. Default: true |
| 113 | +- `cacheLimit`: The maximum amount of cached requests allowed at one time. Null means no limit. Default: 200 |
| 114 | +- `automaticRefresh`: Enable or disable automatic refresh of the Spotify access token when it expires. Default: true |
| 115 | +- `retryWhenRateLimited`: Set whether to block the current thread and wait until the API can retry the request. Default: true |
| 116 | +- `enableLogger`: Set whether to enable to the exception logger. Default: true |
| 117 | +- `testTokenValidity`: After API creation, test whether the token is valid by performing a lightweight request. Default: false |
| 118 | +- `defaultLimit`: The default amount of objects to retrieve in one request. Default: 50 |
| 119 | +- `json`: The Json serializer/deserializer instance. |
| 120 | +- `allowBulkRequests`: Allow splitting too-large requests into smaller, allowable api requests. Default: true |
| 121 | +- `requestTimeoutMillis`: The maximum time, in milliseconds, before terminating an http request. Default: 100000ms |
| 122 | +- `refreshTokenProducer`: Provide if you want to use your own logic when refreshing a Spotify token. |
| 123 | + |
| 124 | +Notes: |
| 125 | +- Unless you have a good reason otherwise, `useCache` should be true |
| 126 | +- `cacheLimit` is per Endpoint, not per API. Don't be surprised if you end up with over 200 items in your cache with the default settings. |
| 127 | +- `automaticRefresh` is disabled when client secret is not provided, or if tokenString is provided in SpotifyClientApi |
| 128 | +- `allowBulkRequests` for example, lets you query 80 artists in one wrapper call by splitting it into 50 artists + 30 artists |
| 129 | +- `refreshTokenProducer` is useful when you want to re-authorize with the Spotify Auth SDK or elsewhere |
| 130 | + |
| 131 | +### Building the API |
| 132 | +The easiest way to build the API is synchronously using .build() after a builder |
| 133 | + |
| 134 | +```kotlin |
| 135 | +spotifyAppApi(clientId, clientSecret).build() |
| 136 | +``` |
| 137 | + |
| 138 | +You can also build the API asynchronously using kotlin coroutines! |
| 139 | +```kotlin |
| 140 | +runBlocking { |
| 141 | + spotifyAppApi(clientId, clientSecret).buildAsyncAt(this) { api -> |
| 142 | + // do things |
| 143 | + } |
| 144 | +} |
| 145 | +``` |
108 | 146 |
|
109 | 147 | ## What is the SpotifyRestAction class?
|
110 | 148 | Abstracting requests into a `SpotifyRestAction` class allows for a lot of flexibility in sending and receiving requests.
|
@@ -161,8 +199,6 @@ For obvious reasons, in most cases, making asynchronous requests via `queue` or
|
161 | 199 | the synchronous format is also shown.
|
162 | 200 |
|
163 | 201 | ```kotlin
|
164 |
| -import com.adamratzman.spotify.SpotifyApi.Companion.spotifyAppApi |
165 |
| - |
166 | 202 | val api = spotifyAppApi(
|
167 | 203 | System.getenv("SPOTIFY_CLIENT_ID"),
|
168 | 204 | System.getenv("SPOTIFY_CLIENT_SECRET")
|
@@ -199,111 +235,4 @@ You can then use this track in `SpotifyClientApi` endpoints such as playing or s
|
199 | 235 | in your market!
|
200 | 236 |
|
201 | 237 | ### Contributing
|
202 |
| -See [CONTRIBUTING.md](CONTRIBUTING.md) |
203 |
| - |
204 |
| -### Endpoint List |
205 |
| -#### SpotifyApi: |
206 |
| - - **[AlbumApi (SpotifyApi.albums)](https://developer.spotify.com/web-api/album-endpoints/)** |
207 |
| - 1. `getAlbum` |
208 |
| - 2. `getAlbums` |
209 |
| - 3. `getAlbumTracks` |
210 |
| - - **[ArtistApi (SpotifyApi.artists)](https://developer.spotify.com/web-api/artist-endpoints/)** |
211 |
| - 1. `getArtist` |
212 |
| - 2. `getArtists` |
213 |
| - 3. `getArtistAlbums` |
214 |
| - 4. `getArtistTopTracks` |
215 |
| - 5. `getRelatedArtists` |
216 |
| - - **[BrowseApi (SpotifyApi.browse)](https://developer.spotify.com/web-api/browse-endpoints/)** |
217 |
| - 1. `getNewReleases` |
218 |
| - 2. `getFeaturedPlaylists` |
219 |
| - 3. `getCategoryList` |
220 |
| - 4. `getCategory` |
221 |
| - 5. `getPlaylistsForCategory` |
222 |
| - 6. `getTrackRecommendations` |
223 |
| - 7. `getAvailableGenreSeeds` |
224 |
| - - **[FollowingApi (SpotifyApi.following)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)** |
225 |
| - 1. `areFollowingPlaylist` |
226 |
| - 2. `isFollowingPlaylist` |
227 |
| - - **[PlaylistApi (SpotifyApi.playlist)](https://developer.spotify.com/web-api/playlist-endpoints/)** |
228 |
| - 1. `getUserPlaylists` |
229 |
| - 2. `getPlaylist` |
230 |
| - 3. `getPlaylistTracks` |
231 |
| - 4. `getPlaylistCovers` |
232 |
| - - **[SearchApi (SpotifyApi.search)](https://developer.spotify.com/web-api/search-item/)** |
233 |
| - It is possible to have 0 results and no exception thrown with these methods. Check the size of items returned. |
234 |
| - 1. `searchPlaylist` |
235 |
| - 2. `searchTrack` |
236 |
| - 3. `searchArtist` |
237 |
| - 4. `searchAlbum` |
238 |
| - 5. `search` |
239 |
| - - **[TrackApi (SpotifyApi.tracks)](https://developer.spotify.com/web-api/track-endpoints/)** |
240 |
| - 1. `getTrack` |
241 |
| - 2. `getTracks` |
242 |
| - 3. `getAudioAnalysis` |
243 |
| - 4. `getAudioFeatures` |
244 |
| - - **[UserApi (SpotifyApi.users)](https://developer.spotify.com/web-api/user-profile-endpoints/)** |
245 |
| - 1. `getProfile` |
246 |
| -#### SpotifyClientApi: |
247 |
| -Make sure your application has requested the proper [Scopes](https://developer.spotify.com/web-api/using-spotifyScopes/) in order to |
248 |
| -ensure proper function of this library. |
249 |
| - |
250 |
| -Check to see which Scope is necessary with the corresponding endpoint using the |
251 |
| -links provided for each API below |
252 |
| - - **[ClientPersonalizationApi (SpotifyClientApi.personalization)](https://developer.spotify.com/web-api/web-api-personalization-endpoints/)** |
253 |
| - 1. `getTopArtists` |
254 |
| - 2. `getTopTracks` |
255 |
| - - **[ClientProfileApi (SpotifyClientApi.users)](https://developer.spotify.com/web-api/user-profile-endpoints/)** |
256 |
| - 1. `getClientProfile` |
257 |
| - - **[ClientLibraryApi (SpotifyClientApi.library)](https://developer.spotify.com/web-api/library-endpoints/)** |
258 |
| - 1. `getSavedTracks` |
259 |
| - 2. `getSavedAlbums` |
260 |
| - 3. `contains` |
261 |
| - 4. `add` |
262 |
| - 5. `remove` |
263 |
| - - **[ClientFollowingApi (SpotifyClientApi.following)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)** |
264 |
| - 1. `isFollowingUser` |
265 |
| - 2. `isFollowingPlaylist` |
266 |
| - 3. `isFollowingUsers` |
267 |
| - 4. `isFollowingArtist` |
268 |
| - 5. `isFollowingArtists` |
269 |
| - 6. `getFollowedArtists` |
270 |
| - 7. `followUser` |
271 |
| - 8. `followUsers` |
272 |
| - 9. `followArtist` |
273 |
| - 10. `followArtists` |
274 |
| - 11. `followPlaylist` |
275 |
| - 12. `unfollowUser` |
276 |
| - 13. `unfollowUsers` |
277 |
| - 14. `unfollowArtist` |
278 |
| - 15. `unfollowArtists` |
279 |
| - 16. `unfollowPlaylist` |
280 |
| - - **[ClientPlayerApi (SpotifyClientApi.player)](https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/)** |
281 |
| - 1. `getDevices` |
282 |
| - 2. `getCurrentContext` |
283 |
| - 3. `getRecentlyPlayed` |
284 |
| - 4. `getCurrentlyPlaying` |
285 |
| - 5. `pause` |
286 |
| - 6. `seek` |
287 |
| - 7. `setRepeatMode` |
288 |
| - 8. `setVolume` |
289 |
| - 9. `skipForward` |
290 |
| - 10. `skipBehind` |
291 |
| - 11. `startPlayback` |
292 |
| - 12. `resume` |
293 |
| - 13. `toggleShuffle` |
294 |
| - 14. `transferPlayback` |
295 |
| - - **[ClientPlaylistApi (SpotifyClientApi.playlists)](https://developer.spotify.com/web-api/playlist-endpoints/)** |
296 |
| - 1. `createClientPlaylist` |
297 |
| - 2. `addTrackToClientPlaylist` |
298 |
| - 3. `addTracksToClientPlaylist` |
299 |
| - 4. `changeClientPlaylistDetails` |
300 |
| - 5. `getClientPlaylists` |
301 |
| - 6. `getClientPlaylist` |
302 |
| - 7. `deleteClientPlaylist` |
303 |
| - 8. `reorderClientPlaylistTracks` |
304 |
| - 9. `setClientPlaylistTracks` |
305 |
| - 10. `replaceClientPlaylistTracks` |
306 |
| - 11. `removeAllClientPlaylistTracks` |
307 |
| - 12. `uploadClientPlaylistCover` |
308 |
| - 13. `removeTrackFromClientPlaylist` |
309 |
| - 14. `removeTracksFromClientPlaylist` |
| 238 | +See [CONTRIBUTING.md](CONTRIBUTING.md) |
0 commit comments