3
3
using System . Web . Script . Serialization ;
4
4
using SendGrid . Helpers . Mail ;
5
5
using Newtonsoft . Json ;
6
+ using System . Threading . Tasks ;
6
7
7
8
namespace Example
8
9
{
@@ -11,15 +12,15 @@ internal class Example
11
12
private static void Main ( )
12
13
{
13
14
// 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
16
17
17
18
// v3 Web API
18
- ApiKeys ( ) ;
19
+ ApiKeys ( ) . Wait ( ) ;
19
20
20
21
}
21
22
22
- private static void HelloEmail ( )
23
+ private static async Task HelloEmail ( )
23
24
{
24
25
String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
25
26
dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
@@ -32,7 +33,7 @@ private static void HelloEmail()
32
33
Email email = new Email ( "[email protected] " ) ;
33
34
mail . Personalization [ 0 ] . AddTo ( email ) ;
34
35
35
- dynamic response = sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
36
+ dynamic response = await sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
36
37
Console . WriteLine ( response . StatusCode ) ;
37
38
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
38
39
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -42,7 +43,7 @@ private static void HelloEmail()
42
43
43
44
}
44
45
45
- private static void KitchenSink ( )
46
+ private static async Task KitchenSink ( )
46
47
{
47
48
String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
48
49
dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
@@ -229,7 +230,7 @@ private static void KitchenSink()
229
230
email . Address = "[email protected] " ;
230
231
mail . ReplyTo = email ;
231
232
232
- dynamic response = sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
233
+ dynamic response = await sg . client . mail . send . post ( requestBody : mail . Get ( ) ) ;
233
234
Console . WriteLine ( response . StatusCode ) ;
234
235
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
235
236
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -238,15 +239,15 @@ private static void KitchenSink()
238
239
Console . ReadLine ( ) ;
239
240
}
240
241
241
- private static void ApiKeys ( )
242
+ private static async Task ApiKeys ( )
242
243
{
243
244
String apiKey = Environment . GetEnvironmentVariable ( "SENDGRID_APIKEY" , EnvironmentVariableTarget . User ) ;
244
245
dynamic sg = new SendGrid . SendGridAPIClient ( apiKey , "https://api.sendgrid.com" ) ;
245
246
246
247
string queryParams = @"{
247
248
'limit': 100
248
249
}" ;
249
- dynamic response = sg . client . api_keys . get ( queryParams : queryParams ) ;
250
+ dynamic response = await sg . client . api_keys . get ( queryParams : queryParams ) ;
250
251
Console . WriteLine ( response . StatusCode ) ;
251
252
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
252
253
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -264,7 +265,7 @@ private static void ApiKeys()
264
265
]
265
266
}" ;
266
267
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 ( ) ) ;
268
269
Console . WriteLine ( response . StatusCode ) ;
269
270
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
270
271
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -276,7 +277,7 @@ private static void ApiKeys()
276
277
Console . ReadLine ( ) ;
277
278
278
279
// GET Single
279
- response = sg . client . api_keys . _ ( api_key_id ) . get ( ) ;
280
+ response = await sg . client . api_keys . _ ( api_key_id ) . get ( ) ;
280
281
Console . WriteLine ( response . StatusCode ) ;
281
282
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
282
283
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -289,7 +290,7 @@ private static void ApiKeys()
289
290
'name': 'A New Hope'
290
291
}" ;
291
292
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 ( ) ) ;
293
294
Console . WriteLine ( response . StatusCode ) ;
294
295
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
295
296
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -306,7 +307,7 @@ private static void ApiKeys()
306
307
]
307
308
}" ;
308
309
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 ( ) ) ;
310
311
Console . WriteLine ( response . StatusCode ) ;
311
312
Console . WriteLine ( response . Body . ReadAsStringAsync ( ) . Result ) ;
312
313
Console . WriteLine ( response . Headers . ToString ( ) ) ;
@@ -315,7 +316,7 @@ private static void ApiKeys()
315
316
Console . ReadLine ( ) ;
316
317
317
318
// DELETE
318
- response = sg . client . api_keys . _ ( api_key_id ) . delete ( ) ;
319
+ response = await sg . client . api_keys . _ ( api_key_id ) . delete ( ) ;
319
320
Console . WriteLine ( response . StatusCode ) ;
320
321
Console . WriteLine ( response . Headers . ToString ( ) ) ;
321
322
0 commit comments