Skip to content

Commit 89075bb

Browse files
committed
update readme
1 parent 2e96603 commit 89075bb

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed

README.md

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@ If you have a question, you can:
2323
## Downloading
2424
This library is available via Maven Central [here](https://search.maven.org/artifact/com.adamratzman/spotify-api-kotlin).
2525

26-
### Maven:
27-
```
28-
<dependency>
29-
<groupId>com.adamratzman</groupId>
30-
<artifactId>spotify-api-kotlin</artifactId>
31-
<version>2.2.0</version>
32-
</dependency>
33-
34-
<repository>
35-
<id>jcenter</id>
36-
<name>jcenter-bintray</name>
37-
<url>http://jcenter.bintray.com</url>
38-
</repository>
39-
```
40-
4126
### Gradle
4227
```
4328
repositories {
@@ -50,8 +35,8 @@ compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.2.0'
5035
To use the latest snapshot instead, you must add the Jitpack repository as well
5136
```
5237
repositories {
53-
jcenter()
5438
maven { url 'https://jitpack.io' }
39+
jcenter()
5540
}
5641
```
5742
Then, you can use the following:
@@ -61,8 +46,23 @@ dependencies {
6146
}
6247
```
6348

49+
### Maven
50+
```
51+
<dependency>
52+
<groupId>com.adamratzman</groupId>
53+
<artifactId>spotify-api-kotlin</artifactId>
54+
<version>2.2.0</version>
55+
</dependency>
56+
57+
<repository>
58+
<id>jcenter</id>
59+
<name>jcenter-bintray</name>
60+
<url>http://jcenter.bintray.com</url>
61+
</repository>
62+
```
63+
6464
#### Android
65-
This library should work out of the box on Android.
65+
This library will work out of the box on Android.
6666

6767
## Documentation
6868
The `spotify-web-api-kotlin` JavaDocs are hosted at https://adamint.github.io/spotify-web-api-kotlin
@@ -71,11 +71,14 @@ The `spotify-web-api-kotlin` JavaDocs are hosted at https://adamint.github.io/sp
7171
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.
7272

7373
### SpotifyAPI
74-
The SpotifyAPI `Token` automatically regenerates when needed.
75-
To build it, you must pass the application id and secret.
74+
By default, the SpotifyAPI `Token` automatically regenerates when needed. This can be changed
75+
through the `automaticRefresh` parameter in all builders.
76+
77+
To build a new `SpotifyAPI`, you must pass the application id and secret.
78+
7679
```kotlin
77-
import com.adamratzman.spotify.main.SpotifyScope
78-
import com.adamratzman.spotify.main.spotifyApi
80+
import com.adamratzman.spotify.SpotifyScope
81+
import com.adamratzman.spotify.spotifyApi
7982

8083
spotifyApi {
8184
credentials {
@@ -86,25 +89,25 @@ spotifyApi {
8689
```
8790
*Note:* You are **unable** to use any client endpoint without authenticating with the methods below.
8891

89-
### SpotifyClientAPI
90-
All endpoints inside `SpotifyAPI` can be accessed within the `SpotifyClientAPI`.
92+
#### SpotifyClientAPI
93+
The `SpotifyClientAPI` is a superset of `SpotifyAPI`.
94+
9195
Its automatic refresh is available *only* when building with
92-
an authorization code or a `Token` object. Otherwise, it will expire `Token#expires_in` seconds after creation.
96+
an authorization code or a `Token` object. Otherwise, it will expire `Token.expiresIn` seconds after creation.
9397

9498
You have two options when building the Client API.
95-
1. You can use [Implicit Grant access tokens](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow) with
96-
`Builder.buildToken(token: String)`. However, this is a one-time token that cannot be refreshed.
97-
2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow). We provide a method
98-
with `Builder.buildAuthCode(code: String, automaticRefresh: Boolean)`to generate the flow url with Builder.getAuthUrl(vararg spotifyScopes: Scope), allowing you to request specific
99-
spotifyScopes. This library does not provide a method to retrieve the code from your
100-
callback URL. You must implement that with a web server. This method allows you
101-
to choose whether to use automatic token refresh.
99+
1. You can use [Implicit Grant access tokens](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow) by
100+
setting the value of `tokenString` in the builder `authentication` block. However, this is a one-time token that cannot be refreshed.
101+
2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) by
102+
setting the value of `authorizationCode` in a builder. You may generate an authentication flow url allowing you to request specific
103+
Spotify scopes using the `getAuthorizationUrl` method in any builder. This library does not provide a method to retrieve the code from your
104+
callback URL; you must implement that with a web server.
102105

