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}");
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
 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();
     }
 }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }