Skip to content

Commit f46ea6f

Browse files
Merge pull request #286 from sendgrid/259-async-fix
Update dependency for async fix
2 parents 4c8297a + ccef94d commit f46ea6f

File tree

31 files changed

+1346
-1319
lines changed

31 files changed

+1346
-1319
lines changed

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,29 @@ The following is the minimum needed code to send an email with the [/mail/send H
5757
using System;
5858
using SendGrid;
5959
using SendGrid.Helpers.Mail;
60+
using System.Threading.Tasks;
6061

6162
namespace Example
6263
{
6364
internal class Example
6465
{
6566
private static void Main()
6667
{
67-
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
68+
Execute.Wait();
69+
}
70+
71+
static async Task Execute()
72+
{
73+
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
6874
dynamic sg = new SendGridAPIClient(apiKey);
6975

7076
Email from = new Email("[email protected]");
71-
String subject = "Hello World from the SendGrid CSharp Library!";
77+
string subject = "Hello World from the SendGrid CSharp Library!";
7278
Email to = new Email("[email protected]");
7379
Content content = new Content("text/plain", "Hello, Email!");
7480
Mail mail = new Mail(from, subject, to, content);
7581

76-
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
82+
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
7783
}
7884
}
7985
}
@@ -89,12 +95,18 @@ The following is the minimum needed code to send an email without the /mail/send
8995
using System;
9096
using SendGrid;
9197
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
98+
using System.Threading.Tasks;
9299

93100
namespace Example
94101
{
95102
internal class Example
96103
{
97104
private static void Main()
105+
{
106+
Execute.Wait();
107+
}
108+
109+
static async Task Execute()
98110
{
99111
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
100112
dynamic sg = new SendGridAPIClient(apiKey);
@@ -121,7 +133,7 @@ namespace Example
121133
]
122134
}";
123135
Object json = JsonConvert.DeserializeObject<Object>(data);
124-
dynamic response = sg.client.mail.send.post(requestBody: json.ToString());
136+
dynamic response = await sg.client.mail.send.post(requestBody: json.ToString());
125137
}
126138
}
127139
}
@@ -132,17 +144,23 @@ namespace Example
132144
```csharp
133145
using System;
134146
using SendGrid;
147+
using System.Threading.Tasks;
135148

136149
namespace Example
137150
{
138151
internal class Example
139152
{
140153
private static void Main()
154+
{
155+
Execute.Wait();
156+
}
157+
158+
static async Task Execute()
141159
{
142160
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
143161
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
144-
dynamic response = sg.client.suppression.bounces.get();
145-
}
162+
dynamic response = await sg.client.suppression.bounces.get();
163+
}
146164
}
147165
}
148166
```
@@ -152,16 +170,22 @@ namespace Example
152170
```csharp
153171
using System;
154172
using SendGrid;
173+
using System.Threading.Tasks;
155174

156175
namespace Example
157176
{
158177
internal class Example
159178
{
160179
private static void Main()
161180
{
162-
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
163-
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
164-
dynamic response = sg.client._("suppression/bounces").get();
181+
Execute.Wait();
182+
}
183+
184+
static async Task Execute()
185+
{
186+
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
187+
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
188+
dynamic response = await sg.client._("suppression/bounces").get();
165189
}
166190
}
167191
}

SendGrid/Example/Example.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Web.Script.Serialization;
44
using SendGrid.Helpers.Mail;
55
using Newtonsoft.Json;
6+
using System.Threading.Tasks;
67

78
namespace 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

SendGrid/SendGrid/SendGrid.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4848
<Private>True</Private>
4949
</Reference>
50-
<Reference Include="SendGrid.CSharp.HTTP.Client, Version=2.0.7.0, Culture=neutral, PublicKeyToken=79219bf4e5ecaaca, processorArchitecture=MSIL">
51-
<HintPath>..\packages\SendGrid.CSharp.HTTP.Client.2.0.7\lib\SendGrid.CSharp.HTTP.Client.dll</HintPath>
50+
<Reference Include="SendGrid.CSharp.HTTP.Client, Version=3.0.0.0, Culture=neutral, PublicKeyToken=79219bf4e5ecaaca, processorArchitecture=MSIL">
51+
<HintPath>..\packages\SendGrid.CSharp.HTTP.Client.3.0.0\lib\SendGrid.CSharp.HTTP.Client.dll</HintPath>
5252
<Private>True</Private>
5353
</Reference>
5454
<Reference Include="System" />

SendGrid/SendGrid/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<packages>
33
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
44
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
5-
<package id="SendGrid.CSharp.HTTP.Client" version="2.0.7" targetFramework="net452" />
5+
<package id="SendGrid.CSharp.HTTP.Client" version="3.0.0" targetFramework="net452" />
66
</packages>

0 commit comments

Comments
 (0)