1
1
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
2
2
package com.adamratzman.spotify.endpoints.public
3
3
4
- import com.adamratzman.spotify.http.EndpointBuilder
5
- import com.adamratzman.spotify.http.SpotifyEndpoint
6
- import com.adamratzman.spotify.http.encode
7
4
import com.adamratzman.spotify.SpotifyAPI
8
5
import com.adamratzman.spotify.SpotifyRestAction
9
6
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
10
10
import com.adamratzman.spotify.models.ArtistURI
11
11
import com.adamratzman.spotify.models.BadRequestException
12
12
import com.adamratzman.spotify.models.ErrorObject
13
13
import com.adamratzman.spotify.models.FeaturedPlaylists
14
- import com.adamratzman.spotify.models.Market
15
14
import com.adamratzman.spotify.models.PagingObject
16
15
import com.adamratzman.spotify.models.RecommendationResponse
17
16
import com.adamratzman.spotify.models.RecommendationSeed
@@ -23,6 +22,7 @@ import com.adamratzman.spotify.models.TrackURI
23
22
import com.adamratzman.spotify.models.serialization.toInnerArray
24
23
import com.adamratzman.spotify.models.serialization.toObject
25
24
import com.adamratzman.spotify.models.serialization.toPagingObject
25
+ import com.neovisionaries.i18n.CountryCode
26
26
import java.text.SimpleDateFormat
27
27
import java.time.Instant
28
28
import java.util.Date
@@ -60,13 +60,13 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
60
60
fun getNewReleases (
61
61
limit : Int? = null,
62
62
offset : Int? = null,
63
- market : Market ? = null
63
+ market : CountryCode ? = null
64
64
): SpotifyRestActionPaging <SimpleAlbum , PagingObject <SimpleAlbum >> {
65
65
return toActionPaging(Supplier {
66
66
get(
67
67
EndpointBuilder (" /browse/new-releases" ).with (" limit" , limit).with (" offset" , offset).with (
68
68
" country" ,
69
- market?.code
69
+ market?.name
70
70
).toString()
71
71
).toPagingObject<SimpleAlbum >(
72
72
" albums" , endpoint = this
@@ -95,14 +95,14 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
95
95
limit : Int? = null,
96
96
offset : Int? = null,
97
97
locale : String? = null,
98
- market : Market ? = null,
98
+ market : CountryCode ? = null,
99
99
timestamp : Long? = null
100
100
): SpotifyRestAction <FeaturedPlaylists > {
101
101
return toAction(Supplier {
102
102
get(
103
103
EndpointBuilder (" /browse/featured-playlists" ).with (" limit" , limit).with (" offset" , offset).with (
104
104
" market" ,
105
- market?.code
105
+ market?.name
106
106
)
107
107
.with (" locale" , locale).with (" timestamp" , timestamp?.let {
108
108
SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss" ).format(Date .from(Instant .ofEpochMilli(timestamp)))
@@ -130,13 +130,13 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
130
130
limit : Int? = null,
131
131
offset : Int? = null,
132
132
locale : String? = null,
133
- market : Market ? = null
133
+ market : CountryCode ? = null
134
134
): SpotifyRestActionPaging <SpotifyCategory , PagingObject <SpotifyCategory >> {
135
135
return toActionPaging(Supplier {
136
136
get(
137
137
EndpointBuilder (" /browse/categories" ).with (" limit" , limit).with (" offset" , offset).with (
138
138
" market" ,
139
- market?.code
139
+ market?.name
140
140
).with (" locale" , locale).toString()
141
141
).toPagingObject<SpotifyCategory >(
142
142
" categories" , endpoint = this
@@ -159,12 +159,12 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
159
159
*/
160
160
fun getCategory (
161
161
categoryId : String ,
162
- market : Market ? = null,
162
+ market : CountryCode ? = null,
163
163
locale : String? = null
164
164
): SpotifyRestAction <SpotifyCategory > {
165
165
return toAction(Supplier {
166
166
get(
167
- EndpointBuilder (" /browse/categories/${categoryId.encode()} " ).with (" market" , market?.code )
167
+ EndpointBuilder (" /browse/categories/${categoryId.encode()} " ).with (" market" , market?.name )
168
168
.with (" locale" , locale).toString()
169
169
).toObject<SpotifyCategory >(api)
170
170
})
@@ -184,15 +184,15 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
184
184
categoryId : String ,
185
185
limit : Int? = null,
186
186
offset : Int? = null,
187
- market : Market ? = null
187
+ market : CountryCode ? = null
188
188
): SpotifyRestActionPaging <SimplePlaylist , PagingObject <SimplePlaylist >> {
189
189
return toActionPaging(Supplier {
190
190
get(
191
191
EndpointBuilder (" /browse/categories/${categoryId.encode()} /playlists" ).with (
192
192
" limit" ,
193
193
limit
194
194
).with (" offset" , offset)
195
- .with (" market" , market?.code ).toString()
195
+ .with (" market" , market?.name ).toString()
196
196
).toPagingObject<SimplePlaylist >(" playlists" , endpoint = this )
197
197
})
198
198
}
@@ -232,7 +232,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
232
232
seedGenres : List <String >? = null,
233
233
seedTracks : List <String >? = null,
234
234
limit : Int? = null,
235
- market : Market ? = null,
235
+ market : CountryCode ? = null,
236
236
targetAttributes : HashMap <TuneableTrackAttribute , Number > = hashMapOf(),
237
237
minAttributes : HashMap <TuneableTrackAttribute , Number > = hashMapOf(),
238
238
maxAttributes : HashMap <TuneableTrackAttribute , Number > = hashMapOf()
@@ -241,7 +241,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
241
241
throw BadRequestException (ErrorObject (400 , " At least one seed (genre, artist, track) must be provided." ))
242
242
}
243
243
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 )
245
245
.with (" seed_artists" , seedArtists?.joinToString(" ," ) { ArtistURI (it).id.encode() })
246
246
.with (" seed_genres" , seedGenres?.joinToString(" ," ) { it.encode() })
247
247
.with (" seed_tracks" , seedTracks?.joinToString(" ," ) { TrackURI (it).id.encode() })
0 commit comments