Skip to content

Commit 89f5252

Browse files
Updating documenation, Remove System.Web dependency
1 parent 80f6dc4 commit 89f5252

File tree

31 files changed

+575
-546
lines changed

31 files changed

+575
-546
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,9 +71,11 @@ 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
{
@@ -112,9 +113,10 @@ The following is the minimum needed code to send an email without the /mail/send
112113

113114
```csharp
114115
using System;
115-
using SendGrid;
116-
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
116+
using System.Collections.Generic;
117117
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;
118120

119121
namespace Example
120122
{

SendGrid/Example/Example.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Web.Script.Serialization;
4-
using SendGrid.Helpers.Mail;
5-
using Newtonsoft.Json;
63
using System.Threading.Tasks;
4+
using Newtonsoft.Json;
75
using SendGrid;
6+
using SendGrid.Helpers.Mail;
87

98
namespace Example
109
{
@@ -23,7 +22,7 @@ private static void Main()
2322
//TemplateWithoutHelperAsync().Wait();
2423

2524
// v3 Web API
26-
ApiKeysAsync().Wait();
25+
ASMGroupsAsync().Wait();
2726
}
2827

2928
private static async Task TemplateWithHelperAsync()
@@ -118,7 +117,7 @@ private static async Task HelloEmailAsync()
118117

119118
private static async Task KitchenSinkAsync()
120119
{
121-
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
120+
string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
122121
Client client = new Client(apiKey);
123122

124123
Mail mail = new Mail();
@@ -312,7 +311,7 @@ private static async Task KitchenSinkAsync()
312311
Console.ReadLine();
313312
}
314313

315-
private static async Task ApiKeysAsync()
314+
private static async Task ASMGroupsAsync()
316315
{
317316
string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
318317
Client client = new Client(apiKey);
@@ -340,8 +339,7 @@ private static async Task ApiKeysAsync()
340339
response = await client.RequestAsync(method: Client.Methods.POST,
341340
urlPath: "asm/groups",
342341
requestBody: json.ToString());
343-
JavaScriptSerializer jss = new JavaScriptSerializer();
344-
var ds_response = jss.Deserialize<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
342+
var ds_response = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
345343
string group_id = ds_response["id"].ToString();
346344
Console.WriteLine(response.StatusCode);
347345
Console.WriteLine(response.Body.ReadAsStringAsync().Result);

SendGrid/SendGrid/Client.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Net;
56
using System.Net.Http;
67
using System.Net.Http.Headers;
8+
using System.Reflection;
79
using System.Text;
810
using System.Threading.Tasks;
9-
using System.Web.Script.Serialization;
10-
using System.Web;
11-
using System.Reflection;
1211

1312
namespace SendGrid
1413
{
@@ -38,8 +37,7 @@ public Response(HttpStatusCode statusCode, HttpContent responseBody, HttpRespons
3837
/// <returns>Dictionary object representation of HttpContent</returns>
3938
public virtual Dictionary<string, dynamic> DeserializeResponseBody(HttpContent content)
4039
{
41-
JavaScriptSerializer jss = new JavaScriptSerializer();
42-
var dsContent = jss.Deserialize<Dictionary<string, dynamic>>(content.ReadAsStringAsync().Result);
40+
var dsContent = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(content.ReadAsStringAsync().Result);
4341
return dsContent;
4442
}
4543

@@ -99,7 +97,7 @@ public Client(string apiKey, string host = "https://api.sendgrid.com", Dictionar
9997
{
10098
Host = host;
10199
Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
102-
Dictionary<String, String> defaultHeaders = new Dictionary<String, String>();
100+
Dictionary<string, string> defaultHeaders = new Dictionary<string, string>();
103101
defaultHeaders.Add("Authorization", "Bearer " + apiKey);
104102
defaultHeaders.Add("Content-Type", "application/json");
105103
defaultHeaders.Add("User-Agent", "sendgrid/" + Version + " csharp");
@@ -161,9 +159,8 @@ private string BuildUrl(string queryParams = null)
161159

162160
if (queryParams != null)
163161
{
164-
JavaScriptSerializer jss = new JavaScriptSerializer();
165-
var ds_query_params = jss.Deserialize<Dictionary<string, dynamic>>(queryParams);
166-
var query = HttpUtility.ParseQueryString(string.Empty);
162+
var ds_query_params = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(queryParams);
163+
var query = new Uri(endpoint + "?" + string.Empty).ParseQueryString();
167164
foreach (var pair in ds_query_params)
168165
{
169166
query[pair.Key] = pair.Value.ToString();
@@ -243,7 +240,7 @@ public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMe
243240
/// </summary>
244241
/// <param name="method">HTTP verb</param>
245242
/// <param name="requestBody">JSON formatted string</param>
246-
/// <param name="queryParams">JSON formatted queary paramaters</param>
243+
/// <param name="queryParams">JSON formatted query paramaters</param>
247244
/// <returns>Response object</returns>
248245
public async Task<Response> RequestAsync(Client.Methods method,
249246
string requestBody = null,

TROUBLESHOOTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com).
1+
If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com).
22

33
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-csharp/issues).
44

@@ -59,9 +59,11 @@ If you are using ASP.NET Core, please [upvote this issue](https://github.com/sen
5959
To read the error message returned by SendGrid's API:
6060

6161
```csharp
62-
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
62+
Response response = await client.RequestAsync(method: Client.Methods.POST,
63+
requestBody: mail.Get(),
64+
urlPath: "mail/send");
6365
Console.WriteLine(response.StatusCode);
64-
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
66+
Console.WriteLine(response.Body.ReadAsStringAsync().Result); // The message will be here
6567
Console.WriteLine(response.Headers.ToString());
6668
```
6769

0 commit comments

Comments
 (0)