public IEnumerable <T> Execute <T>(StackExchangeResourceEnum stackExchangeResourceEnum, List <object> parameters, Dictionary <string, object> data)
        {
            var resource = _stackExchangeResourceFactory.FetchResource(stackExchangeResourceEnum, parameters);
            var client   = _restSharpWrapper.CreateRestClient(_url);
            var request  = _restSharpWrapper.CreateRestRequest(resource);
            var filter   = _stackExchangeFilterCreator.CreateFilter();

            request.AddParameter("filter", filter);
            request.AddParameter("key", _key);
            request.AddParameter("site", _site);

            if (data != null && data.Keys.Any())
            {
                foreach (var dataItem in data)
                {
                    request.AddParameter(dataItem.Key, dataItem.Value);
                }
            }

            var response = client.Execute <ItemResponseDto <T> >(request);

            if (response?.Data == null || response.Data.QuotaRemaining == 0)
            {
                return(null);
            }

            return(response.Data.Items);
        }
示例#2
0
        public string CreateFilter()
        {
            var resource = _stackExchangeResourceFactory.FetchResource(StackExchangeResourceEnum.CreateFilter);
            var request  = _restSharpWrapper.CreateRestRequest(resource);

            request.AddParameter("include", "question.accepted_answer_id;question.body;answer.body");
            request.AddParameter("key", _key);

            var client   = _restSharpWrapper.CreateRestClient(_url);
            var response = client.Execute <ItemResponseDto <FilterDto> >(request);

            if (response?.Data == null || response.Data.QuotaRemaining == 0)
            {
                return(null);
            }

            return(response.Data.Items?.FirstOrDefault()?.Filter);
        }