summaryrefslogtreecommitdiffstats
path: root/SendGrid/Example
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2015-11-11 11:05:46 -0800
committerElmer Thomas <elmer@thinkingserious.com>2015-11-11 11:05:46 -0800
commit85291331846705096b35e75fc4d73491e4fecaaf (patch)
tree90765f78fbf97afdbf488dd2eaa2b6857b70e4fe /SendGrid/Example
parent34ef7589b45086844d6235bae73fe82c632a5dfd (diff)
downloadsendgrid-csharp-85291331846705096b35e75fc4d73491e4fecaaf.zip
sendgrid-csharp-85291331846705096b35e75fc4d73491e4fecaaf.tar.gz
sendgrid-csharp-85291331846705096b35e75fc4d73491e4fecaaf.tar.bz2
Added Integration/Unit Tests for API Keys endpoint
Diffstat (limited to 'SendGrid/Example')
-rw-r--r--SendGrid/Example/Example.csproj5
-rw-r--r--SendGrid/Example/Program.cs47
-rw-r--r--SendGrid/Example/packages.config1
3 files changed, 32 insertions, 21 deletions
diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj
index 60bede7..786d6fb 100644
--- a/SendGrid/Example/Example.csproj
+++ b/SendGrid/Example/Example.csproj
@@ -45,6 +45,11 @@
</DefineConstants>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
<Reference Include="SendGrid.SmtpApi, Version=1.3.1.0, Culture=neutral, PublicKeyToken=2ae73662c35d80e4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SendGrid.SmtpApi.1.3.1\lib\net40\SendGrid.SmtpApi.dll</HintPath>
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs
index 3e222a1..57e59a0 100644
--- a/SendGrid/Example/Program.cs
+++ b/SendGrid/Example/Program.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Mail;
+using Newtonsoft.Json.Linq;
using SendGrid.Resources;
namespace Example
@@ -14,36 +15,40 @@ namespace Example
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
var client = new SendGrid.Client(apiKey);
+ string _api_key_id;
// GET
- HttpResponseMessage response = client.ApiKeys.Get();
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ HttpResponseMessage responseGet = client.ApiKeys.Get();
+ Console.WriteLine(responseGet.StatusCode);
+ Console.WriteLine(responseGet.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("These are your current API Keys. Press any key to continue.");
Console.ReadKey();
-
+
// POST
- /*
- HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey5");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ HttpResponseMessage responsePost = client.ApiKeys.Post("CSharpTestKey");
+ string rawString = responsePost.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ _api_key_id = 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();
- */
- // DELETE
- /*
- HttpResponseMessage response = client.ApiKeys.Delete("<api_key_id>");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ // PATCH
+ HttpResponseMessage responsePatch = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched");
+ Console.WriteLine(responsePatch.StatusCode);
+ Console.WriteLine(responsePatch.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("API Key patched. Press any key to continue.");
Console.ReadKey();
- */
- // PATCH
- /*
- HttpResponseMessage response = client.ApiKeys.Patch("<api_key_id>", "CSharpTestKey7");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ // DELETE
+ Console.WriteLine("Deleting API Key, please wait.");
+ client.ApiKeys.Delete(_api_key_id);
+ HttpResponseMessage responseFinal = client.ApiKeys.Get();
+ Console.WriteLine(responseFinal.StatusCode);
+ Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("API Key Deleted, press any key to end");
Console.ReadKey();
- */
// SEND EMAIL
/*
diff --git a/SendGrid/Example/packages.config b/SendGrid/Example/packages.config
index 030933b..8aa9f7b 100644
--- a/SendGrid/Example/packages.config
+++ b/SendGrid/Example/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="SendGrid.SmtpApi" version="1.3.1" targetFramework="net45" />
</packages> \ No newline at end of file