/// <summary> /// Initializes a new instance of the <see cref="ApiClient" /> class. /// </summary> /// <param name="settings">The settings.</param> public ApiClient(ConnectionSettings settings) { Ensure.That(settings).IsNotNull(); _mediaTypeFormatter = new JsonMediaTypeFormatter { SerializerSettings = new JsonSerializerSettings { Converters = new List<JsonConverter> { new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd'T'HH:mm:sszzz" } } } }; var baseUri = BaseUriUtility.GetBaseUri(settings.Version); _httpClient = new Lazy<HttpClient>(() => GetHttpClient(baseUri, settings.Token)); }
/// <summary> /// Initializes a new instance of the <see cref="ApiClient" /> class. /// </summary> /// <param name="settings">The settings.</param> public ApiClient(ConnectionSettings settings) { Ensure.That(settings).IsNotNull(); _mediaTypeFormatter = new JsonMediaTypeFormatter { SerializerSettings = new JsonSerializerSettings { Converters = new List <JsonConverter> { new IsoDateTimeConverter { DateTimeFormat = "yyyyMMdd'T'HHmmsszzz" } } } }; var baseUri = BaseUriUtility.GetBaseUri(settings.Url, settings.Version, settings.AuthenticationType); switch (settings.AuthenticationType) { case AuthenticationType.GuestAuth: _httpClient = new Lazy <HttpClient>(() => GetHttpClient(baseUri)); break; case AuthenticationType.HttpAuth: _httpClient = new Lazy <HttpClient>(() => GetHttpClient(baseUri, settings.Username, settings.Password)); break; default: throw new NotSupportedException($"Authentication type '{settings.AuthenticationType}' is not supported."); } }
public void CanGetBaseUriForGuestAuth() { var baseUri = BaseUriUtility.GetBaseUri("http://teamcity.jetbrains.com", "10.0", AuthenticationType.GuestAuth); baseUri.ToString().ShouldBe("http://teamcity.jetbrains.com/guestAuth/app/rest/10.0/"); }
public void CanGetBaseUriForServerWithProtocolAndPort() { var baseUri = BaseUriUtility.GetBaseUri("https://teamcity.jetbrains.com:80", "10.0", AuthenticationType.HttpAuth); baseUri.ToString().ShouldBe("https://teamcity.jetbrains.com:80/httpAuth/app/rest/10.0/"); }
public void WillThrowIfUnsupportedScheme() { Assert.Throws <NotSupportedException>(() => BaseUriUtility.GetBaseUri("ftp://teamcity.jetbrains.com", "10.0", AuthenticationType.HttpAuth)); }