Skip to content

Commit e132808

Browse files
authored
Merge pull request #84 from adamint/dev
Update player endpoints, augment existing model documentation, add API documentation
2 parents e85120b + 89075bb commit e132808

File tree

294 files changed

+52965
-6057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+52965
-6057
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,20 @@ 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.1.2</version>
32-
</dependency>
33-
```
34-
3526
### Gradle
3627
```
37-
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.1.2'
28+
repositories {
29+
jcenter()
30+
}
31+
32+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.2.0'
3833
```
3934

40-
To use the latest snapshot instead, you must add the Jitpack repository
35+
To use the latest snapshot instead, you must add the Jitpack repository as well
4136
```
4237
repositories {
43-
maven { url 'https://jitpack.io' }
38+
maven { url 'https://jitpack.io' }
39+
jcenter()
4440
}
4541
```
4642
Then, you can use the following:
@@ -50,21 +46,39 @@ dependencies {
5046
}
5147
```
5248

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+
5364
#### Android
54-
This library should work out of the box on Android.
65+
This library will work out of the box on Android.
5566

5667
## Documentation
57-
The `spotify-web-api-kotlin` KDocs are hosted at https://adamint.github.io/spotify-web-api-kotlin
68+
The `spotify-web-api-kotlin` JavaDocs are hosted at https://adamint.github.io/spotify-web-api-kotlin
5869

5970
## Creating a SpotifyAPI or SpotifyClientAPI object
6071
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.
6172

6273
### SpotifyAPI
63-
The SpotifyAPI `Token` automatically regenerates when needed.
64-
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+
6579
```kotlin
66-
import com.adamratzman.spotify.main.SpotifyScope
67-
import com.adamratzman.spotify.main.spotifyApi
80+
import com.adamratzman.spotify.SpotifyScope
81+
import com.adamratzman.spotify.spotifyApi
6882

6983
spotifyApi {
7084
credentials {
@@ -75,25 +89,25 @@ spotifyApi {
7589
```
7690
*Note:* You are **unable** to use any client endpoint without authenticating with the methods below.
7791

78-
### SpotifyClientAPI
79-
All endpoints inside `SpotifyAPI` can be accessed within the `SpotifyClientAPI`.
92+
#### SpotifyClientAPI
93+
The `SpotifyClientAPI` is a superset of `SpotifyAPI`.
94+
8095
Its automatic refresh is available *only* when building with
81-
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.
8297

8398
You have two options when building the Client API.
84-
1. You can use [Implicit Grant access tokens](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow) with
85-
`Builder.buildToken(token: String)`. However, this is a one-time token that cannot be refreshed.
86-
2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow). We provide a method
87-
with `Builder.buildAuthCode(code: String, automaticRefresh: Boolean)`to generate the flow url with Builder.getAuthUrl(vararg spotifyScopes: Scope), allowing you to request specific
88-
spotifyScopes. This library does not provide a method to retrieve the code from your
89-
callback URL. You must implement that with a web server. This method allows you
90-
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.
91105

92106
## What is the SpotifyRestAction class?
93-
I wanted users of this library to have as much flexibility as possible. This
94-
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,
95109
due to this, you **must** call one of the provided methods in order for the call
96-
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,
97111
- `complete()` blocks the current thread and returns the result
98112
- `queue()` executes and immediately returns
99113
- `queue(consumer: (T) -> Unit)` executes the provided callback as soon as the request
@@ -131,7 +145,7 @@ Just like with PagingObjects, you can get the next page of items with `getNext`.
131145
provided implementation of `after` in this library. You will need to do it yourself, if necessary.
132146

133147
#### LinkedResults
134-
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
135149
list of objects. With this, we have access to its Spotify API url (with `href`), and we provide simple methods to parse
136150
that url.
137151

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

