summaryrefslogtreecommitdiffstats
path: root/SendGrid
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2015-12-10 21:32:45 -0800
committerElmer Thomas <elmer@thinkingserious.com>2015-12-10 21:32:45 -0800
commit7002bfc825ea9904af7811a84740e001fbb34e0c (patch)
tree9279309173a9832fae2623fbc7145ec871834d93 /SendGrid
parent82ed30026efa402952e5977c45398e490e1998f2 (diff)
downloadsendgrid-csharp-7002bfc825ea9904af7811a84740e001fbb34e0c.zip
sendgrid-csharp-7002bfc825ea9904af7811a84740e001fbb34e0c.tar.gz
sendgrid-csharp-7002bfc825ea9904af7811a84740e001fbb34e0c.tar.bz2
Add POST, DELETE
Diffstat (limited to 'SendGrid')
-rw-r--r--SendGrid/Example/Program.cs35
-rw-r--r--SendGrid/SendGrid/Resources/UnsubscribeGroups.cs13
-rw-r--r--SendGrid/SendGridMail/Transport/Web.cs2
-rw-r--r--SendGrid/UnitTest/UnitTest.cs27
4 files changed, 48 insertions, 29 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs
index 096eae3..1d4fbf3 100644
--- a/SendGrid/Example/Program.cs
+++ b/SendGrid/Example/Program.cs
@@ -15,24 +15,18 @@ namespace Example
var to = "example@example.com";
var from = "example@example.com";
var fromName = "Jane Doe";
- // SendEmail(to, from, fromName);
+ SendEmail(to, from, fromName);
// Test viewing, creating, modifying and deleting API keys through our v3 Web API
- // ApiKeys();
+ ApiKeys();
UnsubscribeGroups();
}
- /*
private static void SendAsync(SendGrid.SendGridMessage message)
{
- // Create credentials, specifying your user Name and password.
- var username = Environment.GetEnvironmentVariable("SENDGRID_USERNAME");
- var password = Environment.GetEnvironmentVariable("SENDGRID_PASSWORD");
- //string apikey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
- var credentials = new NetworkCredential(username, password);
+ string apikey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
// Create a Web transport for sending email.
- var transportWeb = new SendGrid.Web(credentials);
- //var transportWeb2 = new SendGrid.Web(apikey);
+ var transportWeb = new SendGrid.Web(apikey);
// Send the email.
try
@@ -105,7 +99,6 @@ namespace Example
Console.WriteLine("API Key Deleted, press any key to end");
Console.ReadKey();
}
- */
private static void UnsubscribeGroups()
{
@@ -126,6 +119,26 @@ namespace Example
Console.WriteLine(responseGetUnique.Content.ReadAsStringAsync().Result);
Console.WriteLine("These is an Unsubscribe Group with ID: " + unsubscribeGroupID.ToString() + ". Press any key to continue.");
Console.ReadKey();
+
+ // POST UNSUBSCRIBE GROUP
+ HttpResponseMessage responsePost = client.UnsubscribeGroups.Post("C Sharp Unsubscribes", "Testing the C Sharp Library", false).Result;
+ var rawString = responsePost.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ var unsubscribeGroupId = jsonObject.id.ToString();
+ Console.WriteLine(responsePost.StatusCode);
+ Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("Unsubscribe Group created. Press any key to continue.");
+ Console.ReadKey();
+
+ // DELETE UNSUBSCRIBE GROUP
+ Console.WriteLine("Deleting Unsubscribe Group, please wait.");
+ HttpResponseMessage responseDelete = client.UnsubscribeGroups.Delete(unsubscribeGroupId).Result;
+ Console.WriteLine(responseDelete.StatusCode);
+ HttpResponseMessage responseFinal = client.UnsubscribeGroups.Get().Result;
+ Console.WriteLine(responseFinal.StatusCode);
+ Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("Unsubscribe Group Deleted, press any key to end");
+ Console.ReadKey();
}
}
}
diff --git a/SendGrid/SendGrid/Resources/UnsubscribeGroups.cs b/SendGrid/SendGrid/Resources/UnsubscribeGroups.cs
index a9de080..17d8ace 100644
--- a/SendGrid/SendGrid/Resources/UnsubscribeGroups.cs
+++ b/SendGrid/SendGrid/Resources/UnsubscribeGroups.cs
@@ -66,18 +66,5 @@ namespace SendGrid.Resources
{
return await _client.Delete(_endpoint + "/" + unsubscribeGroupId);
}
-
- /// <summary>
- /// Delete a suppression group.
- /// </summary>
- /// <param name="apiKeyId">ID of the suppression group to rename</param>
- /// <param name="apiKeyName">New supression group name</param>
- /// <returns>https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html</returns>
- public async Task<HttpResponseMessage> Patch(string unsubscribeGroupId, string unsubscribeGroupName)
- {
- var data = new JObject { { "name", unsubscribeGroupName } };
- return await _client.Patch(_endpoint + "/" + unsubscribeGroupId, data);
- }
-
}
} \ No newline at end of file
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs
index e08a5a2..c42ad49 100644
--- a/SendGrid/SendGridMail/Transport/Web.cs
+++ b/SendGrid/SendGridMail/Transport/Web.cs
@@ -7,8 +7,6 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Threading.Tasks;
-using System.Xml;
-using Exceptions;
using SendGrid.SmtpApi;
// ReSharper disable MemberCanBePrivate.Global
diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs
index fa1210e..853d59e 100644
--- a/SendGrid/UnitTest/UnitTest.cs
+++ b/SendGrid/UnitTest/UnitTest.cs
@@ -111,9 +111,8 @@ namespace UnitTest
TestGet();
TestGetUnique(unsubscribeGroupId);
- //TestPost();
- //TestPatch();
- //TestDelete();
+ TestPost();
+ TestDelete();
}
private void TestGet()
@@ -134,5 +133,27 @@ namespace UnitTest
Assert.IsNotNull(jsonObject);
}
+ private void TestPost()
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.Post("C Sharp Unsubscribes", "Testing the C Sharp Library", false).Result;
+ Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ string name = jsonObject.name.ToString();
+ string description = jsonObject.description.ToString();
+ _unsubscribe_groups_key_id = jsonObject.id.ToString();
+ bool is_default = jsonObject.is_default;
+ Assert.IsNotNull(name);
+ Assert.IsNotNull(description);
+ Assert.IsNotNull(_unsubscribe_groups_key_id);
+ Assert.IsNotNull(is_default);
+ }
+
+ private void TestDelete()
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.Delete(_unsubscribe_groups_key_id).Result;
+ Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
+ }
+
}
}