Skip to content

Commit 47bfdf0

Browse files
committed
Merged current master
2 parents 72adcda + d86103a commit 47bfdf0

File tree

8 files changed

+72
-20
lines changed

8 files changed

+72
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ CSharpHTTPClient/CSharpHTTPClient.userprefs
1313
CSharpHTTPClient/packages/
1414
CSharpHTTPClient/CSharpHTTPClient.sln.VisualState.xml
1515
*.PublicKey
16-
*.pfx
16+
*.pfx

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [3.2.0] - 2017-04-11
7+
### Added
8+
- #23: Timeout Parameter
9+
- Big thanks to [PandaBoy00](https://github.com/PandaBoy00) for the pull request!
10+
11+
## [3.1.0] - 2017-03-01
12+
### Added
13+
- [PR #18](https://github.com/sendgrid/csharp-http-client/pull/18): Cache default httpclient
14+
- Big thanks to [Niels Timmermans](https://github.com/nillis) for the pull request!
15+
616
## [3.0.0] - 2016-07-22
717
### BREAKING CHANGE
818
- While your code may continue to work as before, the async behavior has changed, as we don't block on .Result anymore
@@ -41,3 +51,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4151
## [1.0.2] - 2016-03-17
4252
### Added
4353
- We are live!
54+

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ We use [Milestones](https://github.com/sendgrid/csharp-http-client/milestones) t
1616
<a name="cla"></a>
1717
## CLAs and CCLAs
1818

19-
Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) or a SendGrid Company Contributor Licensing Agreement (CCLA) be filled out by every contributor to a SendGrid open source project.
19+
Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) be filled out by every contributor to a SendGrid open source project.
2020

21-
Our goal with the CLA and CCLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA and CCLA encourage broad participation by our open source community and help us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
21+
Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution.
2222

23-
SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA (or CCLA). Copies of the CLA and CCLA are available [here](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view).
23+
SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla).
2424

25-
You may submit your completed [CLA or CCLA](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view) to SendGrid at [dx@sendgrid.com](mailto:dx@sendgrid.com). SendGrid will then confirm you are ready to begin making contributions.
25+
When you create a Pull Request, after a few seconds, a comment will appear with a link to the CLA. Click the link and fill out the brief form and then click the "I agree" button and you are all set. You will not be asked to re-sign the CLA unless we make a change.
2626

2727
There are a few ways to contribute, which we'll enumerate below:
2828

@@ -163,4 +163,4 @@ Generally, we follow the style guidelines as suggested by the official language.
163163
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
164164
with a clear title and description against the `master` branch. All tests must be passing before we will review the PR.
165165

166-
If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.
166+
If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo.

CSharpHTTPClient/Client.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace SendGrid.CSharp.HTTP.Client
1515
{
1616
public class Response
17-
{
17+
{
1818
public HttpStatusCode StatusCode;
1919
public HttpContent Body;
2020
public HttpResponseHeaders Headers;
@@ -64,17 +64,21 @@ public virtual Dictionary<string, string> DeserializeResponseHeaders(HttpRespons
6464

6565
public class Client : DynamicObject
6666
{
67+
private static HttpClient _httpClient = new HttpClient();
6768
public string Host;
6869
public Dictionary <string,string> RequestHeaders;
6970
public string Version;
7071
public string UrlPath;
7172
public string MediaType;
7273
public WebProxy WebProxy;
74+
public TimeSpan Timeout;
75+
7376
public enum Methods
7477
{
7578
DELETE, GET, PATCH, POST, PUT
7679
}
7780

81+
private int TimeoutDefault = 10;
7882

7983
/// <summary>
8084
/// REST API client.
@@ -90,15 +94,17 @@ public Client(WebProxy webProxy, string host, Dictionary<string, string> request
9094
WebProxy = webProxy;
9195
}
9296

97+
9398
/// <summary>
9499
/// REST API client.
95100
/// </summary>
96101
/// <param name="host">Base url (e.g. https://api.sendgrid.com)</param>
97102
/// <param name="requestHeaders">A dictionary of request headers</param>
98103
/// <param name="version">API version, override AddVersion to customize</param>
99104
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
105+
/// <param name="timeOut">Set an Timeout parameter for the HTTP Client</param>
100106
/// <returns>Fluent interface to a REST API</returns>
101-
public Client(string host, Dictionary<string,string> requestHeaders = null, string version = null, string urlPath = null)
107+
public Client(string host, Dictionary<string,string> requestHeaders = null, string version = null, string urlPath = null, TimeSpan? timeOut = null)
102108
{
103109
Host = host;
104110
if(requestHeaders != null)
@@ -107,6 +113,7 @@ public Client(string host, Dictionary<string,string> requestHeaders = null, stri
107113
}
108114
Version = (version != null) ? version : null;
109115
UrlPath = (urlPath != null) ? urlPath : null;
116+
Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(TimeoutDefault);
110117
}
111118

112119
/// <summary>
@@ -172,11 +179,10 @@ private Client BuildClient(string name = null)
172179
}
173180

174181
UrlPath = null; // Reset the current object's state before we return a new one
175-
return new Client(Host, RequestHeaders, Version, endpoint);
182+
return new Client(Host, RequestHeaders, Version, endpoint, Timeout);
176183

177184
}
178185

179-
/// <summary>
180186
/// Factory method to return the right HttpClient settings.
181187
/// </summary>
182188
/// <returns>Instance of HttpClient</returns>
@@ -195,9 +201,11 @@ private HttpClient BuildHttpClient()
195201
return new HttpClient(httpClientHandler);
196202
}
197203

198-
return new HttpClient();
204+
return _httpClient;
199205
}
200206

207+
/// <summary>
208+
201209
/// <summary>
202210
/// Add the authorization header, override to customize
203211
/// </summary>
@@ -306,7 +314,8 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
306314
/// <returns>Response object</returns>
307315
public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMessage request, CancellationToken cancellationToken)
308316
{
309-
HttpResponseMessage response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
317+
318+
HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
310319
return new Response(response.StatusCode, response.Content, response.Headers);
311320
}
312321

@@ -318,16 +327,18 @@ public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMe
318327
/// <param name="requestBody">JSON formatted string</param>
319328
/// <param name="queryParams">JSON formatted queary paramaters</param>
320329
/// <returns>Response object</returns>
321-
private async Task<Response> RequestAsync(string method, CancellationToken cancellationToken, string requestBody = null, string queryParams = null)
330+
private async Task<Response> RequestAsync(string method, String requestBody = null, String queryParams = null, CancellationToken cancellationToken = null)
322331
{
323-
using (var client = BuildHttpClient())
332+
using (var client = new HttpClient())
324333
{
325334
try
326335
{
327336
// Build the URL
328337
client.BaseAddress = new Uri(Host);
338+
client.Timeout = Timeout;
329339
string endpoint = BuildUrl(queryParams);
330340

341+
331342
// Build the request headers
332343
client.DefaultRequestHeaders.Accept.Clear();
333344
if(RequestHeaders != null)
@@ -383,4 +394,4 @@ private async Task<Response> RequestAsync(string method, CancellationToken cance
383394
}
384395
}
385396
}
386-
}
397+
}

