Skip to content

Commit 7637c28

Browse files
committed
stop hardcoding countries, use nv-i18n, force private fields to not be ignored
1 parent 9be1468 commit 7637c28

24 files changed

+158
-367
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ archivesBaseName = 'spotify-api-kotlin'
2929
sourceCompatibility = 1.8
3030

3131
repositories {
32-
mavenCentral()
3332
jcenter()
3433
}
3534

3635
dependencies {
3736
// Actual library dependencies
3837
compile 'com.beust:klaxon:5.0.5'
38+
compile 'com.neovisionaries:nv-i18n:1.25'
3939

4040
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4141
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

src/main/kotlin/com/adamratzman/spotify/SpotifyLogger.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package com.adamratzman.spotify
33

44
class SpotifyLogger(var enabled: Boolean) {
55
val redString = "\u001B[31m"
6+
val orangeString = "\u001B[33m"
67
val resetString = "\u001B[0m"
78

89
fun logInfo(message: String) {
910
if (enabled) println("Spotify Logger Info: $message")
1011
}
1112

1213
fun logWarning(message: String) {
13-
if (enabled) println("${redString}Spotify Logger Warning: $message$resetString")
14+
if (enabled) println("${orangeString}Spotify Logger Warning: $message$resetString")
1415
}
1516

1617
fun logError(fatal: Boolean, message: String?, throwable: Throwable?) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.http.EndpointBuilder
5-
import com.adamratzman.spotify.http.SpotifyEndpoint
6-
import com.adamratzman.spotify.http.encode
74
import com.adamratzman.spotify.SpotifyAPI
85
import com.adamratzman.spotify.SpotifyRestAction
96
import com.adamratzman.spotify.SpotifyRestActionPaging
7+
import com.adamratzman.spotify.http.EndpointBuilder
8+
import com.adamratzman.spotify.http.SpotifyEndpoint
9+
import com.adamratzman.spotify.http.encode
1010
import com.adamratzman.spotify.models.AlbumURI
11-
import com.adamratzman.spotify.models.Market
1211
import com.adamratzman.spotify.models.PagingObject
1312
import com.adamratzman.spotify.models.SavedAlbum
1413
import com.adamratzman.spotify.models.SavedTrack
1514
import com.adamratzman.spotify.models.TrackURI
1615
import com.adamratzman.spotify.models.serialization.toArray
1716
import com.adamratzman.spotify.models.serialization.toPagingObject
17+
import com.neovisionaries.i18n.CountryCode
1818
import java.util.function.Supplier
1919

2020
/**
@@ -34,11 +34,11 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3434
fun getSavedTracks(
3535
limit: Int? = null,
3636
offset: Int? = null,
37-
market: Market? = null
37+
market: CountryCode? = null
3838
): SpotifyRestActionPaging<SavedTrack, PagingObject<SavedTrack>> {
3939
return toActionPaging(Supplier {
4040
get(
41-
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.code)
41+
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.name)
4242
.toString()
4343
).toPagingObject<SavedTrack>(endpoint = this)
4444
})
@@ -57,11 +57,11 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5757
fun getSavedAlbums(
5858
limit: Int? = null,
5959
offset: Int? = null,
60-
market: Market? = null
60+
market: CountryCode? = null
6161
): SpotifyRestActionPaging<SavedAlbum, PagingObject<SavedAlbum>> {
6262
return toActionPaging(Supplier {
6363
get(
64-
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.code)
64+
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.name)
6565
.toString()
6666
).toPagingObject<SavedAlbum>(endpoint = this)
6767
})

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.public
33

4-
import com.adamratzman.spotify.http.EndpointBuilder
5-
import com.adamratzman.spotify.http.SpotifyEndpoint
6-
import com.adamratzman.spotify.http.encode
74
import com.adamratzman.spotify.SpotifyAPI
85
import com.adamratzman.spotify.SpotifyRestAction
96
import com.adamratzman.spotify.SpotifyRestActionPaging
7+
import com.adamratzman.spotify.http.EndpointBuilder
8+
import com.adamratzman.spotify.http.SpotifyEndpoint
9+
import com.adamratzman.spotify.http.encode
1010
import com.adamratzman.spotify.models.Album
1111
import com.adamratzman.spotify.models.AlbumURI
1212
import com.adamratzman.spotify.models.AlbumsResponse
1313
import com.adamratzman.spotify.models.BadRequestException
14-
import com.adamratzman.spotify.models.Market
1514
import com.adamratzman.spotify.models.PagingObject
1615
import com.adamratzman.spotify.models.SimpleTrack
1716
import com.adamratzman.spotify.models.serialization.toObject
1817
import com.adamratzman.spotify.models.serialization.toPagingObject
1918
import com.adamratzman.spotify.utils.catch
19+
import com.neovisionaries.i18n.CountryCode
2020
import java.util.function.Supplier
2121

2222
/**
@@ -30,10 +30,10 @@ class AlbumAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3030
*
3131
* @return full [Album] object if the provided id is found, otherwise null
3232
*/
33-
fun getAlbum(album: String, market: Market? = null): SpotifyRestAction<Album?> {
33+
fun getAlbum(album: String, market: CountryCode? = null): SpotifyRestAction<Album?> {
3434
return toAction(Supplier {
3535
catch {
36-
get(EndpointBuilder("/albums/${AlbumURI(album).id}").with("market", market?.code).toString())
36+
get(EndpointBuilder("/albums/${AlbumURI(album).id}").with("market", market?.name).toString())
3737
.toObject<Album>(api)
3838
}
3939
})
@@ -44,11 +44,11 @@ class AlbumAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4444
* @param albums the spotify ids or uris for the albums.
4545
* @param market Provide this parameter if you want to apply [Track Relinking](https://github.com/adamint/spotify-web-api-kotlin/blob/master/README.md#track-relinking)
4646
*/
47-
fun getAlbums(vararg albums: String, market: Market? = null): SpotifyRestAction<List<Album?>> {
47+
fun getAlbums(vararg albums: String, market: CountryCode? = null): SpotifyRestAction<List<Album?>> {
4848
return toAction(Supplier {
4949
get(
5050
EndpointBuilder("/albums").with("ids", albums.joinToString(",") { AlbumURI(it).id.encode() })
51-
.with("market", market?.code).toString()
51+
.with("market", market?.name).toString()
5252
).toObject<AlbumsResponse>(api).albums
5353
})
5454
}
@@ -66,14 +66,14 @@ class AlbumAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6666
album: String,
6767
limit: Int? = null,
6868
offset: Int? = null,
69-
market: Market? = null
69+
market: CountryCode? = null
7070
): SpotifyRestActionPaging<SimpleTrack, PagingObject<SimpleTrack>> {
7171
return toActionPaging(Supplier {
7272
get(
7373
EndpointBuilder("/albums/${AlbumURI(album).id.encode()}/tracks").with("limit", limit).with(
7474
"offset",
7575
offset
76-
).with("market", market?.code)
76+
).with("market", market?.name)
7777
.toString()
7878
).toPagingObject<SimpleTrack>(endpoint = this)
7979
})

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.public
33

4-
import com.adamratzman.spotify.http.EndpointBuilder
5-
import com.adamratzman.spotify.http.SpotifyEndpoint
6-
import com.adamratzman.spotify.http.encode
74
import com.adamratzman.spotify.SpotifyAPI
85
import com.adamratzman.spotify.SpotifyRestAction
96
import com.adamratzman.spotify.SpotifyRestActionPaging
7+
import com.adamratzman.spotify.http.EndpointBuilder
8+
import com.adamratzman.spotify.http.SpotifyEndpoint
9+
import com.adamratzman.spotify.http.encode
1010
import com.adamratzman.spotify.models.Artist
1111
import com.adamratzman.spotify.models.ArtistList
1212
import com.adamratzman.spotify.models.ArtistURI
1313
import com.adamratzman.spotify.models.BadRequestException
1414
import com.adamratzman.spotify.models.CursorBasedPagingObject
15-
import com.adamratzman.spotify.models.Market
1615
import com.adamratzman.spotify.models.PagingObject
1716
import com.adamratzman.spotify.models.SimpleAlbum
1817
import com.adamratzman.spotify.models.Track
1918
import com.adamratzman.spotify.models.serialization.toInnerArray
2019
import com.adamratzman.spotify.models.serialization.toObject
2120
import com.adamratzman.spotify.models.serialization.toPagingObject
2221
import com.adamratzman.spotify.utils.catch
22+
import com.neovisionaries.i18n.CountryCode
2323
import java.util.function.Supplier
2424

2525
/**
@@ -69,15 +69,15 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6969
artist: String,
7070
limit: Int? = null,
7171
offset: Int? = null,
72-
market: Market? = null,
72+
market: CountryCode? = null,
7373
vararg include: AlbumInclusionStrategy
7474
): SpotifyRestActionPaging<SimpleAlbum, PagingObject<SimpleAlbum>> {
7575
return toActionPaging(Supplier {
7676
get(
7777
EndpointBuilder("/artists/${ArtistURI(artist).id.encode()}/albums").with("limit", limit).with(
7878
"offset",
7979
offset
80-
).with("market", market?.code)
80+
).with("market", market?.name)
8181
.with("include_groups", include.joinToString(",") { it.keyword }).toString()
8282
).toPagingObject<SimpleAlbum>(null, this)
8383
})
@@ -101,12 +101,12 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
101101
*
102102
* @throws BadRequestException if tracks are not available in the specified [Market] or the [artist] is not found
103103
*/
104-
fun getArtistTopTracks(artist: String, market: Market = Market.US): SpotifyRestAction<List<Track>> {
104+
fun getArtistTopTracks(artist: String, market: CountryCode = CountryCode.US): SpotifyRestAction<List<Track>> {
105105
return toAction(Supplier {
106106
get(
107107
EndpointBuilder("/artists/${ArtistURI(artist).id.encode()}/top-tracks").with(
108108
"country",
109-
market.code
109+
market.name
110110
).toString()
111111
).toInnerArray<Track>("tracks", api)
112112
})

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.public
33

4-
import com.adamratzman.spotify.http.EndpointBuilder
5-
import com.adamratzman.spotify.http.SpotifyEndpoint
6-
import com.adamratzman.spotify.http.encode
74
import com.adamratzman.spotify.SpotifyAPI
85
import com.adamratzman.spotify.SpotifyRestAction
96
import com.adamratzman.spotify.SpotifyRestActionPaging
7+
import com.adamratzman.spotify.http.EndpointBuilder
8+
import com.adamratzman.spotify.http.SpotifyEndpoint
9+
import com.adamratzman.spotify.http.encode
1010
import com.adamratzman.spotify.models.ArtistURI
1111
import com.adamratzman.spotify.models.BadRequestException
1212
import com.adamratzman.spotify.models.ErrorObject
1313
import com.adamratzman.spotify.models.FeaturedPlaylists
14-
import com.adamratzman.spotify.models.Market
1514
import com.adamratzman.spotify.models.PagingObject
1615
import com.adamratzman.spotify.models.RecommendationResponse
1716
import com.adamratzman.spotify.models.RecommendationSeed
@@ -23,6 +22,7 @@ import com.adamratzman.spotify.models.TrackURI
2322
import com.adamratzman.spotify.models.serialization.toInnerArray
2423
import com.adamratzman.spotify.models.serialization.toObject
2524
import com.adamratzman.spotify.models.serialization.toPagingObject
25+
import com.neovisionaries.i18n.CountryCode
2626
import java.text.SimpleDateFormat
2727
import java.time.Instant
2828
import java.util.Date
@@ -60,13 +60,13 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6060
fun getNewReleases(
6161
limit: Int? = null,
6262
offset: Int? = null,
63-
market: Market? = null
63+
market: CountryCode? = null
6464
): SpotifyRestActionPaging<SimpleAlbum, PagingObject<SimpleAlbum>> {
6565
return toActionPaging(Supplier {
6666
get(
6767
EndpointBuilder("/browse/new-releases").with("limit", limit).with("offset", offset).with(
6868
"country",
69-
market?.code
69+
market?.name
7070
).toString()
7171
).toPagingObject<SimpleAlbum>(
7272
"albums", endpoint = this
@@ -95,14 +95,14 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
9595
limit: Int? = null,
9696
offset: Int? = null,
9797
locale: String? = null,
98-
market: Market? = null,
98+
market: CountryCode? = null,
9999
timestamp: Long? = null
100100
): SpotifyRestAction<FeaturedPlaylists> {
101101
return toAction(Supplier {
102102
get(
103103
EndpointBuilder("/browse/featured-playlists").with("limit", limit).with("offset", offset).with(
104104
"market",
105-
market?.code
105+
market?.name
106106
)
107107
.with("locale", locale).with("timestamp", timestamp?.let {
108108
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Date.from(Instant.ofEpochMilli(timestamp)))
@@ -130,13 +130,13 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
130130
limit: Int? = null,
131131
offset: Int? = null,
132132
locale: String? = null,
133-
market: Market? = null
133+
market: CountryCode? = null
134134
): SpotifyRestActionPaging<SpotifyCategory, PagingObject<SpotifyCategory>> {
135135
return toActionPaging(Supplier {
136136
get(
137137
EndpointBuilder("/browse/categories").with("limit", limit).with("offset", offset).with(
138138
"market",
139-
market?.code
139+
market?.name
140140
).with("locale", locale).toString()
141141
).toPagingObject<SpotifyCategory>(
142142
"categories", endpoint = this
@@ -159,12 +159,12 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
159159
*/
160160
fun getCategory(
161161
categoryId: String,
162-
market: Market? = null,
162+
market: CountryCode? = null,
163163
locale: String? = null
164164
): SpotifyRestAction<SpotifyCategory> {
165165
return toAction(Supplier {
166166
get(
167-
EndpointBuilder("/browse/categories/${categoryId.encode()}").with("market", market?.code)
167+
EndpointBuilder("/browse/categories/${categoryId.encode()}").with("market", market?.name)
168168
.with("locale", locale).toString()
169169
).toObject<SpotifyCategory>(api)
170170
})
@@ -184,15 +184,15 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
184184
categoryId: String,
185185
limit: Int? = null,
186186
offset: Int? = null,
187-
market: Market? = null
187+
market: CountryCode? = null
188188
): SpotifyRestActionPaging<SimplePlaylist, PagingObject<SimplePlaylist>> {
189189
return toActionPaging(Supplier {
190190
get(
191191
EndpointBuilder("/browse/categories/${categoryId.encode()}/playlists").with(
192192
"limit",
193193
limit
194194
).with("offset", offset)
195-
.with("market", market?.code).toString()
195+
.with("market", market?.name).toString()
196196
).toPagingObject<SimplePlaylist>("playlists", endpoint = this)
197197
})
198198
}
@@ -232,7 +232,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
232232
seedGenres: List<String>? = null,
233233
seedTracks: List<String>? = null,
234234
limit: Int? = null,
235-
market: Market? = null,
235+
market: CountryCode? = null,
236236
targetAttributes: HashMap<TuneableTrackAttribute, Number> = hashMapOf(),
237237
minAttributes: HashMap<TuneableTrackAttribute, Number> = hashMapOf(),
238238
maxAttributes: HashMap<TuneableTrackAttribute, Number> = hashMapOf()
@@ -241,7 +241,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
241241
throw BadRequestException(ErrorObject(400, "At least one seed (genre, artist, track) must be provided."))
242242
}
243243
return toAction(Supplier {
244-
val builder = EndpointBuilder("/recommendations").with("limit", limit).with("market", market?.code)
244+
val builder = EndpointBuilder("/recommendations").with("limit", limit).with("market", market?.name)
245245
.with("seed_artists", seedArtists?.joinToString(",") { ArtistURI(it).id.encode() })
246246
.with("seed_genres", seedGenres?.joinToString(",") { it.encode() })
247247
.with("seed_tracks", seedTracks?.joinToString(",") { TrackURI(it).id.encode() })

0 commit comments

Comments
 (0)