private async Task GetUrlsAsync() { var requestUri = BuildTrendingGifRequestUri(); try { var getURL = await new HttpClient().GetAsync(requestUri); var content = await getURL.Content.ReadAsStringAsync(); JObject json = JObject.Parse(content); int statusCode = GiphyUtils.GetStatusCodeFromJsonObject(json); if (statusCode != (int)EGiphyResponseStatusCodes.OK) { return; } lock (_lock) { _urlsList = GiphyUtils.GetUrlListFromJsonObject(json); //GiphyUtils.PrintList(_urlsList); } } catch (Exception ex) { Logger.Logger.Instance.WriteToLog($"Exception occured: {ex.Message}"); } }
private async Task GetUrlsAsync() { var requestUri = BuildSearchGifRequestUri(); var getURL = await new HttpClient().GetAsync(requestUri); var content = await getURL.Content.ReadAsStringAsync(); JObject json = JObject.Parse(content); lock (_lock) { _urlsList = GiphyUtils.GetUrlListFromJsonObject(json); //GiphyUtils.PrintList(_urlsList); } }
private void UpdateTrendingResponse(MyDbContext db) { mLastTrendingResponse = db.TrendingResponses .Where(x => x.CreatedTime.Date == DateTime.Today) .OrderByDescending(x => x.CreatedTime) .FirstOrDefault(); if (mLastTrendingResponse == null) { var onlineResponse = GiphyUtils.GetGiftsTrending().Result; mLastTrendingResponse = new TrendingResponse() { CreatedTime = DateTime.Now } .SetGiphyGiftsResponse(onlineResponse); db.TrendingResponses.Add(mLastTrendingResponse); db.SaveChanges(); } }
public GiphyGiftsResponse SearchGifts(MyDbContext db, string searchText) { SearchResponse response = null; response = db.SearchResponses .Where(x => x.CreatedTime.Date == DateTime.Today && x.SearchText.ToLower() == searchText.ToLower()) .OrderByDescending(x => x.CreatedTime) .FirstOrDefault(); if (response == null) { var onlineResponse = GiphyUtils.SearchGifts(searchText).Result; response = new SearchResponse() { CreatedTime = DateTime.Now, SearchText = searchText.ToLower(), } .SetGiphyGiftsResponse(onlineResponse); db.SearchResponses.Add(response); db.SaveChanges(); } return(response.GetGiphyGiftsResponse()); }
private string BuildSearchGifRequestUri() { var requestUri = $"{SearchRequest}?api_key={GiphyUtils.GetGiphyApiKey()}&q={_searchString}"; return(requestUri); }
private string BuildTrendingGifRequestUri() { var requestUri = $"{TrendingRequest}?api_key={GiphyUtils.GetGiphyApiKey()}"; return(requestUri); }