diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-16 19:41:55 -0800 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-16 19:41:55 -0800 |
commit | f7610d321d601d5a6b7dabe8af0cfa30bad39fe5 (patch) | |
tree | 87ebccec8cce7d677f4d2c4e272e64bc32702479 /SendGrid/Example/Program.cs | |
parent | e93e813e701498841e687ed9eb354b37dc7da7eb (diff) | |
download | sendgrid-csharp-f7610d321d601d5a6b7dabe8af0cfa30bad39fe5.zip sendgrid-csharp-f7610d321d601d5a6b7dabe8af0cfa30bad39fe5.tar.gz sendgrid-csharp-f7610d321d601d5a6b7dabe8af0cfa30bad39fe5.tar.bz2 |
Re-factoring based on @deckarep's feedback
- Favor using var instead of string declarations for type inference.
- Use a better type other than object
Diffstat (limited to 'SendGrid/Example/Program.cs')
-rw-r--r-- | SendGrid/Example/Program.cs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs index 6953c27..c0f4295 100644 --- a/SendGrid/Example/Program.cs +++ b/SendGrid/Example/Program.cs @@ -12,9 +12,9 @@ namespace Example private static void Main()
{
// Test sending email
- string to = "example@example.com";
- string from = "example@example.com";
- string fromName = "Jane Doe";
+ var to = "example@example.com";
+ var from = "example@example.com";
+ var fromName = "Jane Doe";
SendEmail(to, from, fromName);
// Test viewing, creating, modifying and deleting API keys through our v3 Web API
ApiKeys();
@@ -23,8 +23,8 @@ namespace Example private static void SendAsync(SendGrid.SendGridMessage message)
{
// Create credentials, specifying your user Name and password.
- string username = Environment.GetEnvironmentVariable("SENDGRID_USERNAME");
- string password = Environment.GetEnvironmentVariable("SENDGRID_PASSWORD");
+ var username = Environment.GetEnvironmentVariable("SENDGRID_USERNAME");
+ var password = Environment.GetEnvironmentVariable("SENDGRID_PASSWORD");
//string apikey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
var credentials = new NetworkCredential(username, password);
@@ -68,7 +68,6 @@ namespace Example {
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
var client = new SendGrid.Client(apiKey);
- string _api_key_id;
// GET API KEYS
HttpResponseMessage responseGet = client.ApiKeys.Get();
@@ -79,16 +78,16 @@ namespace Example // POST API KEYS
HttpResponseMessage responsePost = client.ApiKeys.Post("CSharpTestKey");
- string rawString = responsePost.Content.ReadAsStringAsync().Result;
+ var rawString = responsePost.Content.ReadAsStringAsync().Result;
dynamic jsonObject = JObject.Parse(rawString);
- _api_key_id = jsonObject.api_key_id.ToString();
+ var apiKeyId = jsonObject.api_key_id.ToString();
Console.WriteLine(responsePost.StatusCode);
Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result);
Console.WriteLine("API Key created. Press any key to continue.");
Console.ReadKey();
// PATCH API KEYS
- HttpResponseMessage responsePatch = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched");
+ HttpResponseMessage responsePatch = client.ApiKeys.Patch(apiKeyId, "CSharpTestKeyPatched");
Console.WriteLine(responsePatch.StatusCode);
Console.WriteLine(responsePatch.Content.ReadAsStringAsync().Result);
Console.WriteLine("API Key patched. Press any key to continue.");
@@ -96,7 +95,7 @@ namespace Example // DELETE API KEYS
Console.WriteLine("Deleting API Key, please wait.");
- client.ApiKeys.Delete(_api_key_id);
+ client.ApiKeys.Delete(apiKeyId);
HttpResponseMessage responseFinal = client.ApiKeys.Get();
Console.WriteLine(responseFinal.StatusCode);
Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
|