33using System . Web . Script . Serialization ;
44using SendGrid . Helpers . Mail ;
55using Newtonsoft . Json ;
6+ using System . Threading . Tasks ;
67
78namespace Example
89{
@@ -11,15 +12,15 @@ internal class Example
1112 private static void Main ( )
1213 {
1314 // v3 Mail Helper
14- HelloEmail ( ) ; // this will actually send an email
15- KitchenSink ( ) ; // this will only send an email if you set SandBox Mode to false
15+ HelloEmail ( ) . Wait ( ) ; // this will actually send an email
16+ KitchenSink ( ) . Wait ( ) ; // this will only send an email if you set SandBox Mode to false
1617
1718 // v3 Web API
18- ApiKeys ( ) ;
19+ ApiKeys ( ) . Wait ( ) ;
1920
2021 }
2122
22- private static void HelloEmail ( )
23+ private static async Task HelloEmail ( )
2324 {
2425 String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
2526 dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
@@ -32,7 +33,7 @@ private static void HelloEmail()
3233 Email email = new Email ( "[email protected] " ) ; 3334 mail . Personalization [ 0 ] . AddTo ( email ) ;
3435
35- dynamic response = sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
36+ dynamic response = await sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
3637 Console . WriteLine ( response . StatusCode ) ;
3738 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
3839 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -42,7 +43,7 @@ private static void HelloEmail()
4243
4344 }
4445
45- private static void KitchenSink ( )
46+ private static async Task KitchenSink ( )
4647 {
4748 String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
4849 dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
@@ -229,7 +230,7 @@ private static void KitchenSink()
229230 email . Address = "[email protected] " ; 230231 mail . ReplyTo = email ;
231232
232- dynamic response = sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
233+ dynamic response = await sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
233234 Console . WriteLine ( response . StatusCode ) ;
234235 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
235236 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -238,15 +239,15 @@ private static void KitchenSink()
238239 Console . ReadLine ( ) ;
239240 }
240241
241- private static void ApiKeys ( )
242+ private static async Task ApiKeys ( )
242243 {
243244 String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
244245 dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
245246
246247 string queryParams = @"{
247248 'limit': 100
248249 }" ;
249- dynamic response = sg . client . api_keys . get ( queryParams : queryParams ) ;
250+ dynamic response = await sg . client . api_keys . get ( queryParams : queryParams ) ;
250251 Console . WriteLine ( response . StatusCode ) ;
251252 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
252253 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -264,7 +265,7 @@ private static void ApiKeys()
264265 ]
265266 }" ;
266267 Object json = JsonConvert . DeserializeObject < Object > ( requestBody ) ;
267- response = sg . client . api_keys . post ( requestBody : json . ToString ( ) ) ;
268+ response = await sg . client . api_keys . post ( requestBody : json . ToString ( ) ) ;
268269 Console . WriteLine ( response . StatusCode ) ;
269270 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
270271 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -276,7 +277,7 @@ private static void ApiKeys()
276277 Console . ReadLine ( ) ;
277278
278279 // GET Single
279- response = sg . client . api_keys . _ ( api_key_id ) . get ( ) ;
280+ response = await sg . client . api_keys . _ ( api_key_id ) . get ( ) ;
280281 Console . WriteLine ( response . StatusCode ) ;
281282 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
282283 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -289,7 +290,7 @@ private static void ApiKeys()
289290 'name': 'A New Hope'
290291 }" ;
291292 json = JsonConvert . DeserializeObject < Object > ( requestBody ) ;
292- response = sg . client . api_keys . _ ( api_key_id ) . patch ( requestBody : json . ToString ( ) ) ;
293+ response = await sg . client . api_keys . _ ( api_key_id ) . patch ( requestBody : json . ToString ( ) ) ;
293294 Console . WriteLine ( response . StatusCode ) ;
294295 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
295296 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -306,7 +307,7 @@ private static void ApiKeys()
306307 ]
307308 }" ;
308309 json = JsonConvert . DeserializeObject < Object > ( requestBody ) ;
309- response = sg . client . api_keys . _ ( api_key_id ) . put ( requestBody : json . ToString ( ) ) ;
310+ response = await sg . client . api_keys . _ ( api_key_id ) . put ( requestBody : json . ToString ( ) ) ;
310311 Console . WriteLine ( response . StatusCode ) ;
311312 Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
312313 Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -315,7 +316,7 @@ private static void ApiKeys()
315316 Console . ReadLine ( ) ;
316317
317318 // DELETE
318- response = sg . client . api_keys . _ ( api_key_id ) . delete ( ) ;
319+ response = await sg . client . api_keys . _ ( api_key_id ) . delete ( ) ;
319320 Console . WriteLine ( response . StatusCode ) ;
320321 Console . WriteLine ( response . Headers . ToString ( ) ) ;
321322
0 commit comments