예제 #1
0
        public async Task <GifResult> GifFetch(string searchTerm)
        {
            _logger.LogInformation($"GifFetch search for {searchTerm} at {DateTime.UtcNow.ToLongTimeString()}");
            if (string.IsNullOrEmpty(searchTerm))
            {
                throw new FormatException("query term is required");
            }
            SearchParameters searchParameters = new SearchParameters();

            searchParameters.ApiKey = _apiKey;
            searchParameters.Query  = searchTerm;

            var searchString = WebTools.ToKeyValueURL(searchParameters);

            var result = await _webTools.GetData(new Uri($"{_giphyUrl}{searchString}"));

            if (!result.IsSuccess)
            {
                string message = $"GifFetch Failed to get GIFs: {result.Result}";
                _logger.LogError(message);
                throw new WebException(message);
            }

            GifResult gifResult = JsonConvert.DeserializeObject <GifResult>(result.Result);

            return(gifResult);
        }
예제 #2
0
        public async Task <GifResult> GifFetch(string searchTerm)
        {
            if (string.IsNullOrEmpty(searchTerm))
            {
                throw new FormatException("query term is required");
            }
            SearchParameters searchParameters = new SearchParameters();

            searchParameters.ApiKey = _apiKey;
            searchParameters.Query  = searchTerm;

            var searchString = WebTools.ToKeyValueURL(searchParameters);

            var result = await _webTools.GetData(new Uri($"{_giphyUrl}{searchString}"));

            if (!result.IsSuccess)
            {
                throw new WebException($"Failed to get GIFs: {result.Result}");
            }

            GifResult gifResult = JsonConvert.DeserializeObject <GifResult>(result.Result);

            return(gifResult);
        }