コード例 #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="OnspringClient"/>.
        /// </summary>
        /// <param name="clientConfig"></param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="clientConfig"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="OnspringClientConfiguration.ApiKey"/> is null/empty/whitespace or if the <see cref="OnspringClientConfiguration.BaseAddress"/> is invalid.</exception>
        public OnspringClient(OnspringClientConfiguration clientConfig)
        {
            Arg.IsNotNull(clientConfig, nameof(clientConfig));
            Arg.IsNotNullOrWhitespace(clientConfig.ApiKey, $"{nameof(clientConfig)}.{clientConfig.ApiKey}");
            Arg.IsValidUrl(clientConfig.BaseAddress, $"{nameof(clientConfig)}.{clientConfig.BaseAddress}");

            ClientConfig = clientConfig;
            HttpClient   = HttpClientFactory.GetHttpClient(clientConfig.BaseAddress);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="OnspringClient"/>. The BaseAddress on the <paramref name="httpClient"/> must be set prior to this.
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="httpClient"></param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="httpClient"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="apiKey"/> is null/empty/whitespace or if the <paramref name="httpClient"/>'s base address is invalid.</exception>
        public OnspringClient(string apiKey, HttpClient httpClient)
        {
            Arg.IsNotNullOrWhitespace(apiKey, nameof(apiKey));
            Arg.IsNotNull(httpClient, nameof(httpClient));
            Arg.IsNotNull(httpClient.BaseAddress, $"{nameof(httpClient)}.{nameof(httpClient.BaseAddress)}");

            ClientConfig = new OnspringClientConfiguration(httpClient.BaseAddress.ToString(), apiKey);
            HttpClient   = httpClient;
        }