Exemplo n.º 1
0
        /// <summary>
        /// Searches the mediahound /lookup endpoint for details about the movies with the ids.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>The observable collection containing movie objects.</returns>
        public async Task <ObservableCollection <Movie> > GetMovieInfoAsync(string id)
        {
            var baseUri = new Uri("https://api.mediahound.com/1.3/graph/lookup?params=");

            _movieList.Clear();

            var param = Uri.EscapeUriString("{\"ids\":[\"" + id + "\"],\"components\":[\"primaryImage\",\"keyTraits\",\"keySuitabilities\"]}");

            var response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                await OAuth2.GenerateAuth2TokenAsync("OAuth2 token expired. Generated a new one.");

                response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);
            }
            if (!response.IsSuccessStatusCode)
            {
                return(_movieList);
            }

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

            JObject jobject = JObject.Parse(content);
            JToken  movies  = jobject["content"];

            if (movies.Any())
            {
                await AddMoviesToList(movies);
            }

            await NextResults(jobject);

            return(_movieList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches the mediahound /search endpoint for movies based on the search input.
        /// </summary>
        /// <param name="searchInput">The search input.</param>
        /// <returns name="_movieList">The ObservableCollection containing Movie objects</returns>
        public async Task <ObservableCollection <Movie> > SearchForMovie(string searchInput)
        {
            var baseUri = new Uri("https://api.mediahound.com/1.3/search/all/");
            var param   = searchInput + "?types=movie&types=showseries";

            _movieList.Clear();

            var response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                await OAuth2.GenerateAuth2TokenAsync("OAuth2 token expired. Generated a new one.");

                response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);
            }
            if (!response.IsSuccessStatusCode)
            {
                return(_movieList);
            }

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

            JObject jobject = JObject.Parse(content);
            JToken  movies  = jobject["content"];

            if (movies.Any())
            {
                await AddMoviesToList(movies);
            }

            await NextResults(jobject);

            return(_movieList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a request to the specified uri
        /// </summary>
        /// <param name="method">The http method.</param>
        /// <param name="uri">The uri string.</param>
        /// <returns></returns>
        public static async Task <HttpResponseMessage> ClientRequest(HttpMethod method, string uri)
        {
            using (var client = new HttpClient())
            {
                if (OAuth2.Token == null)
                {
                    await OAuth2.GenerateAuth2TokenAsync("Token was null. Retrieved new one.");                       //Should never get invoked.
                }
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(OAuth2.TokenType, OAuth2.Token);
                client.DefaultRequestHeaders
                .Accept
                .Add(new MediaTypeWithQualityHeaderValue("application/json"));    //ACCEPT header

                HttpRequestMessage request = new HttpRequestMessage(method, uri);

                return(await client.SendAsync(request));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Searches the mediahound /explore endpoint for movies based the parameters.
        /// </summary>
        /// <param name="genre">The genre.</param>
        /// <param name="year">The year.</param>
        /// <param name="type">The type.</param>
        /// <returns>The observable collection containing movie objects.</returns>
        public async Task <ObservableCollection <Movie> > ExploreMovies(string genre, string year, string type)
        {
            var baseUri = new Uri("https://api.mediahound.com/1.3/graph/explore?params=");

            _movieList.Clear();

            var typeWithoutDash = type.Replace("/", string.Empty);
            var param           = Uri.EscapeUriString("{\"filters\": {\"returnType\": {\"$eq\": \"" + typeWithoutDash + "\"},\"traits\": {\"$eq\": \"mhgnr-" + genre.ToLower() + "\"},\"year\": {\"$in\":[" + year + "]}}, \"components\":[\"primaryImage\"]}");

            var response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                await OAuth2.GenerateAuth2TokenAsync("OAuth2 token expired. Generated a new one.");

                response = await Client.ClientRequest(HttpMethod.Get, baseUri + param);
            }
            if (!response.IsSuccessStatusCode)
            {
                return(_movieList);
            }

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

            JObject jobject = JObject.Parse(content);
            JToken  movies  = jobject["content"];

            if (movies.Any())
            {
                await AddMoviesToList(movies);
            }

            await NextResults(jobject);

            return(_movieList);
        }