Add category info (#561)

* Add category info

* Add slash

* Add test
This commit is contained in:
Bram Kragten 2020-08-27 21:49:56 +02:00 committed by GitHub
parent 651080e3da
commit 5e9f97df8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -1453,8 +1453,25 @@ class Spotify(object):
"browse/new-releases", country=country, limit=limit, offset=offset "browse/new-releases", country=country, limit=limit, offset=offset
) )
def category(self, category_id, country=None, locale=None):
""" Get info about a category
Parameters:
- category_id - The Spotify category ID for the category.
- country - An ISO 3166-1 alpha-2 country code.
- locale - The desired language, consisting of an ISO 639
language code and an ISO 3166-1 alpha-2 country code, joined
by an underscore.
"""
return self._get(
"browse/categories/" + category_id,
country=country,
locale=locale,
)
def categories(self, country=None, locale=None, limit=20, offset=0): def categories(self, country=None, locale=None, limit=20, offset=0):
""" Get a list of new album releases featured in Spotify """ Get a list of categories
Parameters: Parameters:
- country - An ISO 3166-1 alpha-2 country code. - country - An ISO 3166-1 alpha-2 country code.
@ -1480,7 +1497,7 @@ class Spotify(object):
def category_playlists( def category_playlists(
self, category_id=None, country=None, limit=20, offset=0 self, category_id=None, country=None, limit=20, offset=0
): ):
""" Get a list of new album releases featured in Spotify """ Get a list of playlists for a specific Spotify category
Parameters: Parameters:
- category_id - The Spotify category ID for the category. - category_id - The Spotify category ID for the category.

View File

@ -297,6 +297,10 @@ class SpotipyBrowseApiTests(unittest.TestCase):
token = prompt_for_user_token(username) token = prompt_for_user_token(username)
cls.spotify = Spotify(auth=token) cls.spotify = Spotify(auth=token)
def test_category(self):
response = self.spotify.category('rock')
self.assertTrue('name' in response)
def test_categories(self): def test_categories(self):
response = self.spotify.categories() response = self.spotify.categories()
self.assertGreater(len(response['categories']), 0) self.assertGreater(len(response['categories']), 0)