Skip to content

Commit a8a7b34

Browse files
committed
add full search functional;ity
1 parent f51016e commit a8a7b34

File tree

18 files changed

+158
-67
lines changed

18 files changed

+158
-67
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636

3737
compile "com.squareup.moshi:moshi:1.8.0"
3838
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
39+
compile group: 'org.json', name: 'json', version: '20190722'
3940

4041
compile "com.google.http-client:google-http-client:1.31.0"
4142

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientFollowingAPI.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.adamratzman.spotify.models.ArtistURI
1414
import com.adamratzman.spotify.models.CursorBasedPagingObject
1515
import com.adamratzman.spotify.models.PlaylistURI
1616
import com.adamratzman.spotify.models.UserURI
17-
import com.adamratzman.spotify.models.serialization.toArray
17+
import com.adamratzman.spotify.models.serialization.toList
1818
import com.adamratzman.spotify.models.serialization.toCursorBasedPagingObject
1919
import java.util.function.Supplier
2020

@@ -77,7 +77,7 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
7777
get(
7878
EndpointBuilder("/me/following/contains").with("type", "user")
7979
.with("ids", users.joinToString(",") { UserURI(it).id.encode() }).toString()
80-
).toArray(api)
80+
).toList<Boolean>(api)
8181
})
8282
}
8383

@@ -112,7 +112,7 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
112112
get(
113113
EndpointBuilder("/me/following/contains").with("type", "artist")
114114
.with("ids", artists.joinToString(",") { ArtistURI(it).id.encode() }).toString()
115-
).toArray(api)
115+
).toList<Boolean>(api)
116116
})
117117
}
118118

@@ -137,7 +137,7 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
137137
"after",
138138
after
139139
).toString()
140-
).toCursorBasedPagingObject("artists", this)
140+
).toCursorBasedPagingObject<Artist>("artists", this)
141141
})
142142
}
143143

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientLibraryAPI.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.adamratzman.spotify.models.PagingObject
1313
import com.adamratzman.spotify.models.SavedAlbum
1414
import com.adamratzman.spotify.models.SavedTrack
1515
import com.adamratzman.spotify.models.TrackURI
16-
import com.adamratzman.spotify.models.serialization.toArray
16+
import com.adamratzman.spotify.models.serialization.toList
1717
import com.adamratzman.spotify.models.serialization.toPagingObject
1818
import com.neovisionaries.i18n.CountryCode
1919
import java.util.function.Supplier
@@ -43,7 +43,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4343
get(
4444
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.name)
4545
.toString()
46-
).toPagingObject(endpoint = this)
46+
).toPagingObject<SavedTrack>(endpoint = this)
4747
})
4848
}
4949

@@ -68,7 +68,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6868
get(
6969
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.name)
7070
.toString()
71-
).toPagingObject(endpoint = this)
71+
).toPagingObject<SavedAlbum>(endpoint = this)
7272
})
7373
}
7474

@@ -103,7 +103,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
103103
get(
104104
EndpointBuilder("/me/$type/contains").with("ids", ids.joinToString(",") { type.id(it).encode() })
105105
.toString()
106-
).toArray(api)
106+
).toList<Boolean>(api)
107107
})
108108
}
109109

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPersonalizationAPI.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5757
get(
5858
EndpointBuilder("/me/top/artists").with("limit", limit).with("offset", offset)
5959
.with("time_range", timeRange).toString()
60-
)
61-
.toPagingObject(endpoint = this)
60+
).toPagingObject<Artist>(endpoint = this)
6261
})
6362
}
6463

@@ -90,8 +89,7 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
9089
get(
9190
EndpointBuilder("/me/top/tracks").with("limit", limit).with("offset", offset)
9291
.with("time_range", timeRange).toString()
93-
)
94-
.toPagingObject(endpoint = this)
92+
).toPagingObject<Track>(endpoint = this)
9593
})
9694
}
9795
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlayerAPI.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3838
*/
3939
fun getDevices(): SpotifyRestAction<List<Device>> {
4040
return toAction(Supplier {
41-
get(EndpointBuilder("/me/player/devices").toString()).toInnerObject(
42-
"devices"
43-
)
41+
get(EndpointBuilder("/me/player/devices").toString()).toInnerObject<List<Device>>("devices")
4442
})
4543
}
4644

@@ -78,9 +76,7 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
7876
get(
7977
EndpointBuilder("/me/player/recently-played")
8078
.with("limit", limit).with("before", before).with("after", after).toString()
81-
).toCursorBasedPagingObject(
82-
endpoint = this
83-
)
79+
).toCursorBasedPagingObject<PlayHistory>(endpoint = this)
8480
})
8581
}
8682

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlaylistAPI.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistAPI(api) {
7070
post(
7171
EndpointBuilder("/users/${UserURI(user).id.encode()}/playlists").toString(),
7272
json.toJson()
73-
).toObject(api)
73+
).toObject<Playlist>(api)
7474
})
7575
}
7676

@@ -173,7 +173,7 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistAPI(api) {
173173
if (offset != null && offset !in 0..100000) throw IllegalArgumentException("Offset must be between 0 and 100,000. Provided $limit")
174174
return toActionPaging(Supplier {
175175
get(EndpointBuilder("/me/playlists").with("limit", limit).with("offset", offset).toString())
176-
.toPagingObject(endpoint = this)
176+
.toPagingObject<SimplePlaylist>(endpoint = this)
177177
})
178178
}
179179

