コード例 #1
0
        public T Execute <T, TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api, Func <SpotifyWebAPI, T> method, bool allowReauth = true)
            where T : BasicModel
            where TSettings : SpotifySettingsBase <TSettings>, new()
        {
            T result = method(api);

            if (result.HasError())
            {
                // If unauthorized, refresh token and try again
                if (result.Error.Status == 401)
                {
                    if (allowReauth)
                    {
                        _logger.Debug("Spotify authorization error, refreshing token and retrying");
                        list.RefreshToken();
                        api.AccessToken = list.AccessToken;
                        return(Execute(list, api, method, false));
                    }
                    else
                    {
                        throw new SpotifyAuthorizationException(result.Error.Message);
                    }
                }
                else
                {
                    throw new SpotifyException("[{0}] {1}", result.Error.Status, result.Error.Message);
                }
            }

            return(result);
        }
コード例 #2
0
 public Paging <T> GetNextPage <T, TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api, Paging <T> item)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, (x) => x.GetNextPage(item)));
 }
コード例 #3
0
 public FollowedArtists GetNextPage <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api, FollowedArtists item)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, (x) => x.GetNextPage <FollowedArtists, FullArtist>(item.Artists)));
 }
コード例 #4
0
 public Paging <PlaylistTrack> GetPlaylistTracks <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api, string id, string fields)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, x => x.GetPlaylistTracks(id, fields: fields)));
 }
コード例 #5
0
 public Paging <SavedAlbum> GetSavedAlbums <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, x => x.GetSavedAlbums(50)));
 }
コード例 #6
0
 public FollowedArtists GetFollowedArtists <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, x => x.GetFollowedArtists(FollowType.Artist, 50)));
 }
コード例 #7
0
 public Paging <SimplePlaylist> GetUserPlaylists <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api, string id)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, x => x.GetUserPlaylists(id)));
 }
コード例 #8
0
 public PrivateProfile GetPrivateProfile <TSettings>(SpotifyImportListBase <TSettings> list, SpotifyWebAPI api)
     where TSettings : SpotifySettingsBase <TSettings>, new()
 {
     return(Execute(list, api, x => x.GetPrivateProfile()));
 }