diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2016-07-22 17:23:28 -0700 |
---|---|---|
committer | Maxim Dubrovkin <maximdubrovkin@Maxims-MBP.Dlink> | 2016-09-20 20:13:16 +0500 |
commit | 05514e3eb89ea0ed5147c44bf2aa06dd0bb99925 (patch) | |
tree | 7857926882e2362907698534eeb9a3c28b52b86c /SendGrid/Example/Example.cs | |
parent | e4da460f1500f72ce30d3393c33785033940dc6f (diff) | |
download | sendgrid-csharp-05514e3eb89ea0ed5147c44bf2aa06dd0bb99925.zip sendgrid-csharp-05514e3eb89ea0ed5147c44bf2aa06dd0bb99925.tar.gz sendgrid-csharp-05514e3eb89ea0ed5147c44bf2aa06dd0bb99925.tar.bz2 |
Update dependency for async fix
Diffstat (limited to 'SendGrid/Example/Example.cs')
-rw-r--r-- | SendGrid/Example/Example.cs | 662 |
1 files changed, 328 insertions, 334 deletions
diff --git a/SendGrid/Example/Example.cs b/SendGrid/Example/Example.cs index 723bee2..3f2198a 100644 --- a/SendGrid/Example/Example.cs +++ b/SendGrid/Example/Example.cs @@ -1,334 +1,328 @@ -using System; -using System.Collections.Generic; -using System.Web.Script.Serialization; -using SendGrid.Helpers.Mail; -using Newtonsoft.Json; - -namespace Example -{ - internal class Example - { - private static void Main() - { - // v3 Mail Helper - HelloEmail(); // this will actually send an email - KitchenSink(); // this will only send an email if you set SandBox Mode to false - - // v3 Web API - ApiKeys(); - - } - - private static void HelloEmail() - { - String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); - dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); - - Email from = new Email("test@example.com"); - String subject = "Hello World from the SendGrid CSharp Library"; - Email to = new Email("test@example.com"); - Content content = new Content("text/plain", "Textual content"); - Mail mail = new Mail(from, subject, to, content); - Email email = new Email("test2@example.com"); - mail.Personalization[0].AddTo(email); - - // If you want to use a transactional [template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html), - // the following code will replace the above subject and content. The sample code assumes you have defined - // substitution variables [KEY_1] and [KEY_2], to be replaced by VALUE_1 and VALUE_2 respectively, in your template. - //mail.TemplateId = "TEMPLATE_ID"; - //mail.Personalization[0].AddSubstitution("[KEY_1]", "VALUE_1"); - //mail.Personalization[0].AddSubstitution("[KEY_2]", "VALUE_2"); - - dynamic response = sg.client.mail.send.post(requestBody: mail.Get()); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine(mail.Get()); - Console.ReadLine(); - - } - - private static void KitchenSink() - { - String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); - dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); - - Mail mail = new Mail(); - - Email email = new Email(); - email.Name = "Example User"; - email.Address = "test@example.com"; - mail.From = email; - - mail.Subject = "Hello World from the SendGrid CSharp Library"; - - Personalization personalization = new Personalization(); - email = new Email(); - email.Name = "Example User"; - email.Address = "test1@example.com"; - personalization.AddTo(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test2@example.com"; - personalization.AddCc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test3@example.com"; - personalization.AddCc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test4@example.com"; - personalization.AddBcc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test5@example.com"; - personalization.AddBcc(email); - personalization.Subject = "Thank you for signing up, %name%"; - personalization.AddHeader("X-Test", "True"); - personalization.AddHeader("X-Mock", "True"); - personalization.AddSubstitution("%name%", "Example User"); - personalization.AddSubstitution("%city%", "Denver"); - personalization.AddCustomArgs("marketing", "false"); - personalization.AddCustomArgs("transactional", "true"); - personalization.SendAt = 1461775051; - mail.AddPersonalization(personalization); - - personalization = new Personalization(); - email = new Email(); - email.Name = "Example User"; - email.Address = "test1@example.com"; - personalization.AddTo(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test2@example.com"; - personalization.AddCc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test3@example.com"; - personalization.AddCc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test4@example.com"; - personalization.AddBcc(email); - email = new Email(); - email.Name = "Example User"; - email.Address = "test5@example.com"; - personalization.AddBcc(email); - personalization.Subject = "Thank you for signing up, %name%"; - personalization.AddHeader("X-Test", "True"); - personalization.AddHeader("X-Mock", "True"); - personalization.AddSubstitution("%name%", "Example User"); - personalization.AddSubstitution("%city%", "Denver"); - personalization.AddCustomArgs("marketing", "false"); - personalization.AddCustomArgs("transactional", "true"); - personalization.SendAt = 1461775051; - mail.AddPersonalization(personalization); - - Content content = new Content(); - content.Type = "text/plain"; - content.Value = "Textual content"; - mail.AddContent(content); - content = new Content(); - content.Type = "text/html"; - content.Value = "<html><body>HTML content</body></html>"; - mail.AddContent(content); - content = new Content(); - content.Type = "text/calendar"; - content.Value = "Party Time!!"; - mail.AddContent(content); - - Attachment attachment = new Attachment(); - attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"; - attachment.Type = "application/pdf"; - attachment.Filename = "balance_001.pdf"; - attachment.Disposition = "attachment"; - attachment.ContentId = "Balance Sheet"; - mail.AddAttachment(attachment); - - attachment = new Attachment(); - attachment.Content = "BwdW"; - attachment.Type = "image/png"; - attachment.Filename = "banner.png"; - attachment.Disposition = "inline"; - attachment.ContentId = "Banner"; - mail.AddAttachment(attachment); - - mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"; - - mail.AddHeader("X-Day", "Monday"); - mail.AddHeader("X-Month", "January"); - - mail.AddSection("%section1", "Substitution for Section 1 Tag"); - mail.AddSection("%section2", "Substitution for Section 2 Tag"); - - mail.AddCategory("customer"); - mail.AddCategory("vip"); - - mail.AddCustomArgs("campaign", "welcome"); - mail.AddCustomArgs("sequence", "2"); - - ASM asm = new ASM(); - asm.GroupId = 3; - List<int> groups_to_display = new List<int>() - { - 1, 4, 5 - }; - asm.GroupsToDisplay = groups_to_display; - mail.Asm = asm; - - mail.SendAt = 1461775051; - - mail.SetIpPoolId = "23"; - - // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) - // mail.BatchId = "some_batch_id"; - - MailSettings mailSettings = new MailSettings(); - BCCSettings bccSettings = new BCCSettings(); - bccSettings.Enable = true; - bccSettings.Email = "test@example.com"; - mailSettings.BccSettings = bccSettings; - BypassListManagement bypassListManagement = new BypassListManagement(); - bypassListManagement.Enable = true; - mailSettings.BypassListManagement = bypassListManagement; - FooterSettings footerSettings = new FooterSettings(); - footerSettings.Enable = true; - footerSettings.Text = "Some Footer Text"; - footerSettings.Html = "<bold>Some HTML Here</bold>"; - mailSettings.FooterSettings = footerSettings; - SandboxMode sandboxMode = new SandboxMode(); - sandboxMode.Enable = true; - mailSettings.SandboxMode = sandboxMode; - SpamCheck spamCheck = new SpamCheck(); - spamCheck.Enable = true; - spamCheck.Threshold = 1; - spamCheck.PostToUrl = "https://gotchya.example.com"; - mailSettings.SpamCheck = spamCheck; - mail.MailSettings = mailSettings; - - TrackingSettings trackingSettings = new TrackingSettings(); - ClickTracking clickTracking = new ClickTracking(); - clickTracking.Enable = true; - clickTracking.EnableText = false; - trackingSettings.ClickTracking = clickTracking; - OpenTracking openTracking = new OpenTracking(); - openTracking.Enable = true; - openTracking.SubstitutionTag = "Optional tag to replace with the open image in the body of the message"; - trackingSettings.OpenTracking = openTracking; - SubscriptionTracking subscriptionTracking = new SubscriptionTracking(); - subscriptionTracking.Enable = true; - subscriptionTracking.Text = "text to insert into the text/plain portion of the message"; - subscriptionTracking.Html = "<bold>HTML to insert into the text/html portion of the message</bold>"; - subscriptionTracking.SubstitutionTag = "text to insert into the text/plain portion of the message"; - trackingSettings.SubscriptionTracking = subscriptionTracking; - Ganalytics ganalytics = new Ganalytics(); - ganalytics.Enable = true; - ganalytics.UtmCampaign = "some campaign"; - ganalytics.UtmContent = "some content"; - ganalytics.UtmMedium = "some medium"; - ganalytics.UtmSource = "some source"; - ganalytics.UtmTerm = "some term"; - trackingSettings.Ganalytics = ganalytics; - mail.TrackingSettings = trackingSettings; - - email = new Email(); - email.Address = "test@example.com"; - mail.ReplyTo = email; - - dynamic response = sg.client.mail.send.post(requestBody: mail.Get()); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine(mail.Get()); - Console.ReadLine(); - } - - private static void ApiKeys() - { - String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); - dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); - - string queryParams = @"{ - 'limit': 100 - }"; - dynamic response = sg.client.api_keys.get(queryParams: queryParams); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine("\n\nPress any key to continue to POST."); - Console.ReadLine(); - - // POST - string requestBody = @"{ - 'name': 'My API Key 5', - 'scopes': [ - 'mail.send', - 'alerts.create', - 'alerts.read' - ] - }"; - Object json = JsonConvert.DeserializeObject<Object>(requestBody); - response = sg.client.api_keys.post(requestBody: json.ToString()); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - JavaScriptSerializer jss = new JavaScriptSerializer(); - var ds_response = jss.Deserialize<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result); - string api_key_id = ds_response["api_key_id"]; - - Console.WriteLine("\n\nPress any key to continue to GET single."); - Console.ReadLine(); - - // GET Single - response = sg.client.api_keys._(api_key_id).get(); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine("\n\nPress any key to continue to PATCH."); - Console.ReadLine(); - - // PATCH - requestBody = @"{ - 'name': 'A New Hope' - }"; - json = JsonConvert.DeserializeObject<Object>(requestBody); - response = sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString()); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine("\n\nPress any key to continue to PUT."); - Console.ReadLine(); - - // PUT - requestBody = @"{ - 'name': 'A New Hope', - 'scopes': [ - ' user.profile.read', - ' user.profile.update' - ] - }"; - json = JsonConvert.DeserializeObject<Object>(requestBody); - response = sg.client.api_keys._(api_key_id).put(requestBody: json.ToString()); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Body.ReadAsStringAsync().Result); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine("\n\nPress any key to continue to DELETE."); - Console.ReadLine(); - - // DELETE - response = sg.client.api_keys._(api_key_id).delete(); - Console.WriteLine(response.StatusCode); - Console.WriteLine(response.Headers.ToString()); - - Console.WriteLine("\n\nPress any key to exit."); - Console.ReadLine(); - - } - } -} +using System;
+using System.Collections.Generic;
+using System.Web.Script.Serialization;
+using SendGrid.Helpers.Mail;
+using Newtonsoft.Json;
+using System.Threading.Tasks;
+
+namespace Example
+{
+ internal class Example
+ {
+ private static void Main()
+ {
+ // v3 Mail Helper
+ HelloEmail().Wait(); // this will actually send an email
+ KitchenSink().Wait(); // this will only send an email if you set SandBox Mode to false
+
+ // v3 Web API
+ ApiKeys().Wait();
+
+ }
+
+ private static async Task HelloEmail()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
+
+ Email from = new Email("test@example.com");
+ String subject = "Hello World from the SendGrid CSharp Library";
+ Email to = new Email("test@example.com");
+ Content content = new Content("text/plain", "Textual content");
+ Mail mail = new Mail(from, subject, to, content);
+ Email email = new Email("test2@example.com");
+ mail.Personalization[0].AddTo(email);
+
+ dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine(mail.Get());
+ Console.ReadLine();
+
+ }
+
+ private static async Task KitchenSink()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
+
+ Mail mail = new Mail();
+
+ Email email = new Email();
+ email.Name = "Example User";
+ email.Address = "test@example.com";
+ mail.From = email;
+
+ mail.Subject = "Hello World from the SendGrid CSharp Library";
+
+ Personalization personalization = new Personalization();
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test1@example.com";
+ personalization.AddTo(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test2@example.com";
+ personalization.AddCc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test3@example.com";
+ personalization.AddCc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test4@example.com";
+ personalization.AddBcc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test5@example.com";
+ personalization.AddBcc(email);
+ personalization.Subject = "Thank you for signing up, %name%";
+ personalization.AddHeader("X-Test", "True");
+ personalization.AddHeader("X-Mock", "True");
+ personalization.AddSubstitution("%name%", "Example User");
+ personalization.AddSubstitution("%city%", "Denver");
+ personalization.AddCustomArgs("marketing", "false");
+ personalization.AddCustomArgs("transactional", "true");
+ personalization.SendAt = 1461775051;
+ mail.AddPersonalization(personalization);
+
+ personalization = new Personalization();
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test1@example.com";
+ personalization.AddTo(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test2@example.com";
+ personalization.AddCc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test3@example.com";
+ personalization.AddCc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test4@example.com";
+ personalization.AddBcc(email);
+ email = new Email();
+ email.Name = "Example User";
+ email.Address = "test5@example.com";
+ personalization.AddBcc(email);
+ personalization.Subject = "Thank you for signing up, %name%";
+ personalization.AddHeader("X-Test", "True");
+ personalization.AddHeader("X-Mock", "True");
+ personalization.AddSubstitution("%name%", "Example User");
+ personalization.AddSubstitution("%city%", "Denver");
+ personalization.AddCustomArgs("marketing", "false");
+ personalization.AddCustomArgs("transactional", "true");
+ personalization.SendAt = 1461775051;
+ mail.AddPersonalization(personalization);
+
+ Content content = new Content();
+ content.Type = "text/plain";
+ content.Value = "Textual content";
+ mail.AddContent(content);
+ content = new Content();
+ content.Type = "text/html";
+ content.Value = "<html><body>HTML content</body></html>";
+ mail.AddContent(content);
+ content = new Content();
+ content.Type = "text/calendar";
+ content.Value = "Party Time!!";
+ mail.AddContent(content);
+
+ Attachment attachment = new Attachment();
+ attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12";
+ attachment.Type = "application/pdf";
+ attachment.Filename = "balance_001.pdf";
+ attachment.Disposition = "attachment";
+ attachment.ContentId = "Balance Sheet";
+ mail.AddAttachment(attachment);
+
+ attachment = new Attachment();
+ attachment.Content = "BwdW";
+ attachment.Type = "image/png";
+ attachment.Filename = "banner.png";
+ attachment.Disposition = "inline";
+ attachment.ContentId = "Banner";
+ mail.AddAttachment(attachment);
+
+ mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932";
+
+ mail.AddHeader("X-Day", "Monday");
+ mail.AddHeader("X-Month", "January");
+
+ mail.AddSection("%section1", "Substitution for Section 1 Tag");
+ mail.AddSection("%section2", "Substitution for Section 2 Tag");
+
+ mail.AddCategory("customer");
+ mail.AddCategory("vip");
+
+ mail.AddCustomArgs("campaign", "welcome");
+ mail.AddCustomArgs("sequence", "2");
+
+ ASM asm = new ASM();
+ asm.GroupId = 3;
+ List<int> groups_to_display = new List<int>()
+ {
+ 1, 4, 5
+ };
+ asm.GroupsToDisplay = groups_to_display;
+ mail.Asm = asm;
+
+ mail.SendAt = 1461775051;
+
+ mail.SetIpPoolId = "23";
+
+ // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
+ // mail.BatchId = "some_batch_id";
+
+ MailSettings mailSettings = new MailSettings();
+ BCCSettings bccSettings = new BCCSettings();
+ bccSettings.Enable = true;
+ bccSettings.Email = "test@example.com";
+ mailSettings.BccSettings = bccSettings;
+ BypassListManagement bypassListManagement = new BypassListManagement();
+ bypassListManagement.Enable = true;
+ mailSettings.BypassListManagement = bypassListManagement;
+ FooterSettings footerSettings = new FooterSettings();
+ footerSettings.Enable = true;
+ footerSettings.Text = "Some Footer Text";
+ footerSettings.Html = "<bold>Some HTML Here</bold>";
+ mailSettings.FooterSettings = footerSettings;
+ SandboxMode sandboxMode = new SandboxMode();
+ sandboxMode.Enable = true;
+ mailSettings.SandboxMode = sandboxMode;
+ SpamCheck spamCheck = new SpamCheck();
+ spamCheck.Enable = true;
+ spamCheck.Threshold = 1;
+ spamCheck.PostToUrl = "https://gotchya.example.com";
+ mailSettings.SpamCheck = spamCheck;
+ mail.MailSettings = mailSettings;
+
+ TrackingSettings trackingSettings = new TrackingSettings();
+ ClickTracking clickTracking = new ClickTracking();
+ clickTracking.Enable = true;
+ clickTracking.EnableText = false;
+ trackingSettings.ClickTracking = clickTracking;
+ OpenTracking openTracking = new OpenTracking();
+ openTracking.Enable = true;
+ openTracking.SubstitutionTag = "Optional tag to replace with the open image in the body of the message";
+ trackingSettings.OpenTracking = openTracking;
+ SubscriptionTracking subscriptionTracking = new SubscriptionTracking();
+ subscriptionTracking.Enable = true;
+ subscriptionTracking.Text = "text to insert into the text/plain portion of the message";
+ subscriptionTracking.Html = "<bold>HTML to insert into the text/html portion of the message</bold>";
+ subscriptionTracking.SubstitutionTag = "text to insert into the text/plain portion of the message";
+ trackingSettings.SubscriptionTracking = subscriptionTracking;
+ Ganalytics ganalytics = new Ganalytics();
+ ganalytics.Enable = true;
+ ganalytics.UtmCampaign = "some campaign";
+ ganalytics.UtmContent = "some content";
+ ganalytics.UtmMedium = "some medium";
+ ganalytics.UtmSource = "some source";
+ ganalytics.UtmTerm = "some term";
+ trackingSettings.Ganalytics = ganalytics;
+ mail.TrackingSettings = trackingSettings;
+
+ email = new Email();
+ email.Address = "test@example.com";
+ mail.ReplyTo = email;
+
+ dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine(mail.Get());
+ Console.ReadLine();
+ }
+
+ private static async Task ApiKeys()
+ {
+ String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
+
+ string queryParams = @"{
+ 'limit': 100
+ }";
+ dynamic response = await sg.client.api_keys.get(queryParams: queryParams);
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to continue to POST.");
+ Console.ReadLine();
+
+ // POST
+ string requestBody = @"{
+ 'name': 'My API Key 5',
+ 'scopes': [
+ 'mail.send',
+ 'alerts.create',
+ 'alerts.read'
+ ]
+ }";
+ Object json = JsonConvert.DeserializeObject<Object>(requestBody);
+ response = await sg.client.api_keys.post(requestBody: json.ToString());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+ JavaScriptSerializer jss = new JavaScriptSerializer();
+ var ds_response = jss.Deserialize<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
+ string api_key_id = ds_response["api_key_id"];
+
+ Console.WriteLine("\n\nPress any key to continue to GET single.");
+ Console.ReadLine();
+
+ // GET Single
+ response = await sg.client.api_keys._(api_key_id).get();
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to continue to PATCH.");
+ Console.ReadLine();
+
+ // PATCH
+ requestBody = @"{
+ 'name': 'A New Hope'
+ }";
+ json = JsonConvert.DeserializeObject<Object>(requestBody);
+ response = await sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to continue to PUT.");
+ Console.ReadLine();
+
+ // PUT
+ requestBody = @"{
+ 'name': 'A New Hope',
+ 'scopes': [
+ ' user.profile.read',
+ ' user.profile.update'
+ ]
+ }";
+ json = JsonConvert.DeserializeObject<Object>(requestBody);
+ response = await sg.client.api_keys._(api_key_id).put(requestBody: json.ToString());
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Body.ReadAsStringAsync().Result);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to continue to DELETE.");
+ Console.ReadLine();
+
+ // DELETE
+ response = await sg.client.api_keys._(api_key_id).delete();
+ Console.WriteLine(response.StatusCode);
+ Console.WriteLine(response.Headers.ToString());
+
+ Console.WriteLine("\n\nPress any key to exit.");
+ Console.ReadLine();
+
+ }
+ }
+}
|