/// <summary>
        /// Perfoms a PUT request using <paramref name="uri"/>.
        /// </summary>
        /// <param name="uri">Target of the PUT request</param>
        /// <returns>The response entity of the request</returns>
        protected async Task <IWebResult> UpdateAsync(Uri uri)
        {
            uri = uri.AppendCredentials(Credentials);
            var apiResponse = await Gateway.InvokeUpdateRequestAsync <StatusResponse>(uri);

            if (apiResponse.IsSuccess)
            {
                return(new SuccessWebResult <object>(null));
            }

            var errorMessage = new StringBuilder();

            if (apiResponse.ContainsData)
            {
                errorMessage.AppendLineIfNotEmpty(apiResponse.Data.Error);
                foreach (var message in apiResponse.Data.Errors)
                {
                    errorMessage.AppendLineIfNotEmpty(message.error_message);
                }
            }
            else
            {
                errorMessage.AppendLineIfNotEmpty(apiResponse.StatusDescription);
            }

            return(new ErrorWebResult <object>(errorMessage.ToString().Trim()));
        }
Exemple #2
0
        public void Test_AppendCredentials_No_Credentials()
        {
            var credentials = new SoundCloudCredentials();

            var uri = new Uri("http://test.com/?");

            uri = uri.AppendCredentials(credentials);

            Assert.That(uri.ToString(), Is.EqualTo("http://test.com/?"));
        }
Exemple #3
0
        public void Test_AppendCredentials_No_Query()
        {
            var credentials = new SoundCloudCredentials();

            credentials.ClientId = "clientId";

            var uri = new Uri("http://test.com/");

            uri = uri.AppendCredentials(credentials);

            Assert.That(uri.ToString(), Is.EqualTo("http://test.com/?client_id=clientId"));
        }
Exemple #4
0
        public void Test_AppendCredentials_Ampersand_Delimiter()
        {
            var credentials = new SoundCloudCredentials();

            credentials.ClientId = "clientId";

            var uri = new Uri("http://test.com/?query=value");

            uri = uri.AppendCredentials(credentials);

            Assert.That(uri.ToString(), Is.EqualTo("http://test.com/?query=value&client_id=clientId"));
        }
Exemple #5
0
        public void Test_AppendCredentials_AccessToken()
        {
            var credentials = new SoundCloudCredentials();

            credentials.AccessToken = "token";

            var uri = new Uri("http://test.com/?");

            uri = uri.AppendCredentials(credentials);

            Assert.That(uri.ToString(), Is.EqualTo("http://test.com/?oauth_token=token"));
        }
        /// <summary>
        /// Perfoms a GET request using <paramref name="uri"/>.
        /// </summary>
        /// <typeparam name="T">Type of the response ntity</typeparam>
        /// <param name="uri">Target of the GET request</param>
        /// <returns>The response entity of the request</returns>
        protected async Task <T> GetByIdAsync <T>(Uri uri) where T : Entity
        {
            uri = uri.AppendCredentials(Credentials);
            var apiResponse = await Gateway.InvokeGetRequestAsync <T>(uri);

            if (apiResponse.IsSuccess && apiResponse.ContainsData)
            {
                apiResponse.Data.AppendCredentialsToProperties(Credentials);
                return(apiResponse.Data);
            }

            return(null);
        }
        /// <summary>
        /// Perfoms a POST request with <paramref name="parameters"/> using <paramref name="uri"/>.
        /// </summary>
        /// <typeparam name="T">Type of the response entity</typeparam>
        /// <param name="uri">Target of the POST request</param>
        /// <param name="parameters">Additional Parameters send with the request</param>
        /// <returns>The response entity of the request</returns>
        protected IWebResult <T> Create <T>(Uri uri, IDictionary <string, object> parameters) where T : Entity
        {
            uri = uri.AppendCredentials(Credentials);
            var apiResponse = Gateway.InvokeCreateRequest <T>(uri, parameters);

            if (apiResponse.IsError)
            {
                return(new ErrorWebResult <T>(apiResponse.StatusDescription));
            }

            if (apiResponse.ContainsData)
            {
                apiResponse.Data.AppendCredentialsToProperties(Credentials);
                return(new SuccessWebResult <T>(apiResponse.Data));
            }

            return(new SuccessWebResult <T>(null));
        }
        /// <summary>
        /// Perfoms a POST request with <paramref name="entity"/> using <paramref name="uri"/>.
        /// </summary>
        /// <typeparam name="T">Type of the response entity</typeparam>
        /// <param name="uri">Target of the POST request</param>
        /// <param name="entity">Entity to be created</param>
        /// <returns>The response entity of the request</returns>
        protected async Task <IWebResult <T> > CreateAsync <T>(Uri uri, Entity entity) where T : Entity
        {
            uri = uri.AppendCredentials(Credentials);
            var apiResponse = await Gateway.InvokeCreateRequestAsync <T>(uri, entity);

            if (apiResponse.IsError)
            {
                return(new ErrorWebResult <T>(apiResponse.StatusDescription));
            }

            if (apiResponse.ContainsData)
            {
                apiResponse.Data.AppendCredentialsToProperties(Credentials);
                return(new SuccessWebResult <T>(apiResponse.Data));
            }

            return(new SuccessWebResult <T>(null));
        }