public string ExecuteQuery(
            string queryURL,
            HttpMethod httpMethod,
            TwitterClientHandler handler    = null,
            ITwitterCredentials credentials = null)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;

            ITwitterQuery twitterQuery;

            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery))
            {
                return(null);
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return(jsonResult);
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);

                throw;
            }
        }
        public string ExecuteQuery(
            string queryURL, 
            HttpMethod httpMethod, 
            TwitterClientHandler handler = null,
            ITwitterCredentials credentials = null)
        {
            CleanupQueryURL(ref queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption;
            
            ITwitterQuery twitterQuery;
            if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery))
            {
                return null;
            }

            try
            {
                var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler);

                QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption);

                return jsonResult;
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);
                
                throw;
            }
        }
        public async Task<HttpResponseMessage> GetHttpResponse(ITwitterQuery twitterQuery, HttpContent httpContent = null, TwitterClientHandler handler = null)
        {
            handler = handler ?? new TwitterClientHandler();
            handler.TwitterQuery = twitterQuery;

            using (var client = new HttpClient(handler))
            {
                client.Timeout = twitterQuery.Timeout;

                var httpMethod = new HttpMethod(twitterQuery.HttpMethod.ToString());

                if (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, httpContent);
                }
            }
        }
        public string ExecuteQuery(
            string queryURL,
            HttpMethod httpMethod,
            TwitterClientHandler handler    = null,
            ITwitterCredentials credentials = null,
            HttpContent httpContent         = null)
        {
            queryURL = CleanupQueryURL(queryURL);
            var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerMode;

            var requestParameters = new HttpRequestParameters
            {
                Query       = queryURL,
                HttpMethod  = httpMethod,
                HttpContent = httpContent
            };

            ITwitterQuery twitterQuery;

            if (!TryPrepareRequest(requestParameters, rateLimitTrackerOption, credentials, out twitterQuery))
            {
                return(null);
            }

            try
            {
                var webRequestResult = _webRequestExecutor.ExecuteQuery(twitterQuery, handler);

                QueryCompleted(twitterQuery, webRequestResult, rateLimitTrackerOption);

                return(webRequestResult.Response);
            }
            catch (TwitterException ex)
            {
                HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery);

                throw;
            }
        }
        // Simple Query
        public string ExecuteQuery(ITwitterQuery twitterQuery, TwitterClientHandler 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;
                }
            }));
        }
Example #6
0
 public string ExecuteQuery(ITwitterQuery twitterQuery, TwitterClientHandler handler = null)
 {
     return(_webRequestExecutor.ExecuteQuery(twitterQuery, handler));
 }
        public async Task <HttpResponseMessage> GetHttpResponse(ITwitterQuery twitterQuery, HttpContent httpContent = null, TwitterClientHandler handler = null)
        {
            handler = handler ?? new TwitterClientHandler();
            handler.TwitterQuery = twitterQuery;

            using (var client = new HttpClient(handler))
            {
                client.Timeout = twitterQuery.Timeout;

                var httpMethod = new HttpMethod(twitterQuery.HttpMethod.ToString());

                if (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, httpContent).ConfigureAwait(false));
                }
            }
        }
Example #8
0
 public string ExecuteQuery(ITwitterQuery twitterQuery, TwitterClientHandler handler = null)
 {
     return _webRequestExecutor.ExecuteQuery(twitterQuery, handler);
 }