File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -382,6 +382,16 @@ class CategoryPlaylistResponse(DataClassORJSONMixin):
382382 playlists : PlaylistResponse
383383
384384
385+ @dataclass
386+ class Category (DataClassORJSONMixin ):
387+ """Category model."""
388+
389+ category_id : str = field (metadata = field_options (alias = "id" ))
390+ name : str
391+ href : str
392+ icons : list [Image ]
393+
394+
385395class ProductType (StrEnum ):
386396 """Product type."""
387397
Original file line number Diff line number Diff line change 1717 ArtistResponse ,
1818 BasePlaylist ,
1919 BaseUserProfile ,
20+ Category ,
2021 CategoryPlaylistResponse ,
2122 CurrentPlaying ,
2223 Device ,
@@ -278,6 +279,11 @@ async def get_featured_playlists(self) -> list[BasePlaylist]:
278279 response = await self ._get ("v1/browse/featured-playlists" , params = params )
279280 return FeaturedPlaylistResponse .from_json (response ).playlists .items
280281
282+ async def get_category (self , category_id : str ) -> Category :
283+ """Get category."""
284+ response = await self ._get (f"v1/browse/categories/{ category_id } " )
285+ return Category .from_json (response )
286+
281287 async def get_saved_albums (self ) -> list [SavedAlbum ]:
282288 """Get saved albums."""
283289 params : dict [str , Any ] = {"limit" : 48 }
Original file line number Diff line number Diff line change 366366 'uri': 'spotify:album:3IqzqH6ShrRtie9Yd2ODyG',
367367 })
368368# ---
369+ # name: test_get_category
370+ dict({
371+ 'category_id': '0JQ5DAqbMKFRY5ok2pxXJ0',
372+ 'href': 'https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFRY5ok2pxXJ0',
373+ 'icons': list([
374+ dict({
375+ 'height': 274,
376+ 'url': 'https://t.scdn.co/media/original/dinner_1b6506abba0ba52c54e6d695c8571078_274x274.jpg',
377+ 'width': 274,
378+ }),
379+ ]),
380+ 'name': 'Cooking & Dining',
381+ })
382+ # ---
369383# name: test_get_category_playlists
370384 list([
371385 dict({
Original file line number Diff line number Diff line change 1+ {
2+ "href" : " https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFRY5ok2pxXJ0" ,
3+ "id" : " 0JQ5DAqbMKFRY5ok2pxXJ0" ,
4+ "icons" : [
5+ {
6+ "height" : 274 ,
7+ "url" : " https://t.scdn.co/media/original/dinner_1b6506abba0ba52c54e6d695c8571078_274x274.jpg" ,
8+ "width" : 274
9+ }
10+ ],
11+ "name" : " Cooking & Dining"
12+ }
Original file line number Diff line number Diff line change @@ -982,3 +982,25 @@ async def test_get_top_tracks(
982982 params = {"limit" : 48 },
983983 data = None ,
984984 )
985+
986+
987+ async def test_get_category (
988+ responses : aioresponses ,
989+ snapshot : SnapshotAssertion ,
990+ authenticated_client : SpotifyClient ,
991+ ) -> None :
992+ """Test retrieving a category."""
993+ responses .get (
994+ f"{ SPOTIFY_URL } /v1/browse/categories/dinner" ,
995+ status = 200 ,
996+ body = load_fixture ("category.json" ),
997+ )
998+ response = await authenticated_client .get_category ("dinner" )
999+ assert response == snapshot
1000+ responses .assert_called_once_with (
1001+ f"{ SPOTIFY_URL } /v1/browse/categories/dinner" ,
1002+ METH_GET ,
1003+ headers = HEADERS ,
1004+ params = None ,
1005+ data = None ,
1006+ )
You can’t perform that action at this time.
0 commit comments