CSharpHTTPClient/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("SendGrid")]
1111
[assembly: AssemblyProduct("SendGrid.CSharp.HTTP.Client")]
12-
[assembly: AssemblyCopyright("Copyright © 2016")]
12+
[assembly: AssemblyCopyright("Copyright © 2017")]
1313
[assembly: AssemblyTrademark("SendGrid")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("3.0.0")]
35-
[assembly: AssemblyFileVersion("3.0.0")]
34+
[assembly: AssemblyVersion("3.2.0")]
35+
[assembly: AssemblyFileVersion("3.2.0")]

LICENSE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22+

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ csharp-http-client is guided and supported by the SendGrid [Developer Experience
9494

9595
csharp-http-client is maintained and funded by SendGrid, Inc. The names and logos for csharp-http-client are trademarks of SendGrid, Inc.
9696

97-
![SendGrid Logo]
98-
(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
97+
![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
98+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
3+
<metadata>
4+
<id>SendGrid.CSharp.HTTP.Client</id>
5+
<version>3.2.0</version>
6+
<title>Fluent REST API Client</title>
7+
<authors>Elmer Thomas,SendGrid DX Team</authors>
8+
<licenseUrl>https://github.com/sendgrid/csharp-http-client/blob/master/LICENSE</licenseUrl>
9+
<projectUrl>https://github.com/sendgrid/csharp-http-client</projectUrl>
10+
<iconUrl>https://sendgrid.com/wp-content/themes/sgdotcom/pages/brand/2016/SendGrid-Logomark.png</iconUrl>
11+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12+
<description>Quickly and easily access any REST or REST-like API using a fluent interface via method chaining and reflection.</description>
13+
<summary>Quickly and easily access any REST or REST-like API.</summary>
14+
<releaseNotes>### Added
15+
- #23: Timeout Parameter
16+
- Big thanks to [PandaBoy00](https://github.com/PandaBoy00) for the pull request!</releaseNotes>
17+
<copyright>Copyright 2017</copyright>
18+
<language>en-US</language>
19+
<tags>SendGrid Email API REST Fluent</tags>
20+
<frameworkAssemblies>
21+
<frameworkAssembly assemblyName="System.Web.Extensions" targetFramework="" />
22+
</frameworkAssemblies>
23+
</metadata>
24+
<files>
25+
<file src="..\CSharpHTTPClient\bin\Release\SendGrid.CSharp.HTTP.Client.dll" target="lib\SendGrid.CSharp.HTTP.Client.dll" />
26+
<file src="..\CSharpHTTPClient\bin\Release\SendGrid.CSharp.HTTP.Client.dll.config" target="lib\SendGrid.CSharp.HTTP.Client.dll.config" />
27+
<file src="..\CSharpHTTPClient\bin\Release\SendGrid.CSharp.HTTP.Client.pdb" target="lib\SendGrid.CSharp.HTTP.Client.pdb" />
28+
</files>
29+
</package>

0 commit comments

Comments
 (0)