Skip to content

Instantly share code, notes, and snippets.

@neuecc
Last active December 30, 2015 11:09
Show Gist options
  • Save neuecc/7821107 to your computer and use it in GitHub Desktop.
Save neuecc/7821107 to your computer and use it in GitHub Desktop.
某クライアント
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