예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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
                       ));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 public OAuthClient(SpotifyClientConfig config) : base(ValidateConfig(config))
 {
 }
예제 #7
0
 public OAuthClient() : this(SpotifyClientConfig.CreateDefault())
 {
 }
예제 #8
0
 public SpotifyClient(string token, string tokenType = "Bearer") :
     this(SpotifyClientConfig.CreateDefault(token, tokenType))
 {
 }