public static TvShow GetResponse(string imdbId) { if (AppCache.Contains(imdbId)) { return(AppCache.Get <TvShow>(imdbId)); } var url = $"{ImdbApi}?idIMDB={imdbId}&token={ApiKey}&format=json&language=en-gb&seasons=1"; var request = WebRequest.Create(url) as HttpWebRequest; using (var response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { throw new Exception($"Server error (HTTP {response.StatusCode}: {response.StatusDescription})."); } var jsonSerializer = new DataContractJsonSerializer(typeof(ImdbResponse)); var imdbResponse = (ImdbResponse)jsonSerializer.ReadObject(response.GetResponseStream()); var show = imdbResponse.Data.Shows.FirstOrDefault(); if (show != null) { AppCache.Add(imdbId, show, DateTime.Now.AddHours(12)); } return(show); } }
public static IEnumerable <TvShow> GetShows() { if (AppCache.Contains("tvshows")) { return(AppCache.Get <List <TvShow> >("tvshows")); } var tvShows = Task.Run(DocumentRepository <TvShow> .GetItemsAsync).Result; AppCache.Add("tvshows", tvShows, DateTime.Now.AddHours(12)); return(tvShows); }