142156
```kotlin
143-
import com.adamratzman.spotify.main.SpotifyScope
144-
import com.adamratzman.spotify.main.spotifyApi
157+
import com.adamratzman.spotify.SpotifyScope
158+
import com.adamratzman.spotify.spotifyApi
145159

146-
val spotifyApi = spotifyApi {
160+
val api = spotifyApi {
147161
credentials {
148162
clientId = "YOUR_CLIENT_ID"
149163
clientSecret = "YOUR_CLIENT_SECRET"
150164
}
151165
}.buildCredentialed()
152166

153167
// block and print out the names of the twenty most similar songs to the search
154-
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())
155169

156170
// now, let's do it asynchronously
157-
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()) }
158172

159-
// simple, right? what about if we want to print ou the featured playlists message from the "Overview" tab?
160-
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)
161175

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

165-
spotifyApi.search.searchArtist("Bénabar").complete()[0].id.let { id ->
166-
spotifyApi.artists.getArtistTopTracks(id).complete().joinToString { it.name }.let { println(it) }
167-
}
179+
val benabarId = api.search.searchArtist("Bénabar").complete()[0].id
180+
181+
println(api.artists.getArtistTopTracks(benabarId).complete().joinToString { it.name })
168182
```
169183

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

179-
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
180194
in your market!
181195

