Skip to content

Commit 733fbc6

Browse files
authored
Merge pull request #8 from adamint/develop
Develop
2 parents 0d8884c + 7dede6a commit 733fbc6

File tree

24 files changed

+262
-163
lines changed

24 files changed

+262
-163
lines changed

.circleci/config.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Java Gradle CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: circleci/openjdk:8-jdk
11+
12+
# Specify service dependencies here if necessary
13+
# CircleCI maintains a library of pre-built images
14+
# documented at https://circleci.com/docs/2.0/circleci-images/
15+
# - image: circleci/postgres:9.4
16+
17+
working_directory: ~/repo
18+
19+
environment:
20+
# Customize the JVM maximum heap limit
21+
JVM_OPTS: -Xmx3200m
22+
TERM: dumb
23+
24+
steps:
25+
- checkout
26+
27+
# Download and cache dependencies
28+
- restore_cache:
29+
keys:
30+
- v1-dependencies-{{ checksum "build.gradle" }}
31+
# fallback to using the latest cache if no exact match is found
32+
- v1-dependencies-
33+
34+
- run: gradle dependencies
35+
36+
- save_cache:
37+
paths:
38+
- ~/.gradle
39+
key: v1-dependencies-{{ checksum "build.gradle" }}
40+
41+
# run tests!
42+
- run: gradle test

.idea/modules/SpotifyKotlinWrapper.iml

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

.idea/modules/SpotifyKotlinWrapper_main.iml

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

.idea/modules/SpotifyKotlinWrapper_test.iml

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

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.adamratzman'
2-
version '1.0.2'
2+
version '1.0.3'
33

