public void WithToken_CreatesNewInstance() { var token = "my-token"; var defaultConfig = SpotifyClientConfig.CreateDefault(); var tokenConfig = defaultConfig.WithToken(token); Assert.AreEqual(token, (tokenConfig.Authenticator as TokenAuthenticator).Token); Assert.AreNotEqual(defaultConfig, tokenConfig); Assert.AreEqual(null, defaultConfig.Authenticator); }
public void CreateDefault_CorrectDefaults() { var defaultConfig = SpotifyClientConfig.CreateDefault(); Assert.IsInstanceOf(typeof(SimplePaginator), defaultConfig.DefaultPaginator); Assert.IsInstanceOf(typeof(NetHttpClient), defaultConfig.HTTPClient); Assert.IsInstanceOf(typeof(NewtonsoftJSONSerializer), defaultConfig.JSONSerializer); Assert.AreEqual(SpotifyUrls.APIV1, defaultConfig.BaseAddress); Assert.AreEqual(null, defaultConfig.Authenticator); Assert.AreEqual(null, defaultConfig.HTTPLogger); Assert.AreEqual(null, defaultConfig.RetryHandler); }
private static APIConnector ValidateConfig(SpotifyClientConfig config) { Ensure.ArgumentNotNull(config, nameof(config)); return(new APIConnector( config.BaseAddress, config.Authenticator, config.JSONSerializer, config.HTTPClient, config.RetryHandler, config.HTTPLogger )); }
public void CreateDefault_CorrectDefaultsWithToken() { var token = "my-token"; var tokenType = "Bearer"; var defaultConfig = SpotifyClientConfig.CreateDefault(token, tokenType); Assert.IsInstanceOf(typeof(SimplePaginator), defaultConfig.DefaultPaginator); Assert.IsInstanceOf(typeof(NetHttpClient), defaultConfig.HTTPClient); Assert.IsInstanceOf(typeof(NewtonsoftJSONSerializer), defaultConfig.JSONSerializer); Assert.AreEqual(SpotifyUrls.APIV1, defaultConfig.BaseAddress); Assert.AreEqual(null, defaultConfig.HTTPLogger); Assert.AreEqual(null, defaultConfig.RetryHandler); Assert.IsInstanceOf(typeof(TokenAuthenticator), defaultConfig.Authenticator); var tokenHeaderAuth = defaultConfig.Authenticator as TokenAuthenticator; Assert.AreEqual(token, tokenHeaderAuth.Token); Assert.AreEqual(tokenType, tokenHeaderAuth.TokenType); }
public SpotifyClient(SpotifyClientConfig config) { Ensure.ArgumentNotNull(config, nameof(config)); if (config.Authenticator == null) { throw new NullReferenceException("Authenticator in config is null. Please supply it via `WithAuthenticator` or `WithToken`"); } _apiConnector = new APIConnector( config.BaseAddress, config.Authenticator, config.JSONSerializer, config.HTTPClient, config.RetryHandler, config.HTTPLogger ); _apiConnector.ResponseReceived += (sender, response) => { LastResponse = response; }; DefaultPaginator = config.DefaultPaginator; UserProfile = new UserProfileClient(_apiConnector); Browse = new BrowseClient(_apiConnector); Shows = new ShowsClient(_apiConnector); Playlists = new PlaylistsClient(_apiConnector); Search = new SearchClient(_apiConnector); Follow = new FollowClient(_apiConnector); Tracks = new TracksClient(_apiConnector); Player = new PlayerClient(_apiConnector); Albums = new AlbumsClient(_apiConnector); Artists = new ArtistsClient(_apiConnector); Personalization = new PersonalizationClient(_apiConnector); Episodes = new EpisodesClient(_apiConnector); Library = new LibraryClient(_apiConnector); }
public OAuthClient(SpotifyClientConfig config) : base(ValidateConfig(config)) { }
public OAuthClient() : this(SpotifyClientConfig.CreateDefault()) { }
public SpotifyClient(string token, string tokenType = "Bearer") : this(SpotifyClientConfig.CreateDefault(token, tokenType)) { }