Skip to content

Commit da840ea

Browse files
Merge remote-tracking branch 'refs/remotes/origin/master' into owre-master
# Conflicts: # SendGrid/UnitTest/UnitTest.cs
2 parents ac3dad8 + ac88fdb commit da840ea

File tree

36 files changed

+1453
-1326
lines changed

36 files changed

+1453
-1326
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [8.0.1] - 2016-07-25 ##
5+
### Added
6+
- [Troubleshooting](https://github.com/sendgrid/sendgrid-csharp/blob/master/TROUBLESHOOTING.md) section
7+
8+
## [8.0.0] - 2016-07-22 ##
9+
## BREAKING CHANGE
10+
- updated dependency on [SendGrid.CSharp.HTTP.Client](https://github.com/sendgrid/csharp-http-client/releases/tag/v3.0.0), which had a breaking change
11+
- Fixes [issue #259](https://github.com/sendgrid/sendgrid-csharp/issues/259)
12+
- the async behavior in the HTTP client has changed, as we don’t block on .Result anymore 
13+
- Updated USAGE, examples and README to demonstrate await usage
14+
415
## [7.1.1] - 2016-07-20 ##
516
### Added
617
- README updates

README.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**This library allows you to quickly and easily use the SendGrid Web API v3 via C# with .NET.**
44

5-
Version 7.X.X of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
5+
Version 7.X.X+ of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
66

77
This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-csharp/issues) and [pull requests](https://github.com/sendgrid/sendgrid-csharp/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.
88

@@ -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
}
@@ -194,6 +218,10 @@ Quick links:
194218
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#cla)
195219
- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#improvements_to_the_codebase)
196220

221+
# Troubleshooting
222+
223+
Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-csharp/blob/master/TROUBLESHOOTING.md) for common library issues.
224+
197225
# About
198226

199227
sendgrid-csharp is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).

SendGrid/Example/Example.cs

Lines changed: 22 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,14 @@ 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+
// If you want to use a transactional [template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html),
37+
// the following code will replace the above subject and content. The sample code assumes you have defined
38+
// substitution variables [KEY_1] and [KEY_2], to be replaced by VALUE_1 and VALUE_2 respectively, in your template.
39+
//mail.TemplateId = "TEMPLATE_ID";
40+
//mail.Personalization[0].AddSubstitution("[KEY_1]", "VALUE_1");
41+
//mail.Personalization[0].AddSubstitution("[KEY_2]", "VALUE_2");
42+
43+
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
3644
Console.WriteLine(response.StatusCode);
3745
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
3846
Console.WriteLine(response.Headers.ToString());
@@ -42,7 +50,7 @@ private static void HelloEmail()
4250

4351
}
4452

45-
private static void KitchenSink()
53+
private static async Task KitchenSink()
4654
{
4755
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
4856
dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
@@ -229,7 +237,7 @@ private static void KitchenSink()
229237
email.Address = "[email protected]";
230238
mail.ReplyTo = email;
231239

232-
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
240+
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
233241
Console.WriteLine(response.StatusCode);
234242
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
235243
Console.WriteLine(response.Headers.ToString());
@@ -238,15 +246,15 @@ private static void KitchenSink()
238246
Console.ReadLine();
239247
}
240248

241-
private static void ApiKeys()
249+
private static async Task ApiKeys()
242250
{
243251
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
244252
dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com");
245253

246254
string queryParams = @"{
247255
'limit': 100
248256
}";
249-
dynamic response = sg.client.api_keys.get(queryParams: queryParams);
257+
dynamic response = await sg.client.api_keys.get(queryParams: queryParams);
250258
Console.WriteLine(response.StatusCode);
251259
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
252260
Console.WriteLine(response.Headers.ToString());
@@ -264,7 +272,7 @@ private static void ApiKeys()
264272
]
265273
}";
266274
Object json = JsonConvert.DeserializeObject<Object>(requestBody);
267-
response = sg.client.api_keys.post(requestBody: json.ToString());
275+
response = await sg.client.api_keys.post(requestBody: json.ToString());
268276
Console.WriteLine(response.StatusCode);
269277
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
270278
Console.WriteLine(response.Headers.ToString());
@@ -276,7 +284,7 @@ private static void ApiKeys()
276284
Console.ReadLine();
277285

278286
// GET Single
279-
response = sg.client.api_keys._(api_key_id).get();
287+
response = await sg.client.api_keys._(api_key_id).get();
280288
Console.WriteLine(response.StatusCode);
281289
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
282290
Console.WriteLine(response.Headers.ToString());
@@ -289,7 +297,7 @@ private static void ApiKeys()
289297
'name': 'A New Hope'
290298
}";
291299
json = JsonConvert.DeserializeObject<Object>(requestBody);
292-
response = sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString());
300+
response = await sg.client.api_keys._(api_key_id).patch(requestBody: json.ToString());
293301
Console.WriteLine(response.StatusCode);
294302
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
295303
Console.WriteLine(response.Headers.ToString());
@@ -306,7 +314,7 @@ private static void ApiKeys()
306314
]
307315
}";
308316
json = JsonConvert.DeserializeObject<Object>(requestBody);
309-
response = sg.client.api_keys._(api_key_id).put(requestBody: json.ToString());
317+
response = await sg.client.api_keys._(api_key_id).put(requestBody: json.ToString());
310318
Console.WriteLine(response.StatusCode);
311319
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
312320
Console.WriteLine(response.Headers.ToString());
@@ -315,7 +323,7 @@ private static void ApiKeys()
315323
Console.ReadLine();
316324

317325
// DELETE
318-
response = sg.client.api_keys._(api_key_id).delete();
326+
response = await sg.client.api_keys._(api_key_id).delete();
319327
Console.WriteLine(response.StatusCode);
320328
Console.WriteLine(response.Headers.ToString());
321329

SendGrid/Example/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
// by using the '*' as shown below:
3636
// [assembly: AssemblyVersion("1.0.*")]
3737

38-
[assembly: AssemblyVersion("7.1.1")]
39-
[assembly: AssemblyFileVersion("7.1.1")]
38+
[assembly: AssemblyVersion("8.0.1")]
39+
[assembly: AssemblyFileVersion("8.0.1")]

SendGrid/SendGrid/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("7.1.1")]
36-
[assembly: AssemblyFileVersion("7.1.1")]
35+
[assembly: AssemblyVersion("8.0.1")]
36+
[assembly: AssemblyFileVersion("8.0.1")]

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>

SendGrid/UnitTest/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("7.1.1")]
36-
[assembly: AssemblyFileVersion("7.1.1")]
35+
[assembly: AssemblyVersion("8.0.1")]
36+
[assembly: AssemblyFileVersion("8.0.1")]

0 commit comments

Comments
 (0)