103106
## What is the SpotifyRestAction class?
104-
I wanted users of this library to have as much flexibility as possible. This
105-
includes options for asynchronous and blocking execution in all endpoints. However,
107+
Abstracting requests into a `SpotifyRestAction` class allows for a lot of flexibility in sending and receiving requests.
108+
This class includes options for asynchronous and blocking execution in all endpoints. However,
106109
due to this, you **must** call one of the provided methods in order for the call
107-
to execute! The `SpotifyRestAction` provides four methods for use: 1 blocking and 3 async.
110+
to execute! The `SpotifyRestAction` provides many methods for use, including blocking and asynchronous ones. For example,
108111
- `complete()` blocks the current thread and returns the result
109112
- `queue()` executes and immediately returns
110113
- `queue(consumer: (T) -> Unit)` executes the provided callback as soon as the request
@@ -142,7 +145,7 @@ Just like with PagingObjects, you can get the next page of items with `getNext`.
142145
provided implementation of `after` in this library. You will need to do it yourself, if necessary.
143146

144147
#### LinkedResults
145-
Some endpoints, like `PlaylistsAPI.getPlaylistTracks`, return a LinkedResult, which is a simple wrapper around the
148+
Some endpoints, like `PlaylistAPI.getPlaylistTracks`, return a LinkedResult, which is a simple wrapper around the
146149
list of objects. With this, we have access to its Spotify API url (with `href`), and we provide simple methods to parse
147150
that url.
148151

@@ -151,31 +154,31 @@ For obvious reasons, in most cases, making asynchronous requests via `queue` or
151154
the synchronous format is also shown.
152155

153156
```kotlin
154-
import com.adamratzman.spotify.main.SpotifyScope
155-
import com.adamratzman.spotify.main.spotifyApi
157+
import com.adamratzman.spotify.SpotifyScope
158+
import com.adamratzman.spotify.spotifyApi
156159

157-
val spotifyApi = spotifyApi {
160+
val api = spotifyApi {
158161
credentials {
159162
clientId = "YOUR_CLIENT_ID"
160163
clientSecret = "YOUR_CLIENT_SECRET"
161164
}
162165
}.buildCredentialed()
163166

164167
// block and print out the names of the twenty most similar songs to the search
165-
spotifyApi.search.searchTrack("Début de la Suite").complete().map { it.name }.joinToString().let { println(it) }
168+
println(api.search.searchTrack("Début de la Suite").complete().map { it.name }.joinToString())
166169

167170
// now, let's do it asynchronously
168-
spotifyApi.search.searchTrack("Début de la Suite").queue { it.map { it.name }.joinToString().let { println(it) } }
171+
api.search.searchTrack("Début de la Suite").queue { println(it.map { it.name }.joinToString()) }
169172

170-
// simple, right? what about if we want to print ou the featured playlists message from the "Overview" tab?
171-
spotifyApi.browse.getFeaturedPlaylists().complete().message.let { println(it )}
173+
// simple, right? what about if we want to print out the featured playlists message from the "Overview" tab?
174+
println(api.browse.getFeaturedPlaylists().complete().message)
172175

173176
// easy! let's try something a little harder
174177
// let's find out Bénabar's Spotify ID, find his top tracks, and print them out
175178

176-
spotifyApi.search.searchArtist("Bénabar").complete()[0].id.let { id ->
177-
spotifyApi.artists.getArtistTopTracks(id).complete().joinToString { it.name }.let { println(it) }
178-
}
179+
val benabarId = api.search.searchArtist("Bénabar").complete()[0].id
180+
181+
println(api.artists.getArtistTopTracks(benabarId).complete().joinToString { it.name })
179182
```
180183

181184
### Track Relinking
@@ -187,7 +190,7 @@ In both Track and SimpleTrack objects in an endpoint response, there is a nullab
187190
If the track is unable to be played in the specified market and there is an alternative that *is* playable, this
188191
will be populated with the href, uri, and, most importantly, the id of the track.
189192

190-
You can then use this track in clientApi actions such as playing or saving the track, knowing that it will be playable
193+
You can then use this track in `SpotifyClientAPI` actions such as playing or saving the track, knowing that it will be playable
191194
in your market!
192195

