Skip to content

#405 reuse http client #417

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

Merged
merged 5 commits into from
Mar 20, 2017
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
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