Skip to content

Commit 3131327

Browse files
Merge pull request #356 from sendgrid/remove-dynamic
Initial removal of dynamic with some Client refactoring
2 parents 9a5dbe2 + 89f5252 commit 3131327

File tree

35 files changed

+1182
-1217
lines changed

35 files changed

+1182
-1217
lines changed

README.md

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ We appreciate your continued support, thank you!
3030

3131
## Prerequisites
3232

33-
- .NET version 4.5.2
33+
- .NET version 4.5 and above
3434
- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-csharp)
3535

3636
## Setup Environment Variables
@@ -51,14 +51,13 @@ For a sample implementation, check the [Example](https://github.com/sendgrid/sen
5151
Add the following namespaces to use the library:
5252
```csharp
5353
using System;
54-
using System.Web.Script.Serialization;
5554
using SendGrid;
56-
using SendGrid.Helpers.Mail; // Include if you want to use the Mail Helper
55+
using SendGrid.Helpers.Mail; // If you are using the Mail Helper
56+
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
5757
```
5858

5959
## Dependencies
6060

61-
- [SendGrid.CSharp.HTTP.Client](https://github.com/sendgrid/csharp-http-client)
6261
- [Newtonsoft.Json](http://www.newtonsoft.com/json)
6362

6463
<a name="quick_start"></a>
@@ -72,31 +71,35 @@ The following is the minimum needed code to send an email with the [/mail/send H
7271

7372
```csharp
7473
using System;
74+
using System.Collections.Generic;
75+
using System.Threading.Tasks;
76+
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
7577
using SendGrid;
7678
using SendGrid.Helpers.Mail;
77-
using System.Threading.Tasks;
7879

7980
namespace Example
8081
{
8182
internal class Example
8283
{
8384
private static void Main()
8485
{
85-
Execute().Wait();
86+
Execute().Wait();
8687
}
8788

8889
static async Task Execute()
8990
{
9091
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
91-
dynamic sg = new SendGridAPIClient(apiKey);
92+
Client client = new Client(apiKey);
9293

9394
Email from = new Email("[email protected]");
9495
string subject = "Hello World from the SendGrid CSharp Library!";
9596
Email to = new Email("[email protected]");
9697
Content content = new Content("text/plain", "Hello, Email!");
9798
Mail mail = new Mail(from, subject, to, content);
9899

99-
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
100+
Response response = await client.RequestAsync(method: Client.Methods.POST,
101+
requestBody: mail.Get(),
102+
urlPath: "mail/send");
100103
}
101104
}
102105
}
@@ -110,23 +113,24 @@ The following is the minimum needed code to send an email without the /mail/send
110113

111114
```csharp
112115
using System;
113-
using SendGrid;
114-
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
116+
using System.Collections.Generic;
115117
using System.Threading.Tasks;
118+
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
119+
using SendGrid;
116120

117121
namespace Example
118122
{
119123
internal class Example
120124
{
121125
private static void Main()
122126
{
123-
Execute().Wait();
127+
Execute().Wait();
124128
}
125129

126130
static async Task Execute()
127131
{
128-
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
129-
dynamic sg = new SendGridAPIClient(apiKey);
132+
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
133+
Client client = new Client(apiKey);
130134

131135
string data = @"{
132136
'personalizations': [
@@ -150,39 +154,15 @@ namespace Example
150154
]
151155
}";
152156
Object json = JsonConvert.DeserializeObject<Object>(data);
153-
dynamic response = await sg.client.mail.send.post(requestBody: json.ToString());
154-
}
155-
}
156-
}
157-
```
158-
159-
## General v3 Web API Usage (With Fluent Interface)
160-
161-
```csharp
162-
using System;
163-
using SendGrid;
164-
using System.Threading.Tasks;
165-
166-
namespace Example
167-
{
168-
internal class Example
169-
{
170-
private static void Main()
171-
{
172-
Execute().Wait();
157+
Response response = await client.RequestAsync(method: Client.Methods.POST,
158+
requestBody: json.ToString(),
159+
urlPath: "mail/send");
173160
}
174-
175-
static async Task Execute()
176-
{
177-
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
178-
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
179-
dynamic response = await sg.client.suppression.bounces.get();
180-
}
181161
}
182162
}
183163
```
184164

185-
## General v3 Web API Usage (Without Fluent Interface)
165+
## General v3 Web API Usage
186166

187167
```csharp
188168
using System;
@@ -200,10 +180,12 @@ namespace Example
200180

201181
static async Task Execute()
202182
{
203-
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
204-
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
205-
dynamic response = await sg.client._("suppression/bounces").get();
206-
}
183+
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
184+
Client client = new Client(apiKey);
185+
Response response = await client.RequestAsync(method: Client.Methods.GET,
186+
requestBody: json.ToString(),
187+
urlPath: "suppression/bounces");
188+
}
207189
}
208190
}
209191
```

0 commit comments

Comments
 (0)