193196
### Contributing
@@ -213,9 +216,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md)
213216
5. `getPlaylistsForCategory` returns a `PagingObject` of top simple playlists for the specified category id
214217
6. `getRecommendations` returns a RecommendationResponse. Parameters include seed artists, genres, tracks, and
215218
tuneable track attributes listed [here](https://developer.spotify.com/web-api/complete-recommendations/)
216-
- **[PublicFollowingAPI (SpotifyAPI.publicFollowing)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)**
219+
- **[PublicFollowingAPI (SpotifyAPI.following)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)**
217220
1. `doUsersFollowPlaylist` returns a List of Booleans corresponding to the order in which ids were specified
218-
- **[PlaylistsAPI (SpotifyAPI.playlists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
221+
- **[PlaylistAPI (SpotifyAPI.playlist)](https://developer.spotify.com/web-api/playlist-endpoints/)**
219222
1. `getPlaylists` returns a `PagingObject` of SimplePlaylists the user has
220223
2. `getPlaylist` returns a full Playlist object of the specified user and playlist id
221224
3. `getPlaylistTracks` returns a `LinkedResult` (linked with the playlist url) of **PlaylistTrack**s
@@ -243,9 +246,9 @@ links provided for each API below
243246
- **[PersonalizationAPI (SpotifyClientAPI.personalization)](https://developer.spotify.com/web-api/web-api-personalization-endpoints/)**
244247
1. `getTopArtists` returns an Artist `PagingObject` representing the most played Artists by the user
245248
2. `getTopTracks` returns a Track `PagingObject` representing the most played Tracks by the user
246-
- **[ClientUserAPI (SpotifyClientAPI.userProfile)](https://developer.spotify.com/web-api/user-profile-endpoints/)**
249+
- **[ClientUserAPI (SpotifyClientAPI.users)](https://developer.spotify.com/web-api/user-profile-endpoints/)**
247250
1. `getUserInformation` returns SpotifyUserInformation object, a much more detailed version of the public user object.
248-
- **[UserLibraryAPI (SpotifyClientAPI.userLibrary)](https://developer.spotify.com/web-api/library-endpoints/)**
251+
- **[UserLibraryAPI (SpotifyClientAPI.library)](https://developer.spotify.com/web-api/library-endpoints/)**
249252
1. `getSavedTracks` returns a `PagingObject` of saved tracks in the user's library
250253
2. `getSavedAlbums` returns a `PagingObject` of saved albums in the user's library
251254
3. `savedTracksContains` returns an ordered List of Booleans of whether the track exists in the user's library
@@ -256,7 +259,7 @@ links provided for each API below
256259
6. `saveAlbums` saves the entered albums to the user's library. Returns nothing
257260
7. `removeSavedTracks` removes the entered tracks from the user's library. Nothing happens if the track is not found. Returns nothing
258261
8. `removeSavedAlbums` removes the entered albums from the user's library. Nothing happens if the album is not found in the library. Returns nothing
259-
- **[FollowingAPI (SpotifyClientAPI.userFollowing)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)**
262+
- **[FollowingAPI (SpotifyClientAPI.following)](https://developer.spotify.com/web-api/web-api-follow-endpoints/)**
260263
1. `followingUsers` returns an ordered List of Booleans representing if the user follows the specified users
261264
2. `followingArtists` returns an ordered List of Booleans representing if the user follows the specified artists
262265
3. `getFollowedArtists` returns a [Cursor-Based Paging Object](https://developer.spotify.com/web-api/object-model/#cursor-based-paging-object) of followed Artists.
@@ -268,7 +271,7 @@ links provided for each API below
268271
9. `unfollowPlaylist` unfollows the specified playlist. Returns nothing
269272
- **[PlayerAPI (SpotifyClientAPI.player)](https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/)**
270273
The methods in this API are in beta and in flux as per Spotify. They will be documented in the near future.
271-
- **[ClientPlaylistsAPI (SpotifyClientAPI.clientPlaylists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
274+
- **[ClientPlaylistsAPI (SpotifyClientAPI.playlists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
272275
1. `createPlaylist` creates the playlist and returns its full Playlist representation
273276
2. `addTrackToPlaylist` adds the entered tracks to the playlist. Returns nothing
274277
3. `changePlaylistDescription` changes the description of the playlist. Returns nothing

0 commit comments

Comments
 (0)