44
buildscript {
55
ext.kotlin_version = '1.2.31'

src/main/kotlin/com/adamratzman/spotify/endpoints/priv/follow/ClientFollowAPI.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3030
*/
3131
fun isFollowingUsers(vararg userIds: String): SpotifyRestAction<List<Boolean>> {
3232
return toAction(Supplier {
33-
get("https://api.spotify.com/v1/me/following/contains?type=user&ids=${userIds.joinToString(",") { it.encode() }}").toObject<List<Boolean>>(api)
33+
get(EndpointBuilder("/me/following/contains").with("type", "user")
34+
.with("ids", userIds.joinToString(",") { it.encode() }).build()).toObject<List<Boolean>>(api)
3435
})
3536
}
3637

@@ -56,7 +57,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5657
*/
5758
fun isFollowingArtists(vararg artistIds: String): SpotifyRestAction<List<Boolean>> {
5859
return toAction(Supplier {
59-
get("https://api.spotify.com/v1/me/following/contains?type=artist&ids=${artistIds.joinToString(",") { it.encode() }}").toObject<List<Boolean>>(api)
60+
get(EndpointBuilder("/me/following/contains").with("type", "artist")
61+
.with("ids", artistIds.joinToString(",") { it.encode() }).build()).toObject<List<Boolean>>(api)
6062
})
6163
}
6264

@@ -66,14 +68,14 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6668
* @return [CursorBasedPagingObject] ([Information about them](https://github.com/adamint/spotify-web-api-kotlin/blob/master/README.md#the-benefits-of-linkedresults-pagingobjects-and-cursor-based-paging-objects)
6769
* with full [Artist] objects
6870
*/
69-
fun getFollowedArtists(): SpotifyRestAction<CursorBasedPagingObject<Artist>> {
71+
fun getFollowedArtists(limit: Int? = null, after: String? = null): SpotifyRestAction<CursorBasedPagingObject<Artist>> {
7072
return toAction(Supplier {
71-
get("https://api.spotify.com/v1/me/following?type=artist").toCursorBasedPagingObject<Artist>("artists", api)
73+
get(EndpointBuilder("/me/following").with("type", "artist").with("limit", limit).with("after", after).build())
74+
.toCursorBasedPagingObject<Artist>("artists", this)
7275
})
7376
}
7477

75-
fun getFollowedUsers(): SpotifyRestAction<SpotifyPublicUser>
76-
= throw NotImplementedError("Though Spotify will implement this in the future, it is not currently supported.")
78+
fun getFollowedUsers(): SpotifyRestAction<SpotifyPublicUser> = throw NotImplementedError("Though Spotify will implement this in the future, it is not currently supported.")
7779

7880
/**
7981
* Add the current user as a follower of another user
@@ -93,7 +95,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
9395
*/
9496
fun followUsers(vararg userIds: String): SpotifyRestAction<Unit> {
9597
return toAction(Supplier {
96-
put("https://api.spotify.com/v1/me/following?type=user&ids=${userIds.joinToString(",") { it.encode() }}")
98+
put(EndpointBuilder("/me/following").with("type", "user")
99+
.with("ids", userIds.joinToString(",") { it.encode() }).build())
97100
Unit
98101
})
99102
}
@@ -116,7 +119,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
116119
*/
117120
fun followArtists(vararg artistIds: String): SpotifyRestAction<Unit> {
118121
return toAction(Supplier {
119-
put("https://api.spotify.com/v1/me/following?type=artist&ids=${artistIds.joinToString(",")}")
122+
put(EndpointBuilder("/me/following").with("type", "artist")
123+
.with("ids", artistIds.joinToString(",") { it.encode() }).build())
120124
Unit
121125
})
122126
}
@@ -134,7 +138,7 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
134138
*/
135139
fun followPlaylist(ownerId: String, playlistId: String, followPublicly: Boolean = true): SpotifyRestAction<Unit> {
136140
return toAction(Supplier {
137-
put("https://api.spotify.com/v1/users/$ownerId/playlists/$playlistId/followers", "{\"public\": $followPublicly}")
141+
put(EndpointBuilder("/users/$ownerId/playlists/$playlistId/followers").build(), "{\"public\": $followPublicly}")
138142
Unit
139143
})
140144

@@ -162,7 +166,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
162166
*/
163167
fun unfollowUsers(vararg userIds: String): SpotifyRestAction<Unit> {
164168
return toAction(Supplier {
165-
delete("https://api.spotify.com/v1/me/following?type=user&ids=${userIds.joinToString(",") { it.encode() }}")
169+
delete(EndpointBuilder("/me/following").with("type", "user")
170+
.with("ids", userIds.joinToString(",") { it.encode() }).build())
166171
Unit
167172
})
168173
}
@@ -189,7 +194,8 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
189194
*/
190195
fun unfollowArtists(vararg artistIds: String): SpotifyRestAction<Unit> {
191196
return toAction(Supplier {
192-
delete("https://api.spotify.com/v1/me/following?type=artist&ids=${artistIds.joinToString(",")}")
197+
delete(EndpointBuilder("/me/following").with("type", "artist")
198+
.with("ids", artistIds.joinToString(",") { it.encode() }).build())
193199
Unit
194200
})
195201
}
@@ -204,7 +210,7 @@ class ClientFollowAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
204210
*/
205211
fun unfollowPlaylist(ownerId: String, playlistId: String): SpotifyRestAction<Unit> {
206212
return toAction(Supplier {
207-
delete("https://api.spotify.com/v1/users/$ownerId/playlists/$playlistId/followers")
213+
delete(EndpointBuilder("/users/$ownerId/playlists/$playlistId/followers").build())
208214
Unit
209215
})
210216
}

src/main/kotlin/com/adamratzman/spotify/endpoints/priv/library/ClientLibraryAPI.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.adamratzman.spotify.endpoints.priv.library
22

33
import com.adamratzman.spotify.main.SpotifyAPI
44
import com.adamratzman.spotify.utils.*
5-
import com.sun.org.apache.xpath.internal.operations.Bool
65
import java.util.function.Supplier
76

87
/**
@@ -14,9 +13,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
1413
*
1514
* @return Paging Object of [SavedTrack] ordered by position in library
1615
*/
17-
fun getSavedTracks(): SpotifyRestAction<PagingObject<SavedTrack>> {
16+
fun getSavedTracks(limit: Int? = null, offset: Int? = null, market: Market? = null): SpotifyRestAction<PagingObject<SavedTrack>> {
1817
return toAction(Supplier {
19-
get("https://api.spotify.com/v1/me/tracks").toPagingObject<SavedTrack>(api = api)
18+
get(EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.code)
19+
.build()).toPagingObject<SavedTrack>(endpoint = this)
2020
})
2121
}
2222

@@ -27,7 +27,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2727
*/
2828
fun getSavedAlbums(): SpotifyRestAction<PagingObject<SavedAlbum>> {
2929
return toAction(Supplier {
30-
get("https://api.spotify.com/v1/me/albums").toPagingObject<SavedAlbum>(api = api)
30+
get(EndpointBuilder("/me/albums").build()).toPagingObject<SavedAlbum>(endpoint = this)
3131
})
3232
}
3333

@@ -49,7 +49,8 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4949
*/
5050
fun doesLibraryContainTracks(vararg ids: String): SpotifyRestAction<List<Boolean>> {
5151
return toAction(Supplier {
52-
get("https://api.spotify.com/v1/me/tracks/contains?ids=${ids.joinToString(",") { it.encode() }}").toObject<List<Boolean>>(api)
52+
get(EndpointBuilder("/me/tracks/contains").with("ids", ids.joinToString(",") { it.encode() })
53+
.build()).toObject<List<Boolean>>(api)
5354
})
5455
}
5556

@@ -71,7 +72,8 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
7172
*/
7273
fun doesLibraryContainAlbums(vararg ids: String): SpotifyRestAction<List<Boolean>> {
7374
return toAction(Supplier {
74-
get("https://api.spotify.com/v1/me/albums/contains?ids=${ids.joinToString(",") { it.encode() }}").toObject<List<Boolean>>(api)
75+
get(EndpointBuilder("/me/albums/contains").with("ids", ids.joinToString(",") { it.encode() })
76+
.build()).toObject<List<Boolean>>(api)
7577
})
7678
}
7779

@@ -93,7 +95,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
9395
*/
9496
fun addTracksToLibrary(vararg ids: String): SpotifyRestAction<Unit> {
9597
return toAction(Supplier {
96-
put("https://api.spotify.com/v1/me/tracks?ids=${ids.joinToString(",") { it.encode() }}")
98+
put(EndpointBuilder("/me/tracks").with("ids", ids.joinToString(",") { it.encode() }).build())
9799
Unit
98100
})
99101
}
@@ -116,7 +118,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
116118
*/
117119
fun addAlbumsToLibrary(vararg ids: String): SpotifyRestAction<Unit> {
118120
return toAction(Supplier {
119-
put("https://api.spotify.com/v1/me/albums?ids=${ids.joinToString(",") { it.encode() }}")
121+
put(EndpointBuilder("/me/albums").with("ids", ids.joinToString(",") { it.encode() }).build())
120122
Unit
121123
})
122124
}
@@ -139,7 +141,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
139141
*/
140142
fun removeTracksFromLibrary(vararg ids: String): SpotifyRestAction<Unit> {
141143
return toAction(Supplier {
142-
delete("https://api.spotify.com/v1/me/tracks?ids=${ids.joinToString(",") { it.encode() }}")
144+
delete(EndpointBuilder("/me/tracks").with("ids", ids.joinToString(",") { it.encode() }).build())
143145
Unit
144146
})
145147
}
@@ -162,7 +164,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
162164
*/
163165
fun removeAlbumsFromLibrary(vararg ids: String): SpotifyRestAction<Unit> {
164166
return toAction(Supplier {
165-
delete("https://api.spotify.com/v1/me/albums?ids=${ids.joinToString(",") { it.encode() }}")
167+
delete(EndpointBuilder("/me/albums").with("ids", ids.joinToString(",") { it.encode() }).build())
166168
Unit
167169
})
168170
}

src/main/kotlin/com/adamratzman/spotify/endpoints/priv/personalization/PersonalizationAPI.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import java.util.function.Supplier
88
* Endpoints for retrieving information about the user’s listening habits.
99
*/
1010
class PersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
11+
enum class TimeRange(val id: String) {
12+
LONG_TERM("long_term"), MEDIUM_TERM("medium_term"), SHORT_TERM("short_term");
13+
override fun toString() = id
14+
}
15+
1116
/**
1217
* Get the current user’s top artists based on calculated affinity.
1318
* Affinity is a measure of the expected preference a user has for a particular track or artist. It is based on user
@@ -20,9 +25,10 @@ class PersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2025
*
2126
* @return [PagingObject] of full [Artist] objects sorted by affinity
2227
*/
23-
fun getTopArtists(): SpotifyRestAction<PagingObject<Artist>> {
28+
fun getTopArtists(limit: Int? = null, offset: Int? = null, timeRange: TimeRange? = null): SpotifyRestAction<PagingObject<Artist>> {
2429
return toAction(Supplier {
25-
get("https://api.spotify.com/v1/me/top/artists").toPagingObject<Artist>(api = api)
30+
get(EndpointBuilder("/me/top/artists").with("limit", limit).with("offset", offset)
31+
.with("time_range", timeRange).build()).toPagingObject<Artist>(endpoint = this)
2632
})
2733
}
2834

@@ -38,9 +44,10 @@ class PersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3844
*
3945
* @return [PagingObject] of full [Track] objects sorted by affinity
4046
*/
41-
fun getTopTracks(): SpotifyRestAction<PagingObject<Track>> {
47+
fun getTopTracks(limit: Int? = null, offset: Int? = null, timeRange: TimeRange? = null): SpotifyRestAction<PagingObject<Track>> {
4248
return toAction(Supplier {
43-
get("https://api.spotify.com/v1/me/top/tracks").toPagingObject<Track>(api = api)
49+
get(EndpointBuilder("/me/top/tracks").with("limit", limit).with("offset", offset)
50+
.with("time_range", timeRange).build()).toPagingObject<Track>(endpoint = this)
4451
})
4552
}
4653

0 commit comments

Comments
 (0)