summaryrefslogtreecommitdiffstats
path: root/src/SendGrid/Client.cs
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-12-12 23:58:19 -0800
committerElmer Thomas <elmer@thinkingserious.com>2016-12-12 23:58:19 -0800
commit83a0891c8917d06031571015e24c1acf88ac4ae2 (patch)
tree7b7f015a1c4f8a587624ada56a0af7746ef0a882 /src/SendGrid/Client.cs
parentff603f56e723d3e49c453cfdfe8dcf05617b6b50 (diff)
downloadsendgrid-csharp-origin/single-email.zip
sendgrid-csharp-origin/single-email.tar.gz
sendgrid-csharp-origin/single-email.tar.bz2
Properties FTW, Cancellation Tokens, Reorganizeorigin/single-email
Based on feedback from @darrelmiller and @jkewley on issue #331 and @taspeotis on issue 317. See ExampleCore for working example.
Diffstat (limited to 'src/SendGrid/Client.cs')
-rw-r--r--src/SendGrid/Client.cs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/SendGrid/Client.cs b/src/SendGrid/Client.cs
index 4eabcea..3528fef 100644
--- a/src/SendGrid/Client.cs
+++ b/src/SendGrid/Client.cs
@@ -8,6 +8,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
namespace SendGrid
@@ -60,7 +61,7 @@ namespace SendGrid
public static class MimeType
{
- public static readonly string HTML = "text/html";
+ public static readonly string Html = "text/html";
public static readonly string Text = "text/plain";
}
@@ -73,7 +74,6 @@ namespace SendGrid
public string MediaType;
public IWebProxy WebProxy;
public enum Method { DELETE, GET, PATCH, POST, PUT }
- public Mail Mail { get; set; }
/// <summary>
/// REST API client.
@@ -113,7 +113,6 @@ namespace SendGrid
}
SetVersion(version);
SetUrlPath(urlPath);
- Mail = new Mail(this);
}
/// <summary>
@@ -222,7 +221,7 @@ namespace SendGrid
/// <summary>
/// Get the version of the API, override to customize
/// </summary>
- /// <returns>Version of the API</param>
+ /// <returns>Version of the API</returns>
public string GetVersion()
{
return Version;
@@ -234,9 +233,9 @@ namespace SendGrid
/// <param name="client">Client object ready for communication with API</param>
/// <param name="request">The parameters for the API call</param>
/// <returns>Response object</returns>
- public async Task<Response> MakeRequest(HttpClient client, HttpRequestMessage request)
+ public async Task<Response> MakeRequest(HttpClient client, HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken))
{
- HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
+ HttpResponseMessage response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
return new Response(response.StatusCode, response.Content, response.Headers);
}
@@ -251,7 +250,8 @@ namespace SendGrid
string requestBody = null,
Dictionary<string, string> requestHeaders = null,
string queryParams = null,
- string urlPath = null)
+ string urlPath = null,
+ CancellationToken cancellationToken = default(CancellationToken))
{
using (var client = BuildHttpClient())
{
@@ -305,7 +305,7 @@ namespace SendGrid
RequestUri = new Uri(endpoint),
Content = content
};
- return await MakeRequest(client, request).ConfigureAwait(false);
+ return await MakeRequest(client, request, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
@@ -319,5 +319,13 @@ namespace SendGrid
}
}
}
+
+ public async Task<Response> SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return await RequestAsync(Client.Method.POST,
+ msg.Serialize(),
+ urlPath: "mail/send",
+ cancellationToken: cancellationToken).ConfigureAwait(false);
+ }
}
}