コード例 #1
0
ファイル: ClientBase.cs プロジェクト: sashka3076/HIBP.NET
        private ClientBase(HttpClient client, ApiKey apiKey, string serviceName)
        {
            if (apiKey == null)
            {
                throw new InvalidApiKeyException();
            }

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new InvalidServiceNameException();
            }

            if (client == null)
            {
                this.client = new HttpClient();
            }
            else
            {
                this.client = client;
            }

            this.client.BaseAddress = new Uri("https://haveibeenpwned.com/api/v3/");
            this.SetMandatoryDefaultRequestHeaders(apiKey, serviceName);
        }
コード例 #2
0
ファイル: ClientBase.cs プロジェクト: sashka3076/HIBP.NET
 /// <summary>
 /// Sets the mandatory request headers.
 /// </summary>
 /// <param name="apiKey">The API key.</param>
 /// <param name="serviceName">Name of the service.</param>
 protected void SetMandatoryDefaultRequestHeaders(ApiKey apiKey, string serviceName)
 {
     this.client.DefaultRequestHeaders.Add(UserAgentHeader, serviceName);
     this.client.DefaultRequestHeaders.Add(HIBPApiKeyHeader, apiKey.Key);
 }
コード例 #3
0
ファイル: ClientBase.cs プロジェクト: sashka3076/HIBP.NET
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientBase" /> class.
 /// The name of the client calling the API (used as user-agent).
 /// </summary>
 /// <param name="apiKey">The API key.</param>
 /// <param name="serviceName">The service name.</param>
 /// <param name="httpClient">The HTTP client.</param>
 /// <exception cref="ArgumentException">To interact with the HIBP API a name must be provided for the useragent string. This name is ment to be to distinguish your service from others. - serviceName.</exception>
 protected ClientBase(ApiKey apiKey, string serviceName, HttpClient httpClient = null)
     : this(httpClient, apiKey, serviceName)
 {
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PastesClient" /> class.
 /// </summary>
 /// <param name="apiKey">The API key.</param>
 /// <param name="serviceName">The service name.</param>
 /// <param name="client">The client. If none is provided, a new one will be created.</param>
 public PastesClient(ApiKey apiKey, string serviceName, HttpClient client = null)
     : base(apiKey, serviceName, client)
 {
 }