summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SendGrid/Example/Program.cs11
-rw-r--r--SendGrid/SendGrid/Client.cs16
-rw-r--r--SendGrid/SendGrid/Resources/APIKeys.cs17
-rw-r--r--SendGrid/UnitTest/UnitTest.cs36
4 files changed, 55 insertions, 25 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs
index c0f4295..4cdc71a 100644
--- a/SendGrid/Example/Program.cs
+++ b/SendGrid/Example/Program.cs
@@ -70,14 +70,14 @@ namespace Example
var client = new SendGrid.Client(apiKey);
// GET API KEYS
- HttpResponseMessage responseGet = client.ApiKeys.Get();
+ HttpResponseMessage responseGet = client.ApiKeys.Get().Result;
Console.WriteLine(responseGet.StatusCode);
Console.WriteLine(responseGet.Content.ReadAsStringAsync().Result);
Console.WriteLine("These are your current API Keys. Press any key to continue.");
Console.ReadKey();
// POST API KEYS
- HttpResponseMessage responsePost = client.ApiKeys.Post("CSharpTestKey");
+ HttpResponseMessage responsePost = client.ApiKeys.Post("CSharpTestKey").Result;
var rawString = responsePost.Content.ReadAsStringAsync().Result;
dynamic jsonObject = JObject.Parse(rawString);
var apiKeyId = jsonObject.api_key_id.ToString();
@@ -87,7 +87,7 @@ namespace Example
Console.ReadKey();
// PATCH API KEYS
- HttpResponseMessage responsePatch = client.ApiKeys.Patch(apiKeyId, "CSharpTestKeyPatched");
+ HttpResponseMessage responsePatch = client.ApiKeys.Patch(apiKeyId, "CSharpTestKeyPatched").Result;
Console.WriteLine(responsePatch.StatusCode);
Console.WriteLine(responsePatch.Content.ReadAsStringAsync().Result);
Console.WriteLine("API Key patched. Press any key to continue.");
@@ -95,8 +95,9 @@ namespace Example
// DELETE API KEYS
Console.WriteLine("Deleting API Key, please wait.");
- client.ApiKeys.Delete(apiKeyId);
- HttpResponseMessage responseFinal = client.ApiKeys.Get();
+ HttpResponseMessage responseDelete = client.ApiKeys.Delete(apiKeyId).Result;
+ Console.WriteLine(responseDelete.StatusCode);
+ HttpResponseMessage responseFinal = client.ApiKeys.Get().Result;
Console.WriteLine(responseFinal.StatusCode);
Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
Console.WriteLine("API Key Deleted, press any key to end");
diff --git a/SendGrid/SendGrid/Client.cs b/SendGrid/SendGrid/Client.cs
index 10cc1e8..dc45b85 100644
--- a/SendGrid/SendGrid/Client.cs
+++ b/SendGrid/SendGrid/Client.cs
@@ -94,32 +94,32 @@ namespace SendGrid
/// <param name="endpoint">Resource endpoint, do not prepend slash</param>
/// <returns>The resulting message from the API call</returns>
- public HttpResponseMessage Get(string endpoint)
+ public async Task<HttpResponseMessage> Get(string endpoint)
{
- return RequestAsync(Methods.GET, endpoint, null).Result;
+ return await RequestAsync(Methods.GET, endpoint, null);
}
/// <param name="endpoint">Resource endpoint, do not prepend slash</param>
/// <param name="data">An JObject representing the resource's data</param>
/// <returns>The resulting message from the API call</returns>
- public HttpResponseMessage Post(string endpoint, JObject data)
+ public async Task<HttpResponseMessage> Post(string endpoint, JObject data)
{
- return RequestAsync(Methods.POST, endpoint, data).Result;
+ return await RequestAsync(Methods.POST, endpoint, data);
}
/// <param name="endpoint">Resource endpoint, do not prepend slash</param>
/// <returns>The resulting message from the API call</returns>
- public HttpResponseMessage Delete(string endpoint)
+ public async Task<HttpResponseMessage> Delete(string endpoint)
{
- return RequestAsync(Methods.DELETE, endpoint, null).Result;
+ return await RequestAsync(Methods.DELETE, endpoint, null);
}
/// <param name="endpoint">Resource endpoint, do not prepend slash</param>
/// <param name="data">An JObject representing the resource's data</param>
/// <returns>The resulting message from the API call</returns>
- public HttpResponseMessage Patch(string endpoint, JObject data)
+ public async Task<HttpResponseMessage> Patch(string endpoint, JObject data)
{
- return RequestAsync(Methods.PATCH, endpoint, data).Result;
+ return await RequestAsync(Methods.PATCH, endpoint, data);
}
}
}
diff --git a/SendGrid/SendGrid/Resources/APIKeys.cs b/SendGrid/SendGrid/Resources/APIKeys.cs
index a3d8d35..9b98e7e 100644
--- a/SendGrid/SendGrid/Resources/APIKeys.cs
+++ b/SendGrid/SendGrid/Resources/APIKeys.cs
@@ -1,5 +1,6 @@
using System.Net.Http;
using System.Runtime.InteropServices;
+using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace SendGrid.Resources
@@ -25,9 +26,9 @@ namespace SendGrid.Resources
/// Get a list of active API Keys
/// </summary>
/// <returns>https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html</returns>
- public HttpResponseMessage Get()
+ public async Task<HttpResponseMessage> Get()
{
- return _client.Get(_endpoint);
+ return await _client.Get(_endpoint);
}
/// <summary>
@@ -35,10 +36,10 @@ namespace SendGrid.Resources
/// </summary>
/// <param name="apiKeyName">Name of the new API Key</param>
/// <returns>https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html</returns>
- public HttpResponseMessage Post(string apiKeyName)
+ public async Task<HttpResponseMessage> Post(string apiKeyName)
{
var data = new JObject {{"name", apiKeyName}};
- return _client.Post(_endpoint, data);
+ return await _client.Post(_endpoint, data);
}
/// <summary>
@@ -46,9 +47,9 @@ namespace SendGrid.Resources
/// </summary>
/// <param name="apiKeyId">ID of the API Key to delete</param>
/// <returns>https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html</returns>
- public HttpResponseMessage Delete(string apiKeyId)
+ public async Task<HttpResponseMessage> Delete(string apiKeyId)
{
- return _client.Delete(_endpoint + "/" + apiKeyId);
+ return await _client.Delete(_endpoint + "/" + apiKeyId);
}
/// <summary>
@@ -57,10 +58,10 @@ namespace SendGrid.Resources
/// <param name="apiKeyId">ID of the API Key to rename</param>
/// <param name="apiKeyName">New API Key name</param>
/// <returns>https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html</returns>
- public HttpResponseMessage Patch(string apiKeyId, string apiKeyName)
+ public async Task<HttpResponseMessage> Patch(string apiKeyId, string apiKeyName)
{
var data = new JObject { { "name", apiKeyName } };
- return _client.Patch(_endpoint + "/" + apiKeyId, data);
+ return await _client.Patch(_endpoint + "/" + apiKeyId, data);
}
}
diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs
index 9064d79..5d1b696 100644
--- a/SendGrid/UnitTest/UnitTest.cs
+++ b/SendGrid/UnitTest/UnitTest.cs
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Net.Http;
+using System.Threading.Tasks;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using SendGrid;
@@ -26,7 +27,7 @@ namespace UnitTest
private void TestGet()
{
- HttpResponseMessage response = client.ApiKeys.Get();
+ HttpResponseMessage response = client.ApiKeys.Get().Result;
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
string rawString = response.Content.ReadAsStringAsync().Result;
dynamic jsonObject = JObject.Parse(rawString);
@@ -36,7 +37,7 @@ namespace UnitTest
private void TestPost()
{
- HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey");
+ HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey").Result;
Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
string rawString = response.Content.ReadAsStringAsync().Result;
dynamic jsonObject = JObject.Parse(rawString);
@@ -50,7 +51,7 @@ namespace UnitTest
private void TestPatch()
{
- HttpResponseMessage response = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched");
+ HttpResponseMessage response = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched").Result;
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
string rawString = response.Content.ReadAsStringAsync().Result;
dynamic jsonObject = JObject.Parse(rawString);
@@ -62,8 +63,35 @@ namespace UnitTest
private void TestDelete()
{
- HttpResponseMessage response = client.ApiKeys.Delete(_api_key_id);
+ HttpResponseMessage response = client.ApiKeys.Delete(_api_key_id).Result;
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
+
+ [Test]
+ public void TestGetOnce()
+ {
+ var responseGet = client.ApiKeys.Get().Result;
+ }
+
+ [Test]
+ public void TestGetTenTimes()
+ {
+ HttpResponseMessage responseGet;
+ for (int i = 0; i < 10; i++)
+ {
+ responseGet = client.ApiKeys.Get().Result;
+ }
+ }
+
+ [Test]
+ public void TestGetTenTimesAsync()
+ {
+ Task[] tasks = new Task[10];
+ for (int i = 0; i < 10; i++)
+ {
+ tasks[i] = client.ApiKeys.Get();
+ }
+ Task.WaitAll(tasks);
+ }
}
}