summaryrefslogtreecommitdiffstats
path: root/examples/alerts/alerts.cs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/alerts/alerts.cs')
-rw-r--r--examples/alerts/alerts.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/examples/alerts/alerts.cs b/examples/alerts/alerts.cs
new file mode 100644
index 0000000..26bd8f2
--- /dev/null
+++ b/examples/alerts/alerts.cs
@@ -0,0 +1,67 @@
+using System;
+using SendGrid.Helpers.Mail; // If you are using the Mail Helper
+
+string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+dynamic sg = new SendGrid.SendGridAPIClient(_apiKey);
+
+////////////////////////////////////////////////////////
+// Create a new Alert
+// POST /alerts
+
+string data = @"{
+ 'email_to': 'example@example.com',
+ 'frequency': 'daily',
+ 'type': 'stats_notification'
+}";
+dynamic response = sg.client.alerts.post(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Retrieve all alerts
+// GET /alerts
+
+dynamic response = sg.client.alerts.get();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Update an alert
+// PATCH /alerts/{alert_id}
+
+string data = @"{
+ 'email_to': 'example@example.com'
+}";
+var alert_id = "test_url_param";
+dynamic response = sg.client.alerts._(alert_id).patch(requestBody: data);
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Retrieve a specific alert
+// GET /alerts/{alert_id}
+
+var alert_id = "test_url_param";
+dynamic response = sg.client.alerts._(alert_id).get();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+
+////////////////////////////////////////////////////////
+// Delete an alert
+// DELETE /alerts/{alert_id}
+
+var alert_id = "test_url_param";
+dynamic response = sg.client.alerts._(alert_id).delete();
+Console.WriteLine(response.StatusCode);
+Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+Console.WriteLine(response.Headers.ToString());
+Console.ReadLine();
+