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); }
/// <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; }
public TokenHttpClientHandler(string token, string onBehalfOf) : base(onBehalfOf) { ArgumentCheck.ThrowIfNullOrEmpty(token, nameof(token)); _authenticationHeader = CreateAuthenticationHeader(token); }
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); }
public HttpRequestBuilder UseRequestUri(string requestUri) { ArgumentCheck.ThrowIfNullOrEmpty(requestUri, nameof(requestUri)); return(UseRequestUri(new Uri(requestUri))); }