@@ -4,7 +4,6 @@ package com.adamratzman.spotify.endpoints.public
44import com.adamratzman.spotify.main.SpotifyAPI
55import com.adamratzman.spotify.main.SpotifyRestAction
66import com.adamratzman.spotify.main.SpotifyRestPagingAction
7- import com.adamratzman.spotify.utils.Album
87import com.adamratzman.spotify.utils.ArtistURI
98import com.adamratzman.spotify.utils.BadRequestException
109import com.adamratzman.spotify.utils.EndpointBuilder
@@ -14,6 +13,7 @@ import com.adamratzman.spotify.utils.Market
1413import com.adamratzman.spotify.utils.PagingObject
1514import com.adamratzman.spotify.utils.RecommendationResponse
1615import com.adamratzman.spotify.utils.RecommendationSeed
16+ import com.adamratzman.spotify.utils.SimpleAlbum
1717import com.adamratzman.spotify.utils.SimplePlaylist
1818import com.adamratzman.spotify.utils.SimpleTrack
1919import com.adamratzman.spotify.utils.SpotifyCategory
@@ -41,7 +41,8 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4141 */
4242 fun getAvailableGenreSeeds (): SpotifyRestAction <List <String >> {
4343 return toAction(Supplier {
44- JSONObject (get(EndpointBuilder (" /recommendations/available-genre-seeds" ).toString())).getJSONArray(" genres" ).map { it.toString() }
44+ JSONObject (get(EndpointBuilder (" /recommendations/available-genre-seeds" ).toString())).getJSONArray(" genres" )
45+ .map { it.toString() }
4546 })
4647 }
4748
@@ -55,10 +56,23 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5556 *
5657 * @throws BadRequestException if filter parameters are illegal
5758 */
58- fun getNewReleases (limit : Int? = null, offset : Int? = null, market : Market ? = null): SpotifyRestPagingAction <Album , PagingObject <Album >> {
59+ fun getNewReleases (
60+ limit : Int? = null,
61+ offset : Int? = null,
62+ market : Market ? = null
63+ ): SpotifyRestPagingAction <SimpleAlbum , PagingObject <SimpleAlbum >> {
5964 return toPagingObjectAction(Supplier {
60- get(EndpointBuilder (" /browse/new-releases" ).with (" limit" , limit).with (" offset" , offset).with (" country" , market?.code).toString())
61- .toPagingObject(" albums" , endpoint = this , serializer = Album .serializer())
65+ get(
66+ EndpointBuilder (" /browse/new-releases" ).with (" limit" , limit).with (" offset" , offset).with (
67+ " country" ,
68+ market?.code
69+ ).toString()
70+ )
71+ .toPagingObject(
72+ " albums" ,
73+ endpoint = this ,
74+ serializer = PagingObject .serializer(SimpleAlbum .serializer())
75+ )
6276 })
6377 }
6478
@@ -79,12 +93,22 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
7993 *
8094 * @throws BadRequestException if filter parameters are illegal or [locale] does not exist
8195 */
82- fun getFeaturedPlaylists (limit : Int? = null, offset : Int? = null, locale : String? = null, market : Market ? = null, timestamp : Long? = null): SpotifyRestAction <FeaturedPlaylists > {
96+ fun getFeaturedPlaylists (
97+ limit : Int? = null,
98+ offset : Int? = null,
99+ locale : String? = null,
100+ market : Market ? = null,
101+ timestamp : Long? = null
102+ ): SpotifyRestAction <FeaturedPlaylists > {
83103 return toAction(Supplier {
84- get(EndpointBuilder (" /browse/featured-playlists" ).with (" limit" , limit).with (" offset" , offset).with (" market" , market?.code)
85- .with (" locale" , locale).with (" timestamp" , timestamp?.let {
86- SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss" ).format(Date .from(Instant .ofEpochMilli(timestamp)))
87- }).toString()).toObject(api, FeaturedPlaylists .serializer())
104+ get(EndpointBuilder (" /browse/featured-playlists" ).with (" limit" , limit).with (" offset" , offset).with (
105+ " market" ,
106+ market?.code
107+ )
108+ .with (" locale" , locale).with (" timestamp" , timestamp?.let {
109+ SimpleDateFormat (" yyyy-MM-dd'T'HH:mm:ss" ).format(Date .from(Instant .ofEpochMilli(timestamp)))
110+ }).toString()
111+ ).toObject(api, FeaturedPlaylists .serializer())
88112 })
89113 }
90114
@@ -103,11 +127,25 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
103127 *
104128 * @return Default category list if [locale] is invalid, otherwise the localized PagingObject
105129 */
106- fun getCategoryList (limit : Int? = null, offset : Int? = null, locale : String? = null, market : Market ? = null): SpotifyRestPagingAction <SpotifyCategory , PagingObject <SpotifyCategory >> {
130+ fun getCategoryList (
131+ limit : Int? = null,
132+ offset : Int? = null,
133+ locale : String? = null,
134+ market : Market ? = null
135+ ): SpotifyRestPagingAction <SpotifyCategory , PagingObject <SpotifyCategory >> {
107136 return toPagingObjectAction(Supplier {
108- get(EndpointBuilder (" /browse/categories" ).with (" limit" , limit).with (" offset" , offset).with (" market" , market?.code)
109- .with (" locale" , locale).toString())
110- .toPagingObject(" categories" , endpoint = this , serializer = SpotifyCategory .serializer())
137+ get(
138+ EndpointBuilder (" /browse/categories" ).with (" limit" , limit).with (" offset" , offset).with (
139+ " market" ,
140+ market?.code
141+ )
142+ .with (" locale" , locale).toString()
143+ )
144+ .toPagingObject(
145+ " categories" ,
146+ endpoint = this ,
147+ serializer = PagingObject .serializer(SpotifyCategory .serializer())
148+ )
111149 })
112150 }
113151
@@ -124,10 +162,16 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
124162 *
125163 * @throws BadRequestException if [categoryId] is not found or [locale] does not exist on Spotify
126164 */
127- fun getCategory (categoryId : String , market : Market ? = null, locale : String? = null): SpotifyRestAction <SpotifyCategory > {
165+ fun getCategory (
166+ categoryId : String ,
167+ market : Market ? = null,
168+ locale : String? = null
169+ ): SpotifyRestAction <SpotifyCategory > {
128170 return toAction(Supplier {
129- get(EndpointBuilder (" /browse/categories/${categoryId.encode()} " ).with (" market" , market?.code)
130- .with (" locale" , locale).toString()).toObject(api, SpotifyCategory .serializer())
171+ get(
172+ EndpointBuilder (" /browse/categories/${categoryId.encode()} " ).with (" market" , market?.code)
173+ .with (" locale" , locale).toString()
174+ ).toObject(api, SpotifyCategory .serializer())
131175 })
132176 }
133177
@@ -141,11 +185,25 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
141185 *
142186 * @throws BadRequestException if [categoryId] is not found or filters are illegal
143187 */
144- fun getPlaylistsForCategory (categoryId : String , limit : Int? = null, offset : Int? = null, market : Market ? = null): SpotifyRestPagingAction <SimplePlaylist , PagingObject <SimplePlaylist >> {
188+ fun getPlaylistsForCategory (
189+ categoryId : String ,
190+ limit : Int? = null,
191+ offset : Int? = null,
192+ market : Market ? = null
193+ ): SpotifyRestPagingAction <SimplePlaylist , PagingObject <SimplePlaylist >> {
145194 return toPagingObjectAction(Supplier {
146- get(EndpointBuilder (" /browse/categories/${categoryId.encode()} /playlists" ).with (" limit" , limit).with (" offset" , offset)
147- .with (" market" , market?.code).toString())
148- .toPagingObject(" playlists" , endpoint = this , serializer = SimplePlaylist .serializer())
195+ get(
196+ EndpointBuilder (" /browse/categories/${categoryId.encode()} /playlists" ).with (
197+ " limit" ,
198+ limit
199+ ).with (" offset" , offset)
200+ .with (" market" , market?.code).toString()
201+ )
202+ .toPagingObject(
203+ " playlists" ,
204+ endpoint = this ,
205+ serializer = PagingObject .serializer(SimplePlaylist .serializer())
206+ )
149207 })
150208 }
151209
@@ -194,9 +252,9 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
194252 }
195253 return toAction(Supplier {
196254 val builder = EndpointBuilder (" /recommendations" ).with (" limit" , limit).with (" market" , market?.code)
197- .with (" seed_artists" , seedArtists?.joinToString(" ," ) { ArtistURI (it).id.encode() })
198- .with (" seed_genres" , seedGenres?.joinToString(" ," ) { it.encode() })
199- .with (" seed_tracks" , seedTracks?.joinToString(" ," ) { TrackURI (it).id.encode() })
255+ .with (" seed_artists" , seedArtists?.joinToString(" ," ) { ArtistURI (it).id.encode() })
256+ .with (" seed_genres" , seedGenres?.joinToString(" ," ) { it.encode() })
257+ .with (" seed_tracks" , seedTracks?.joinToString(" ," ) { TrackURI (it).id.encode() })
200258 targetAttributes.forEach { attribute, value -> builder.with (" target_$attribute " , value) }
201259 minAttributes.forEach { attribute, value -> builder.with (" min_$attribute " , value) }
202260 maxAttributes.forEach { attribute, value -> builder.with (" max_$attribute " , value) }
0 commit comments