// Simple Query public Task <ITwitterResponse> ExecuteQueryAsync(ITwitterRequest request, ITwitterClientHandler handler = null) { return(ExecuteTwitterQuerySafelyAsync(request, async() => { HttpResponseMessage httpResponseMessage = null; try { httpResponseMessage = await _httpClientWebHelper.GetHttpResponseAsync(request.Query, handler).ConfigureAwait(false); var result = CreateTwitterResponseFromHttpResponse(request.Query.Url, httpResponseMessage); if (!result.IsSuccessStatusCode) { throw _twitterExceptionFactory.Create(result, request); } var stream = result.ResultStream; if (stream != null) { result.Binary = StreamToBinary(stream); result.Content = Encoding.UTF8.GetString(result.Binary); } return result; } catch (Exception) { httpResponseMessage?.Dispose(); throw; } })); }
public HttpClient GetHttpClient(ITwitterQuery twitterQuery, ITwitterClientHandler twitterHandler = null) { var handler = (twitterHandler as TwitterClientHandler) ?? new TwitterClientHandler(); handler.TwitterQuery = twitterQuery; var client = new HttpClient(handler) { Timeout = twitterQuery.Timeout, }; return client; }
public HttpClient GetHttpClient(ITwitterQuery twitterQuery, ITwitterClientHandler twitterHandler = null) { var handler = (twitterHandler as TwitterClientHandler) ?? new TwitterClientHandler(); handler.TwitterQuery = twitterQuery; var client = new HttpClient(handler) { Timeout = twitterQuery.Timeout, }; return(client); }
public HttpClient GetHttpClient(ITwitterQuery twitterQuery, ITwitterClientHandler twitterHandler = null) { var oAuthWebRequestGenerator = _oAuthWebRequestGeneratorFactory.Create(); var handler = (twitterHandler as TwitterClientHandler) ?? new TwitterClientHandler(oAuthWebRequestGenerator); handler.TwitterQuery = twitterQuery; var client = new HttpClient(handler) { Timeout = twitterQuery.Timeout, }; return(client); }
// Simple Query public IWebRequestResult ExecuteQuery(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { return(ExecuteTwitterQuerySafely(twitterQuery, () => { HttpResponseMessage httpResponseMessage = null; try { httpResponseMessage = _httpClientWebHelper.GetHttpResponse(twitterQuery, handler).Result; var result = GetWebResultFromResponse(twitterQuery.QueryURL, httpResponseMessage); if (!result.IsSuccessStatusCode) { throw _exceptionHandler.TryLogFailedWebRequestResult(result, twitterQuery); } var stream = result.ResultStream; if (stream != null) { result.Binary = StreamToBinary(stream); result.Text = Encoding.UTF8.GetString(result.Binary); } return result; } catch (Exception) { if (httpResponseMessage != null) { httpResponseMessage.Dispose(); } throw; } })); }
// Simple Query public string ExecuteQuery(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { return(ExecuteTwitterQuerySafely(twitterQuery, () => { HttpResponseMessage httpResponseMessage = null; try { httpResponseMessage = _httpClientWebHelper.GetHttpResponse(twitterQuery, null, handler).Result; var result = GetWebResultFromResponse(twitterQuery.QueryURL, httpResponseMessage); if (!result.IsSuccessStatusCode) { throw _exceptionHandler.TryLogFailedWebRequestResult(result); } var stream = result.ResultStream; if (stream != null) { var responseReader = new StreamReader(stream); return responseReader.ReadLine(); } return null; } catch (Exception) { if (httpResponseMessage != null) { httpResponseMessage.Dispose(); } throw; } })); }
public async Task<HttpResponseMessage> GetHttpResponse(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { using (var client = GetHttpClient(twitterQuery, handler)) { client.Timeout = twitterQuery.Timeout; var httpMethod = new HttpMethod(twitterQuery.HttpMethod.ToString()); if (twitterQuery.HttpContent == null) { return await client.SendAsync(new HttpRequestMessage(httpMethod, twitterQuery.QueryURL)).ConfigureAwait(false); } else { if (httpMethod != HttpMethod.Post) { throw new ArgumentException("Cannot send HttpContent in a WebRequest that is not POST."); } return await client.PostAsync(twitterQuery.QueryURL, twitterQuery.HttpContent).ConfigureAwait(false); } } }
public string ExecuteQuery(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { return(_webRequestExecutor.ExecuteQuery(twitterQuery, handler)); }
public string ExecuteQuery(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { return _webRequestExecutor.ExecuteQuery(twitterQuery, handler); }
public async Task <HttpResponseMessage> GetHttpResponse(ITwitterQuery twitterQuery, ITwitterClientHandler handler = null) { using (var client = GetHttpClient(twitterQuery, handler)) { client.Timeout = twitterQuery.Timeout; var httpMethod = new HttpMethod(twitterQuery.HttpMethod.ToString()); if (twitterQuery.HttpContent == null) { return(await client.SendAsync(new HttpRequestMessage(httpMethod, twitterQuery.Url)).ConfigureAwait(false)); } else { if (httpMethod != HttpMethod.Post) { throw new ArgumentException("Cannot send HttpContent in a WebRequest that is not POST."); } return(await client.PostAsync(twitterQuery.Url, twitterQuery.HttpContent).ConfigureAwait(false)); } } }