Last active
December 30, 2015 11:09
-
-
Save neuecc/7821107 to your computer and use it in GitHub Desktop.
某クライアント
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChatWorkAuthenticationHandler : DelegatingHandler | |
{ | |
readonly string apiToken; | |
public ChatWorkAuthenticationHandler(string apiToken) | |
: this(apiToken, new System.Net.Http.HttpClientHandler()) | |
{ | |
} | |
public ChatWorkAuthenticationHandler(string apiToken, HttpMessageHandler innerHandler) | |
: base(innerHandler) | |
{ | |
this.apiToken = apiToken; | |
} | |
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) | |
{ | |
request.Headers.Add("X-ChatWorkToken", apiToken); | |
return base.SendAsync(request, cancellationToken); | |
} | |
} | |
public class ChatWorkClient | |
{ | |
readonly HttpClient httpClient; | |
public long MaxResponseContentBufferSize | |
{ | |
get | |
{ | |
return httpClient.MaxResponseContentBufferSize; | |
} | |
set | |
{ | |
httpClient.MaxResponseContentBufferSize = value; | |
} | |
} | |
public TimeSpan Timeout | |
{ | |
get | |
{ | |
return httpClient.Timeout; | |
} | |
set | |
{ | |
httpClient.Timeout = value; | |
} | |
} | |
public ChatWorkClient(string apiToken) | |
{ | |
this.httpClient = new HttpClient(new ChatWorkAuthenticationHandler(apiToken)); | |
} | |
public ChatWorkClient(string apiToken, HttpMessageHandler innerHandler) | |
{ | |
this.httpClient = new HttpClient(new ChatWorkAuthenticationHandler(apiToken, innerHandler)); | |
} | |
// 以下略 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment