Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial removal of dynamic with some Client refactoring #356

Merged
merged 6 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 27 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We appreciate your continued support, thank you!

## Prerequisites

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

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

## Dependencies

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

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

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
Execute().Wait();
}

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGridAPIClient(apiKey);
Client client = new Client(apiKey);

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

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

```csharp
using System;
using SendGrid;
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
using SendGrid;

namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
Execute().Wait();
}

static async Task Execute()
{
String apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGridAPIClient(apiKey);
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
Client client = new Client(apiKey);

string data = @"{
'personalizations': [
Expand All @@ -150,39 +154,15 @@ namespace Example
]
}";
Object json = JsonConvert.DeserializeObject<Object>(data);
dynamic response = await sg.client.mail.send.post(requestBody: json.ToString());
}
}
}
```

## General v3 Web API Usage (With Fluent Interface)

```csharp
using System;
using SendGrid;
using System.Threading.Tasks;

namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
Response response = await client.RequestAsync(method: Client.Methods.POST,
requestBody: json.ToString(),
urlPath: "mail/send");
}

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
dynamic response = await sg.client.suppression.bounces.get();
}
}
}
```

## General v3 Web API Usage (Without Fluent Interface)
## General v3 Web API Usage

```csharp
using System;
Expand All @@ -200,10 +180,12 @@ namespace Example

static async Task Execute()
{
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
dynamic sg = new SendGrid.SendGridAPIClient(apiKey);
dynamic response = await sg.client._("suppression/bounces").get();
}
string apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", EnvironmentVariableTarget.User);
Client client = new Client(apiKey);
Response response = await client.RequestAsync(method: Client.Methods.GET,
requestBody: json.ToString(),
urlPath: "suppression/bounces");
}
}
}
```
Expand Down
Loading