diff options
Diffstat (limited to 'SendGrid')
-rw-r--r-- | SendGrid/Example/Program.cs | 35 | ||||
-rw-r--r-- | SendGrid/SendGrid/Resources/UnsubscribeGroups.cs | 13 | ||||
-rw-r--r-- | SendGrid/SendGridMail/Transport/Web.cs | 2 | ||||
-rw-r--r-- | SendGrid/UnitTest/UnitTest.cs | 27 |
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); + } + } } |