@@ -244,7 +244,7 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistAPI(api) {
244244
put(
245245
EndpointBuilder("/playlists/${PlaylistURI(playlist).id.encode()}/tracks").toString(),
246246
json.toJson()
247-
).toObject(api)
247+
).toObject<Snapshot>(api)
248248
})
249249
}
250250

@@ -423,7 +423,7 @@ class ClientPlaylistAPI(api: SpotifyAPI) : PlaylistAPI(api) {
423423
}.let { json.put("tracks", it) }
424424
delete(
425425
EndpointBuilder("/playlists/${PlaylistURI(playlist).id}/tracks").toString(), body = json.toJson()
426-
).toObject(api)
426+
).toObject<Snapshot>(api)
427427
})
428428
}
429429

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientUserAPI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ClientUserAPI(api: SpotifyAPI) : UserAPI(api) {
2626
*/
2727
fun getUserProfile(): SpotifyRestAction<SpotifyUserInformation> {
2828
return toAction(Supplier {
29-
get(EndpointBuilder("/me").toString()).toObject(api)
29+
get(EndpointBuilder("/me").toString()).toObject<SpotifyUserInformation>(api)
3030
})
3131
}
3232
}

src/main/kotlin/com/adamratzman/spotify/endpoints/public/AlbumAPI.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class AlbumAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3434
fun getAlbum(album: String, market: CountryCode? = null): SpotifyRestAction<Album?> {
3535
return toAction(Supplier {
3636
catch {
37-
get(EndpointBuilder("/albums/${AlbumURI(album).id}").with("market", market?.name).toString())
38-
.toObject(api)
37+
get(EndpointBuilder("/albums/${AlbumURI(album).id}").with("market", market?.name).toString()).toObject<Album>(api)
3938
}
4039
})
4140
}
@@ -82,7 +81,7 @@ class AlbumAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
8281
offset
8382
).with("market", market?.name)
8483
.toString()
85-
).toPagingObject(endpoint = this)
84+
).toPagingObject<SimpleTrack>(endpoint = this)
8685
})
8786
}
8887
}

src/main/kotlin/com/adamratzman/spotify/endpoints/public/ArtistsAPI.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3636
fun getArtist(artist: String): SpotifyRestAction<Artist?> {
3737
return toAction(Supplier {
3838
catch {
39-
get(EndpointBuilder("/artists/${ArtistURI(artist).id.encode()}").toString())
40-
.toObject(api)
39+
get(EndpointBuilder("/artists/${ArtistURI(artist).id.encode()}").toString()).toObject<Artist>(api)
4140
}
4241
})
4342
}
@@ -85,7 +84,7 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
8584
offset
8685
).with("market", market?.name)
8786
.with("include_groups", include.joinToString(",") { it.keyword }).toString()
88-
).toPagingObject(null, this)
87+
).toPagingObject<SimpleAlbum>(null, this)
8988
})
9089
}
9190

@@ -120,7 +119,7 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
120119
"country",
121120
market.name
122121
).toString()
123-
).toInnerArray("tracks")
122+
).toInnerArray<Track>("tracks")
124123
})
125124
}
126125

src/main/kotlin/com/adamratzman/spotify/endpoints/public/BrowseAPI.kt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3939
*/
4040
fun getAvailableGenreSeeds(): SpotifyRestAction<List<String>> {
4141
return toAction(Supplier {
42-
get(EndpointBuilder("/recommendations/available-genre-seeds").toString()).toInnerArray(
43-
"genres"
44-
)
42+
get(EndpointBuilder("/recommendations/available-genre-seeds").toString()).toInnerArray<String>("genres")
4543
})
4644
}
4745

@@ -67,9 +65,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6765
"country",
6866
market?.name
6967
).toString()
70-
).toPagingObject(
71-
"albums", endpoint = this
72-
)
68+
).toPagingObject<SimpleAlbum>("albums", endpoint = this)
7369
})
7470
}
7571

@@ -107,7 +103,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
107103
.with("locale", locale).with("timestamp", timestamp?.let {
108104
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date.from(Instant.ofEpochMilli(timestamp)))
109105
}).toString()
110-
).toObject(api)
106+
).toObject<FeaturedPlaylists>(api)
111107
})
112108
}
113109

@@ -138,9 +134,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
138134
"market",
139135
market?.name
140136
).with("locale", locale).toString()
141-
).toPagingObject(
142-
"categories", endpoint = this
143-
)
137+
).toPagingObject<SpotifyCategory>("categories", endpoint = this)
144138
})
145139
}
146140

@@ -166,7 +160,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
166160
get(
167161
EndpointBuilder("/browse/categories/${categoryId.encode()}").with("market", market?.name)
168162
.with("locale", locale).toString()
169-
).toObject(api)
163+
).toObject<SpotifyCategory>(api)
170164
})
171165
}
172166

@@ -194,7 +188,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
194188
limit
195189
).with("offset", offset)
196190
.with("market", market?.name).toString()
197-
).toPagingObject("playlists", endpoint = this)
191+
).toPagingObject<SimplePlaylist>("playlists", endpoint = this)
198192
})
199193
}
200194

@@ -304,7 +298,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
304298
targetAttributes.forEach { (attribute, value) -> builder.with("target_$attribute", value) }
305299
minAttributes.forEach { (attribute, value) -> builder.with("min_$attribute", value) }
306300
maxAttributes.forEach { (attribute, value) -> builder.with("max_$attribute", value) }
307-
get(builder.toString()).toObject(api)
301+
get(builder.toString()).toObject<RecommendationResponse>(api)
308302
})
309303
}
310304
}

0 commit comments

Comments
 (0)