Beispiel #1
0
        /// <summary>
        /// Retreive all episodes from particular show that have aired on a specific date.
        /// </summary>
        /// <param name="showId">Show id</param>
        /// <param name="airDate">Air date</param>
        /// <returns>List of epiodes of particular show</returns>
        public async Task <IEnumerable <Episode> > GetShowEpisodesAsync(int showId, DateTime airDate)
        {
            const string relativeUrl = "/shows";

            var uriBuilder = new UriBuilder(baseApiUrl)
            {
                Path = relativeUrl
            };

            uriBuilder.AppendPathSegments(showId.ToString(), "episodesbydate");
            uriBuilder.BuildQueryString(new { date = airDate.ToString(DATE_ISO_8601, CultureInfo.InvariantCulture) });

            //var response = await httpClient.GetStringAsync(uriBuilder.Uri);
            var httpResponse = await httpClient.GetAsync(uriBuilder.Uri);

            try {
                httpResponse.EnsureSuccessStatusCode();
            } catch (HttpRequestException ex) {
                throw new HttpRequestExtException(httpResponse.StatusCode, ex.Message, ex);
            }

            var response = await httpResponse.Content.ReadAsStringAsync();

            var episodes = DomainObjectFactory.CreateEpisodes(response);

            return(episodes);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a complete list of episodes for the given show.
        /// Episodes are returned in their airing order and include
        /// full episode information.
        ///
        /// By default, specials are not included in the list.
        /// </summary>
        /// <param name="showId">Show id</param>
        /// <param name="includeSpecials">True to include special episodes, otherwise false. Default is true.</param>
        /// <returns>Epiodes list</returns>
        public async Task <IEnumerable <Episode> > GetShowEpisodeListAsync(int showId, bool includeSpecials = true)
        {
            const string relativeUrl = "/shows";

            var uriBuilder = new UriBuilder(baseApiUrl)
            {
                Path = relativeUrl
            };

            uriBuilder.AppendPathSegments(showId.ToString(), "episodes");

            if (includeSpecials)
            {
                uriBuilder.BuildQueryString(new { specials = "1" });
            }

            //var response = await httpClient.GetStringAsync(uriBuilder.Uri);
            var httpResponse = await httpClient.GetAsync(uriBuilder.Uri);

            try {
                httpResponse.EnsureSuccessStatusCode();
            } catch (HttpRequestException ex) {
                throw new HttpRequestExtException(httpResponse.StatusCode, ex.Message, ex);
            }

            var response = await httpResponse.Content.ReadAsStringAsync();

            var episodes = DomainObjectFactory.CreateEpisodes(response);

            return(episodes);
        }