Skip to content

Commit a54eb52

Browse files
authored
Merge pull request #119 from adamint/dev
update search endpoint, fix isTokenValid logic
2 parents a74219d + 8f55c1f commit a54eb52

File tree

17 files changed

+148
-57
lines changed

17 files changed

+148
-57
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repositories {
2828
jcenter()
2929
}
3030
31-
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.3.06'
31+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.3.08'
3232
```
3333

3434
To use the latest snapshot instead, you must add the Jitpack repository as well
@@ -50,7 +50,7 @@ dependencies {
5050
<dependency>
5151
<groupId>com.adamratzman</groupId>
5252
<artifactId>spotify-api-kotlin</artifactId>
53-
<version>2.3.06</version>
53+
<version>2.3.08</version>
5454
</dependency>
5555
5656
<repository>

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ apply plugin: 'kotlin'
2222
apply plugin: 'org.jetbrains.dokka'
2323

2424
group 'com.adamratzman'
25-
version '2.3.06'
25+
version '2.3.08'
2626

2727
archivesBaseName = 'spotify-api-kotlin'
2828

@@ -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/SpotifyAPI.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
3131
import java.util.concurrent.Executors
3232
import java.util.concurrent.ScheduledExecutorService
3333

34-
internal val base = "https://api.spotify.com/v1"
34+
internal const val base = "https://api.spotify.com/v1"
3535

3636
/**
3737
* Represents an instance of the Spotify API client, with common
@@ -171,7 +171,7 @@ abstract class SpotifyAPI internal constructor(
171171
* @return [TokenValidityResponse] containing whether this token is valid, and if not, an Exception explaining why
172172
*/
173173
fun isTokenValid(makeTestRequest: Boolean = true): TokenValidityResponse {
174-
if (!token.shouldRefresh()) return TokenValidityResponse(false, SpotifyException("Token expired"))
174+
if (token.shouldRefresh()) return TokenValidityResponse(false, SpotifyException("Token needs to be refreshed (is it expired?)"))
175175
if (!makeTestRequest) return TokenValidityResponse(true, null)
176176

177177
return try {

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

Lines changed: 3 additions & 3 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<Boolean>(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<Boolean>(api)
115+
).toList<Boolean>(api)
116116
})
117117
}
118118

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

Lines changed: 2 additions & 2 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
@@ -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<Boolean>(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<Artist>(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<Track>(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<List<Device>>(
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<PlayHistory>(
82-
endpoint = this
83-
)
79+
).toCursorBasedPagingObject<PlayHistory>(endpoint = this)
8480
})
8581
}
8682

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

Lines changed: 1 addition & 2 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<Album>(api)
37+
get(EndpointBuilder("/albums/${AlbumURI(album).id}").with("market", market?.name).toString()).toObject<Album>(api)
3938
}
4039
})
4140
}

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

Lines changed: 1 addition & 2 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<Artist>(api)
39+
get(EndpointBuilder("/artists/${ArtistURI(artist).id.encode()}").toString()).toObject<Artist>(api)
4140
}
4241
})
4342
}

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

Lines changed: 6 additions & 12 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<String>(
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<SimpleAlbum>(
71-
"albums", endpoint = this
72-
)
68+
).toPagingObject<SimpleAlbum>("albums", endpoint = this)
7369
})
7470
}
7571

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

@@ -301,9 +295,9 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
301295
.with("seed_artists", seedArtists?.joinToString(",") { ArtistURI(it).id.encode() })
302296
.with("seed_genres", seedGenres?.joinToString(",") { it.encode() })
303297
.with("seed_tracks", seedTracks?.joinToString(",") { TrackURI(it).id.encode() })
304-
targetAttributes.forEach { attribute, value -> builder.with("target_$attribute", value) }
305-
minAttributes.forEach { attribute, value -> builder.with("min_$attribute", value) }
306-
maxAttributes.forEach { attribute, value -> builder.with("max_$attribute", value) }
298+
targetAttributes.forEach { (attribute, value) -> builder.with("target_$attribute", value) }
299+
minAttributes.forEach { (attribute, value) -> builder.with("min_$attribute", value) }
300+
maxAttributes.forEach { (attribute, value) -> builder.with("max_$attribute", value) }
307301
get(builder.toString()).toObject<RecommendationResponse>(api)
308302
})
309303
}

0 commit comments

Comments
 (0)