public async Task Trending_NotSuccessStatusCode_ThrowsHttpRequestException() { var mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject(); var giphy = new Giphy(mockHttpHandler); var search = new TrendingParameter(); _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.Trending(search)); }
public async Task Trending_ParameterIsNull_ThrowsNullReferenceException() { var giphy = new Giphy("test"); TrendingParameter search = null; _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.Trending(search)); }
public void Limit_DefaultValue_Is25() { var searchParamter = new TrendingParameter(); var expected = 25; var actual = searchParamter.Limit; Assert.IsType <int>(actual); Assert.Equal(expected, actual); }
public void Rating_DefaultValue_IsG() { var searchParamter = new TrendingParameter(); var expected = Rating.G; var actual = searchParamter.Rating; Assert.IsType <Rating>(actual); Assert.Equal(expected, actual); }
public void Offset_DefaultValue_Is0() { var searchParamter = new TrendingParameter(); var expected = 0; var actual = searchParamter.Offset; Assert.IsType <int>(actual); Assert.Equal(expected, actual); }
static void Main(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\appsettings.json")), true, true) .Build(); var apikey = configuration.GetSection("giphyapikey").Value; bool stayInSearch = true; var giphy = new Giphy(apikey, new MemoryCache(new MemoryCacheOptions())); while (stayInSearch) { Console.WriteLine("Please enter a word or words you want to search for gifs for: "); var searchQuery = Console.ReadLine(); if (string.IsNullOrEmpty(searchQuery)) { continue; } // Returns gif results var gifs = giphy.GetOrCreateSearchResults(searchQuery); Console.WriteLine($"Following the search results for '{searchQuery}':\n\n"); gifs.Wait(); foreach (var url in gifs.Result) { Console.WriteLine(url); } ConsoleKey response; do { Console.Write("\n\nAre you want to keep searching for gifs ? [y/n]"); response = Console.ReadKey(false).Key; if (response != ConsoleKey.Enter) { Console.WriteLine(); } } while (response != ConsoleKey.Y && response != ConsoleKey.N); stayInSearch = response == ConsoleKey.Y; } Console.WriteLine("\n\nPlease enter any key to get trending gifs\n\n"); Console.ReadKey(); Console.WriteLine($"Following the search results for trending gifs:\n\n"); var trendingParameter = new TrendingParameter(); var t2 = giphy.TrendingGifs(trendingParameter); t2.Wait(); foreach (Data item in t2.Result.Data) { Console.WriteLine(item.EmbedUrl); } Console.ReadKey(); }
public async Task Trending_WhenCalled_ReturnsRootObject() { var mockHttpHandler = HttpHandler.GetMockSuccessHttpHandlerObject(); var giphy = new Giphy(mockHttpHandler); var search = new TrendingParameter(); var actual = await giphy.Trending(search); Assert.NotNull(actual); Assert.IsType <RootObject>(actual); }
private void TimerElapsed(object sender, ElapsedEventArgs e) { var trending = new TrendingParameter() { Limit = 1 }; m_giphy.TrendingGifs(trending).ContinueWith(task => { var results = task.Result.Data; Send(results[0].Images.Original.Url); }); }
/// <summary> /// Returns a list of the top trending GIFs on the internet, consistently updated throughout each day. /// </summary> /// <param name="parameter">Specifies search parameters</param> /// <returns>Root object</returns> public async Task <RootObject> Trending(TrendingParameter parameter) { if (parameter is null) { throw new NullReferenceException("Paramter cannot be null"); } /* Finish exception checks */ string url = $@"{ _trendingUrl }?api_key={ _apiKey }&limit={ parameter.Limit }&offset={ parameter.Offset }&rating={ parameter.Rating.ToString() }"; var response = await _httpHandler.GetAsync(url); if (!response.IsSuccessStatusCode) { throw new HttpRequestException(response.ReasonPhrase); } return(await response.Content.ReadAsAsync <RootObject>()); }
public async Task <GiphySearchResult> TrendingStickers(TrendingParameter trendingParameter) { var nvc = new NameValueCollection(); nvc.Add("api_key", _authKey); nvc.Add("limit", trendingParameter.Limit.ToString()); if (trendingParameter.Rating != Rating.None) { nvc.Add("rating", trendingParameter.Rating.ToFriendlyString()); } if (!string.IsNullOrEmpty(trendingParameter.Format)) { nvc.Add("fmt", trendingParameter.Format); } var result = await _webManager.GetData(new Uri($"{BaseUrl}{BaseSticker}/trending{UriExtensions.ToQueryString(nvc)}")); if (!result.IsSuccess) { throw new WebException($"Failed to get Sticker: {result.ResultJson}"); } return(JsonConvert.DeserializeObject <GiphySearchResult>(result.ResultJson)); }