Beispiel #1
0
        public HttpRequestBuilder AddPath(string path)
        {
            ArgumentCheck.ThrowIfNullOrEmpty(path, nameof(path));

            var pathBuilder = new StringBuilder(_requestUriBuilder.Path);

            if (pathBuilder.Length == 0)
            {
                if (path[0] != '/')
                {
                    pathBuilder.Append('/');
                }
            }
            else
            {
                if (pathBuilder[pathBuilder.Length - 1] == '/' && path[0] == '/')
                {
                    pathBuilder.Remove(pathBuilder.Length - 1, 1);
                }
                else if (pathBuilder[pathBuilder.Length - 1] != '/' && path[0] != '/')
                {
                    pathBuilder.Append('/');
                }
            }
            pathBuilder.Append(path);
            _requestUriBuilder.Path = pathBuilder.ToString();
            return(this);
        }
        public BasicHttpClientHandler(string user, string password)
        {
            ArgumentCheck.ThrowIfNullOrEmpty(user, nameof(user));
            ArgumentCheck.ThrowIfNullOrEmpty(password, nameof(password));

            _authenticationHeader = CreateAuthenticationHeader(user, password);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ZammadAccount"/> class.
        /// </summary>
        /// <param name="endpoint">The endpoint of the Zammad instance being used.</param>
        /// <param name="authentication">Specifies the authentication method who is used for authentication.</param>
        /// <param name="user">The user who is used for authentication.</param>
        /// <param name="password">The password who is used for authentication.</param>
        /// <param name="token">The token who is used for authentication.</param>
        public ZammadAccount(Uri endpoint, ZammadAuthentication authentication, string user, string password, string token)
        {
            ArgumentCheck.ThrowIfNull(endpoint, nameof(endpoint));

            switch (authentication)
            {
            case ZammadAuthentication.Basic:
            {
                ArgumentCheck.ThrowIfNullOrEmpty(user, nameof(user));
                ArgumentCheck.ThrowIfNullOrEmpty(password, nameof(password));
                break;
            }

            case ZammadAuthentication.Token:
            {
                ArgumentCheck.ThrowIfNullOrEmpty(token, nameof(token));
                break;
            }

            default:
            {
                throw new NotSupportedException($"Authentication \"{authentication}\" is not supported.");
            }
            }

            Endpoint       = endpoint;
            Authentication = authentication;
            Token          = token;
            User           = user;
            Password       = password;
        }
Beispiel #4
0
        public TokenHttpClientHandler(string token, string onBehalfOf)
            : base(onBehalfOf)
        {
            ArgumentCheck.ThrowIfNullOrEmpty(token, nameof(token));

            _authenticationHeader = CreateAuthenticationHeader(token);
        }
Beispiel #5
0
        public HttpRequestBuilder AddQuery(string key, string value)
        {
            ArgumentCheck.ThrowIfNullOrEmpty(key, nameof(key));
            ArgumentCheck.ThrowIfNull(value, nameof(value));

            var queryBuilder = new StringBuilder(_requestUriBuilder.Query);

            if (queryBuilder.Length == 0)
            {
                queryBuilder.Append('?');
            }
            else
            {
                queryBuilder.Append('&');
            }
            queryBuilder.AppendFormat("{0}={1}", key, value);
            _requestUriBuilder.Query = queryBuilder.ToString();
            return(this);
        }
Beispiel #6
0
        public HttpRequestBuilder UseRequestUri(string requestUri)
        {
            ArgumentCheck.ThrowIfNullOrEmpty(requestUri, nameof(requestUri));

            return(UseRequestUri(new Uri(requestUri)));
        }