コード例 #1
0
        private static SoundCloudClient GetClient(SoundCloudAuthInfo credentials)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSoundCloudClient(credentials);

            var provider = serviceCollection.BuildServiceProvider();

            return(provider.GetService <SoundCloudClient>());
        }
コード例 #2
0
        public SoundCloudClient(IHttpClientFactory httpClientFactory, SoundCloudAuthInfo authInfo)
        {
            AuthInfo = authInfo;

            var gateway = new SoundCloudApiGateway(httpClientFactory);

            Apps      = new Apps(gateway);
            Comments  = new Comments(gateway);
            OAuth2    = new OAuth2(gateway);
            Playlists = new Playlists(gateway);
            Tracks    = new Tracks(gateway);
            Users     = new Users(gateway);
            Me        = new Me(gateway);
            Resolve   = new Resolve(gateway);
        }
コード例 #3
0
        private static Uri AppendCredentials(Uri uri, SoundCloudAuthInfo credentials)
        {
            if (uri == null)
            {
                return(null);
            }


            if (uri.Query.Contains("oauth_token") || uri.Query.Contains("client_id"))
            {
                return(uri);
            }

            var delimiter = "&";

            if (string.IsNullOrEmpty(uri.Query))
            {
                delimiter = "?";
            }
            else if (uri.Query.Last() == '?')
            {
                delimiter = "";
            }

            var uriString = uri.ToString();

            if (!string.IsNullOrEmpty(credentials.AccessToken))
            {
                uriString += delimiter + "oauth_token=" + credentials.AccessToken;
                return(new Uri(uriString));
            }

            if (!string.IsNullOrEmpty(credentials.ClientId))
            {
                uriString += delimiter + "client_id=" + credentials.ClientId;
                return(new Uri(uriString));
            }

            return(new Uri(uriString));
        }
コード例 #4
0
 public SoundCloudAuthenticationHandler(SoundCloudAuthInfo credentials)
 {
     _credentials = credentials;
 }
        public static IHttpClientBuilder AddSoundCloudHttpClient(this IServiceCollection serviceCollection, SoundCloudAuthInfo credentials)
        {
            var version   = typeof(SoundCloudClient).Assembly.GetName().Version.ToString();
            var userAgent = new ProductInfoHeaderValue("SoundCloud.Api", version);

            serviceCollection.TryAddSingleton(credentials);
            serviceCollection.TryAddTransient <SoundCloudAuthenticationHandler>();

            var builder = serviceCollection.AddHttpClient(SoundCloudClient.HttpClientName);

            builder.AddHttpMessageHandler <SoundCloudAuthenticationHandler>();
            builder.ConfigureHttpClient(c => { c.DefaultRequestHeaders.UserAgent.Add(userAgent); });

            return(builder);
        }
        public static IServiceCollection AddSoundCloudClient(this IServiceCollection serviceCollection, SoundCloudAuthInfo credentials)
        {
            serviceCollection.AddSingleton <SoundCloudClient>();

            serviceCollection.AddSoundCloudHttpClient(credentials);

            return(serviceCollection);
        }