From 44bbfac8b70e5f85398df128dcc22a8493405e16 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Tue, 2 Feb 2016 07:25:33 -0500 Subject: [PATCH] Added category end points --- spotipy/client.py | 37 +++++++++++++++++++++++++++++++++++++ tests/authtests.py | 11 +++++++++++ 2 files changed, 48 insertions(+) diff --git a/spotipy/client.py b/spotipy/client.py index e62b618..27ca38b 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -585,6 +585,43 @@ class Spotify(object): return self._get('browse/new-releases', country=country, limit=limit, offset=offset) + def categories(self, country=None, locale=None, limit=20, offset = 0): + ''' Get a list of new album releases featured in Spotify + + Parameters: + - 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. + + - limit - The maximum number of items to return. Default: 20. + Minimum: 1. Maximum: 50 + + - offset - The index of the first item to return. Default: 0 + (the first object). Use with limit to get the next set of + items. + ''' + return self._get('browse/categories', country=country, locale=locale, + limit=limit, offset=offset) + + def category_playlists(self, category_id=None, country=None, limit=20, offset = 0): + ''' Get a list of new album releases featured in Spotify + + Parameters: + - category_id - The Spotify category ID for the category. + + - country - An ISO 3166-1 alpha-2 country code. + + - limit - The maximum number of items to return. Default: 20. + Minimum: 1. Maximum: 50 + + - offset - The index of the first item to return. Default: 0 + (the first object). Use with limit to get the next set of + items. + ''' + return self._get('browse/categories/' + category_id + '/playlists', country=country, + limit=limit, offset=offset) + def audio_features(self, tracks=[]): ''' Get audio features for multiple tracks based upon their Spotify IDs Parameters: diff --git a/tests/authtests.py b/tests/authtests.py index 1666f77..6d4f9bb 100644 --- a/tests/authtests.py +++ b/tests/authtests.py @@ -101,6 +101,17 @@ class AuthTestSpotipy(unittest.TestCase): self.assertTrue(new_total == total) + def test_categories(self): + response = spotify.categories() + self.assertTrue(len(response['categories']) > 0) + + def test_category_playlists(self): + response = spotify.categories() + for cat in response['categories']['items']: + cat_id = cat['id'] + response = spotify.category_playlists(category_id=cat_id) + self.assertTrue(len(response['playlists']["items"]) > 0) + def test_new_releases(self): response = spotify.new_releases() self.assertTrue(len(response['albums']) > 0)