182196
### Contributing
@@ -202,9 +216,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md)
202216
5. `getPlaylistsForCategory` returns a `PagingObject` of top simple playlists for the specified category id
203217
6. `getRecommendations` returns a RecommendationResponse. Parameters include seed artists, genres, tracks, and
204218
tuneable track attributes listed [here](https://developer.spotify.com/web-api/complete-recommendations/)
205-
- **[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/)**
206220
1. `doUsersFollowPlaylist` returns a List of Booleans corresponding to the order in which ids were specified
207-
- **[PlaylistsAPI (SpotifyAPI.playlists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
221+
- **[PlaylistAPI (SpotifyAPI.playlist)](https://developer.spotify.com/web-api/playlist-endpoints/)**
208222
1. `getPlaylists` returns a `PagingObject` of SimplePlaylists the user has
209223
2. `getPlaylist` returns a full Playlist object of the specified user and playlist id
210224
3. `getPlaylistTracks` returns a `LinkedResult` (linked with the playlist url) of **PlaylistTrack**s
@@ -232,9 +246,9 @@ links provided for each API below
232246
- **[PersonalizationAPI (SpotifyClientAPI.personalization)](https://developer.spotify.com/web-api/web-api-personalization-endpoints/)**
233247
1. `getTopArtists` returns an Artist `PagingObject` representing the most played Artists by the user
234248
2. `getTopTracks` returns a Track `PagingObject` representing the most played Tracks by the user
235-
- **[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/)**
236250
1. `getUserInformation` returns SpotifyUserInformation object, a much more detailed version of the public user object.
237-
- **[UserLibraryAPI (SpotifyClientAPI.userLibrary)](https://developer.spotify.com/web-api/library-endpoints/)**
251+
- **[UserLibraryAPI (SpotifyClientAPI.library)](https://developer.spotify.com/web-api/library-endpoints/)**
238252
1. `getSavedTracks` returns a `PagingObject` of saved tracks in the user's library
239253
2. `getSavedAlbums` returns a `PagingObject` of saved albums in the user's library
240254
3. `savedTracksContains` returns an ordered List of Booleans of whether the track exists in the user's library
@@ -245,7 +259,7 @@ links provided for each API below
245259
6. `saveAlbums` saves the entered albums to the user's library. Returns nothing
246260
7. `removeSavedTracks` removes the entered tracks from the user's library. Nothing happens if the track is not found. Returns nothing
247261
8. `removeSavedAlbums` removes the entered albums from the user's library. Nothing happens if the album is not found in the library. Returns nothing
248-
- **[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/)**
249263
1. `followingUsers` returns an ordered List of Booleans representing if the user follows the specified users
250264
2. `followingArtists` returns an ordered List of Booleans representing if the user follows the specified artists
251265
3. `getFollowedArtists` returns a [Cursor-Based Paging Object](https://developer.spotify.com/web-api/object-model/#cursor-based-paging-object) of followed Artists.
@@ -257,7 +271,7 @@ links provided for each API below
257271
9. `unfollowPlaylist` unfollows the specified playlist. Returns nothing
258272
- **[PlayerAPI (SpotifyClientAPI.player)](https://developer.spotify.com/web-api/web-api-connect-endpoint-reference/)**
259273
The methods in this API are in beta and in flux as per Spotify. They will be documented in the near future.
260-
- **[ClientPlaylistsAPI (SpotifyClientAPI.clientPlaylists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
274+
- **[ClientPlaylistsAPI (SpotifyClientAPI.playlists)](https://developer.spotify.com/web-api/playlist-endpoints/)**
261275
1. `createPlaylist` creates the playlist and returns its full Playlist representation
262276
2. `addTrackToPlaylist` adds the entered tracks to the playlist. Returns nothing
263277
3. `changePlaylistDescription` changes the description of the playlist. Returns nothing

TESTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Testing
22

3-
We use [Spek](https://github.com/spekframework/spek) to run unit tests.
3+
We use [Spek](https://github.com/spekframework/spek) to run unit tests. You must add Maven Central to the gradle repositories
4+
in order to pull Spek.
45

56
To run **only** public endpoint tests, run
67

build.gradle

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.21'
2+
ext.kotlin_version = '1.3.31'
33
ext.dokka_version = '0.9.17'
44

55
repositories { jcenter() }
@@ -12,47 +12,46 @@ buildscript {
1212

1313

1414
plugins {
15-
id "com.diffplug.gradle.spotless" version "3.16.0"
15+
id "com.diffplug.gradle.spotless" version "3.23.0"
1616
id "base"
17-
id "io.codearte.nexus-staging" version "0.12.0"
17+
id "io.codearte.nexus-staging" version "0.20.0"
1818
id "com.bmuschko.nexus" version "2.3.1"
1919
}
2020

2121
apply plugin: 'kotlin'
2222
apply plugin: 'org.jetbrains.dokka'
2323

2424
group 'com.adamratzman'
25-
version '2.1.2'
25+
version '2.2.0'
2626

2727
archivesBaseName = 'spotify-api-kotlin'
2828

2929
sourceCompatibility = 1.8
3030

3131
repositories {
32-
mavenCentral()
3332
jcenter()
34-
maven { url "https://dl.bintray.com/spekframework/spek" }
3533
}
3634

3735
dependencies {
3836
// Actual library dependencies
39-
implementation 'com.beust:klaxon:5.0.5'
37+
compile 'com.beust:klaxon:5.0.5'
38+
compile 'com.neovisionaries:nv-i18n:1.25'
4039

4140
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4241
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
4342

4443
// Spek testing requirements
45-
testImplementation('org.spekframework.spek2:spek-dsl-jvm:2.0.0') {
44+
testCompile('org.spekframework.spek2:spek-dsl-jvm:2.0.0') {
4645
exclude group: 'org.jetbrains.kotlin'
4746
}
4847
testRuntimeOnly('org.spekframework.spek2:spek-runner-junit5:2.0.0') {
4948
exclude group: 'org.junit.platform'
5049
exclude group: 'org.jetbrains.kotlin'
5150
}
5251

53-
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.0')
54-
testImplementation(group: 'org.json', name: 'json', version: '20180130')
55-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
52+
testCompile('org.junit.jupiter:junit-jupiter-api:5.4.2')
53+
testCompile(group: 'org.json', name: 'json', version: '20180130')
54+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
5655
}
5756

5857
dokka {
@@ -73,7 +72,7 @@ dokka {
7372
spotless {
7473
kotlin {
7574
ktlint()
76-
licenseHeader '/* Created by Adam Ratzman (2018) */' // License header
75+
licenseHeader '/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */' // License header
7776
}
7877
}
7978

0 commit comments

Comments
 (0)