public static async Task ClassInitialize(TestContext _) { var logger = new NullLogger <AlbumifyService>(); var config = new TestingConfiguration().Build(); var spotifyMusicService = new SpotifyWebApi(new HttpClient(), new SpotifyClientCredentialsFlow(config, new HttpClient())); _myCollectionInMongoDB = new MyCollectionInMongoDB(config); _sut = new AlbumifyService(logger, spotifyMusicService, _myCollectionInMongoDB); _result = await _sut.AddAsync(ThirdPartyId); _expected.Id = _result.Id; }
public async Task Run() { var token = await this.GetToken(); Console.Clear(); Console.WriteLine("Successfully logged in!"); // Use the api with access to personal data. var api = new SpotifyWebApi(token); var me = await api.UserProfile.GetMe(); Console.WriteLine($"Hello {me.DisplayName}"); var playlists = await api.Playlist.GetMyPlaylists(); Console.WriteLine("Your playlists:"); foreach (var simplePlaylist in playlists) { Console.Write($"{simplePlaylist.Name}, "); } Console.WriteLine(); Console.WriteLine(); var devices = await api.Player.GetAvailableDevices(); Console.WriteLine("Your devices:"); foreach (var device in devices) { Console.Write($"{device.Name}, "); } Console.WriteLine("Refreshing token..."); var newToken = await AuthorizationCode.RefreshTokenAsync(this.parameters, token); Console.WriteLine($"old: {token.AccessToken}"); Console.WriteLine($"new: {newToken.AccessToken}"); api.SetToken(newToken); me = await api.UserProfile.GetMe(); Console.WriteLine($"Hello {me.DisplayName}"); Console.ReadLine(); }
public async Task HandlesAlbums_WithAFullReleaseDateOrJustAYear() { // Arrange var spotifyAuthorization = StubAuthorization(); var httpClient = StubHttpClient(); // Act var sut = new SpotifyWebApi(httpClient, spotifyAuthorization); var result = await sut.GetAnArtistsAlbumsAsync("does not matter for this test"); // Assert var expected = new List <string> { "2019-10-25", "2005" }; result.Select(r => r.ReleaseDate).Should().BeEquivalentTo(expected); }
/// <summary> /// Main entry point. /// </summary> /// <param name="args">Command line arguments.</param> public static void Main(string[] args) { var param = new AuthParameters { Scopes = Scope.All, ClientId = ConfigurationManager.AppSettings["clientId"], ClientSecret = ConfigurationManager.AppSettings["clientSecret"], RedirectUri = ConfigurationManager.AppSettings["redirectUri"], ShowDialog = false, // Set to true to login each time. }; //var url = AuthorizationCode.GetUrl(param, "test"); //Process.Start(url); //var r = GetResponse().GetAwaiter().GetResult(); //var token = AuthorizationCode.ProcessCallback(param, r, string.Empty); var token = ClientCredentials.GetToken(param); ISpotifyWebApi api = new SpotifyWebApi(token); var task1 = api.UserProfile.GetMe(); var task2 = api.Player.GetCurrentlyPlayingContext(); var task3 = api.Playlist.GetMyPlaylists(200); Task.WhenAll(task1, task2, task3).GetAwaiter().GetResult(); var me = task1.Result; var t = task2.Result; var p = task3.Result; Console.WriteLine($"Hello {me.DisplayName}, This is an example application!"); Console.WriteLine($"You are listening to {t.Item.Name} on {t.Device.Name}"); foreach (var simplePlaylist in p) { Console.WriteLine($"{simplePlaylist.Id}, {simplePlaylist.Name}"); } Console.ReadLine(); }
/// <summary> /// /// </summary> /// <param name="SController"></param> /// <param name="user"></param> /// <returns></returns> private async Task <bool> GetCurrentUserTopTracks(SpotifyWebApi SController, PrivateProfile user) { try { // fetches the current user's top artists. It grabs the short, med and long term data. await SController.GetUsersTopTracksShortTerm(user.Id); await SController.GetUsersTopTracksMeduimTerm(user.Id); await SController.GetUsersTopTracksLongTerm(user.Id); } catch (Exception ex) { Console.WriteLine(ex); return(false); } //if there were no expections then we assume everything went well. return(true); }
/// <summary>The get basic data.</summary> /// <param name="tokenString">The token string.</param> private async void GetBasicData(string tokenString) { var token = AuthorizationCode.ProcessCallback(this.apiParameter, tokenString, string.Empty); this.container.RegisterInstance(token); var api = new SpotifyWebApi(token); this.container.RegisterInstance <ISpotifyWebApi>(api); var profile = api.UserProfile.GetMe(); var playLists = api.Playlist.GetMyPlaylists(200); var data = new ConnectionData { Profile = await profile, Playlists = await playLists, Api = api, Token = token }; this.eventAggregator.GetEvent <ConnectionEstablishedEvent>().Publish(data); }
public static void ClassInitialize(TestContext _) { var config = new TestingConfiguration().Build(); sut = new SpotifyWebApi(new HttpClient(), new SpotifyClientCredentialsFlow(config, new HttpClient())); }
public SpotifyService(SpotifyWebApi spotify) { _spotify = spotify; }