forked from sendgrid/sendgrid-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendGridClient.cs
96 lines (88 loc) · 5.26 KB
/
SendGridClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
namespace SendGrid
{
/// <summary>
/// An HTTP client wrapper for interacting with Twilio SendGrid's API.
/// </summary>
public class SendGridClient : BaseClient
{
private static readonly SendGridClientOptions DefaultOptions = new SendGridClientOptions();
/// <summary>
/// Initializes a new instance of the <see cref="SendGridClient"/> class.
/// </summary>
/// <param name="webProxy">Web proxy.</param>
/// <param name="apiKey">Your Twilio SendGrid API key.</param>
/// <param name="host">Base url (e.g. https://api.sendgrid.com).</param>
/// <param name="requestHeaders">A dictionary of request headers.</param>
/// <param name="version">API version, override AddVersion to customize.</param>
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint).</param>
/// <param name="httpErrorAsException">Indicates whether HTTP error responses should be raised as exceptions. Default is false.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = null, string urlPath = null, bool httpErrorAsException = false)
: base(webProxy, buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SendGridClient"/> class.
/// </summary>
/// <param name="httpClient">An optional http client which may me injected in order to facilitate testing.</param>
/// <param name="apiKey">Your Twilio SendGrid API key.</param>
/// <param name="host">Base url (e.g. https://api.sendgrid.com).</param>
/// <param name="requestHeaders">A dictionary of request headers.</param>
/// <param name="version">API version, override AddVersion to customize.</param>
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint).</param>
/// <param name="httpErrorAsException">Indicates whether HTTP error responses should be raised as exceptions. Default is false.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
public SendGridClient(HttpClient httpClient, string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = null, string urlPath = null, bool httpErrorAsException = false)
: base(httpClient, buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SendGridClient"/> class.
/// </summary>
/// <param name="apiKey">Your Twilio SendGrid API key.</param>
/// <param name="host">Base url (e.g. https://api.sendgrid.com).</param>
/// <param name="requestHeaders">A dictionary of request headers.</param>
/// <param name="version">API version, override AddVersion to customize.</param>
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint).</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
public SendGridClient(string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = null, string urlPath = null)
: base(buildOptions(apiKey, host, requestHeaders, version, urlPath, false))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SendGridClient"/> class.
/// </summary>
/// <param name="options">A <see cref="SendGridClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
public SendGridClient(SendGridClientOptions options)
: base(options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SendGridClient"/> class.
/// </summary>
/// <param name="httpClient">An optional HTTP client which may me injected in order to facilitate testing.</param>
/// <param name="options">A <see cref="SendGridClientOptions"/> instance that defines the configuration settings to use with the client.</param>
/// <returns>Interface to the Twilio SendGrid REST API.</returns>
public SendGridClient(HttpClient httpClient, SendGridClientOptions options)
: base(httpClient, options)
{
}
private static SendGridClientOptions buildOptions(string apiKey, string host, Dictionary<string, string> requestHeaders, string version, string urlPath, bool httpErrorAsException)
{
return new SendGridClientOptions
{
ApiKey = apiKey, // No default.
Host = host ?? DefaultOptions.Host,
RequestHeaders = requestHeaders ?? DefaultOptions.RequestHeaders,
Version = version ?? DefaultOptions.Version,
UrlPath = urlPath ?? DefaultOptions.UrlPath,
HttpErrorAsException = httpErrorAsException
};
}
}
}