-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`. * Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code. * Updated CHANGELOG.md * Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`. * Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist. * Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes. * Removed duplicate word "multiple" from CHANGELOG * * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645. * Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser. * Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`. * Removed unneeded import * Added cache handler to `SpotifyClientCredentials` and fixed a bug in refresh tokens methods that raised the wrong exception (#655) * Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`. * Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code. * Updated CHANGELOG.md * Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`. * Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist. * Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes. * Removed duplicate word "multiple" from CHANGELOG * * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645. * Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser. * Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`. * Removed unneeded import Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com> * Made `CacheHandler` an abstract base class Added: * `Scope` - An enum which contains all of the authorization scopes (see [here](#652 (comment))). * Added the following endpoints * `Spotify.current_user_saved_episodes` * `Spotify.current_user_saved_episodes_add` * `Spotify.current_user_saved_episodes_delete` * `Spotify.current_user_saved_episodes_contains` * `Spotify.available_markets * Fixed formatting issues. Removed python 2.7 from github workflows. * Added python 3.9 to github workflows. The type hints for set now uses the generic typing.Set instead of builtins.set. * Changed f-string to percent-formatted string. * Fixed the duplicate "###Changed" section in the change log. Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
- Loading branch information
1 parent
39650ec
commit 3f5eeca
Showing
7 changed files
with
232 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__all__ = ["Scope"] | ||
|
||
from enum import Enum | ||
import re | ||
from typing import Iterable, Set | ||
|
||
|
||
class Scope(Enum): | ||
""" | ||
The Spotify authorization scopes | ||
Create a Scope from a string: | ||
scope = Scope("playlist-modify-private") | ||
Create a set of scopes: | ||
scopes = { | ||
Scope.user_read_currently_playing, | ||
Scope.playlist_read_collaborative, | ||
Scope.playlist_modify_public | ||
} | ||
""" | ||
|
||
user_read_currently_playing = "user-read-currently-playing" | ||
playlist_read_collaborative = "playlist-read-collaborative" | ||
playlist_modify_private = "playlist-modify-private" | ||
user_read_playback_position = "user-read-playback-position" | ||
user_library_modify = "user-library-modify" | ||
user_top_read = "user-top-read" | ||
user_read_playback_state = "user-read-playback-state" | ||
user_read_email = "user-read-email" | ||
ugc_image_upload = "ugc-image-upload" | ||
user_read_private = "user-read-private" | ||
playlist_modify_public = "playlist-modify-public" | ||
user_library_read = "user-library-read" | ||
streaming = "streaming" | ||
user_read_recently_played = "user-read-recently-played" | ||
user_follow_read = "user-follow-read" | ||
user_follow_modify = "user-follow-modify" | ||
app_remote_control = "app-remote-control" | ||
playlist_read_private = "playlist-read-private" | ||
user_modify_playback_state = "user-modify-playback-state" | ||
|
||
@staticmethod | ||
def all() -> Set['Scope']: | ||
"""Returns all of the authorization scopes""" | ||
|
||
return set(Scope) | ||
|
||
@staticmethod | ||
def make_string(scopes: Iterable['Scope']) -> str: | ||
""" | ||
Converts an iterable of scopes to a space-separated string. | ||
* scopes: An iterable of scopes. | ||
returns: a space-separated string of scopes | ||
""" | ||
return " ".join([scope.value for scope in scopes]) | ||
|
||
@staticmethod | ||
def from_string(scope_string: str) -> Set['Scope']: | ||
""" | ||
Converts a string of (usuallly space-separated) scopes into a | ||
set of scopes | ||
Any scope-strings that do not match any of the known scopes are | ||
ignored. | ||
* scope_string: a string of scopes | ||
returns: a set of scopes. | ||
""" | ||
scope_string_list = re.split(pattern=r"[^\w-]+", string=scope_string) | ||
scopes = set() | ||
for scope_string in sorted(scope_string_list): | ||
try: | ||
scope = Scope(scope_string) | ||
scopes.add(scope) | ||
except ValueError: | ||
pass | ||
return scopes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.