Skip to content

Commit

Permalink
Merge pull request #417 from jonnybee/#405_Reuse_HttpClient
Browse files Browse the repository at this point in the history
#405 reuse http client
  • Loading branch information
thinkingserious committed Mar 20, 2017
2 parents 6e715fd + 698740c commit 7ea44d6
Show file tree
Hide file tree
Showing 6 changed files with 1,782 additions and 2,273 deletions.
83 changes: 44 additions & 39 deletions ExampleCoreProject/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object
Expand All @@ -48,7 +48,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email using the Mail Helper, entirely with convenience methods
Expand All @@ -63,7 +63,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email Without the Mail Helper
Expand Down Expand Up @@ -94,7 +94,7 @@ static async Task Execute()
urlPath: "mail/send");
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// GET Collection
Expand All @@ -107,7 +107,7 @@ static async Task Execute()
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to POST.");
Console.WriteLine("\n\nPress <Enter> to continue to POST.");
Console.ReadLine();

// POST
Expand All @@ -121,45 +121,50 @@ static async Task Execute()
urlPath: "asm/groups",
requestBody: json.ToString());
var ds_response = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
string group_id = ds_response["id"].ToString();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to GET single.");
Console.WriteLine("\n\nPress <Enter> to continue to GET single.");
Console.ReadLine();

// GET Single
response = await client.RequestAsync(method: SendGridClient.Method.GET,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to PATCH.");
Console.ReadLine();

// PATCH
requestBody = @"{
'name': 'Cool Magic Products'
}";
json = JsonConvert.DeserializeObject<object>(requestBody);

response = await client.RequestAsync(method: SendGridClient.Method.PATCH,
urlPath: string.Format("asm/groups/{0}", group_id),
requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Console.WriteLine("\n\nPress any key to continue to PUT.");
Console.ReadLine();

// DELETE
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers.ToString());
Console.WriteLine("\n\nPress any key to DELETE and exit.");
Console.ReadLine();
if (ds_response != null && ds_response.ContainsKey("id"))
{
string group_id = ds_response["id"].ToString();


// GET Single
response = await client.RequestAsync(method: SendGridClient.Method.GET,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress <Enter> to continue to PATCH.");
Console.ReadLine();

// PATCH
requestBody = @"{
'name': 'Cool Magic Products'
}";
json = JsonConvert.DeserializeObject<object>(requestBody);

response = await client.RequestAsync(method: SendGridClient.Method.PATCH,
urlPath: string.Format("asm/groups/{0}", group_id),
requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Console.WriteLine("\n\nPress <Enter> to continue to PUT.");
Console.ReadLine();

// DELETE
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers.ToString());
Console.WriteLine("\n\nPress <Enter> to DELETE and exit.");
Console.ReadLine();
}
}
}
}
83 changes: 44 additions & 39 deletions ExampleNet45Project/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object
Expand All @@ -48,7 +48,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email using the Mail Helper, entirely with convenience methods
Expand All @@ -63,7 +63,7 @@ static async Task Execute()
Console.WriteLine(msg.Serialize());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// Send a Single Email Without the Mail Helper
Expand Down Expand Up @@ -94,7 +94,7 @@ static async Task Execute()
urlPath: "mail/send");
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue.");
Console.WriteLine("\n\nPress <Enter> to continue.");
Console.ReadLine();

// GET Collection
Expand All @@ -107,7 +107,7 @@ static async Task Execute()
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to POST.");
Console.WriteLine("\n\nPress <Enter> to continue to POST.");
Console.ReadLine();

// POST
Expand All @@ -121,45 +121,50 @@ static async Task Execute()
urlPath: "asm/groups",
requestBody: json.ToString());
var ds_response = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response.Body.ReadAsStringAsync().Result);
string group_id = ds_response["id"].ToString();
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to GET single.");
Console.WriteLine("\n\nPress <Enter> to continue to GET single.");
Console.ReadLine();

// GET Single
response = await client.RequestAsync(method: SendGridClient.Method.GET,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress any key to continue to PATCH.");
Console.ReadLine();

// PATCH
requestBody = @"{
'name': 'Cool Magic Products'
}";
json = JsonConvert.DeserializeObject<object>(requestBody);

response = await client.RequestAsync(method: SendGridClient.Method.PATCH,
urlPath: string.Format("asm/groups/{0}", group_id),
requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Console.WriteLine("\n\nPress any key to continue to PUT.");
Console.ReadLine();

// DELETE
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers.ToString());
Console.WriteLine("\n\nPress any key to DELETE and exit.");
Console.ReadLine();
if (ds_response != null && ds_response.ContainsKey("id"))
{
string group_id = ds_response["id"].ToString();

// GET Single
response = await client.RequestAsync(method: SendGridClient.Method.GET,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers);
Console.WriteLine("\n\nPress <Enter> to continue to PATCH.");
Console.ReadLine();


// PATCH
requestBody = @"{
'name': 'Cool Magic Products'
}";
json = JsonConvert.DeserializeObject<object>(requestBody);

response = await client.RequestAsync(method: SendGridClient.Method.PATCH,
urlPath: string.Format("asm/groups/{0}", group_id),
requestBody: json.ToString());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Console.WriteLine("\n\nPress <Enter> to continue to PUT.");
Console.ReadLine();

// DELETE
response = await client.RequestAsync(method: SendGridClient.Method.DELETE,
urlPath: string.Format("asm/groups/{0}", group_id));
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Headers.ToString());
Console.WriteLine("\n\nPress <Enter> to DELETE and exit.");
Console.ReadLine();
}
}
}
}
4 changes: 2 additions & 2 deletions SendGrid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.Build.0 = Release|Any CPU
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{377C20E4-2297-488F-933B-FB635C56D8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{377C20E4-2297-488F-933B-FB635C56D8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{377C20E4-2297-488F-933B-FB635C56D8FC}.Release|Any CPU.Build.0 = Release|Any CPU
{D89ADAEA-2BE8-49AC-B5BC-6EABBB2AE4E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
Loading

0 comments on commit 7ea44d6

Please sign in to comment.