Exemplo n.º 1
0
        public MovieSearchResults GetMovieDetails(string movieName, int page)
        {
            var request = new RestRequest("3/search/movie?api_key=" + _config.Value.video_api_key + "&language=en-US&query=" + movieName + "&page=" + page + "&include_adult=false", Method.GET);
            MovieSearchResults response2 = _restClient.Execute <MovieSearchResults>(request).Data;

            return(response2);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse Search Results For Movies
        /// </summary>
        /// <param name="json">JSON string to parse</param>
        /// <returns>MovieSearchResult object containing a list of Movie objects</returns>
        public static MovieSearchResults ParseMovieSearchResults(string json)
        {
            JObject jObject = JObject.Parse(json);

            var result = new MovieSearchResults();

            if (jObject["total"] != null)
                result.ResultCount = (int)jObject["total"];

            var movies = (JArray)jObject["movies"];
            if (movies != null)
            {
                foreach (var movie in movies)
                {
                    Movie m = ParseMovie(movie.ToString());
                    result.Add(m);
                }
            }

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse Search Results For Movies
        /// </summary>
        /// <param name="json">JSON string to parse</param>
        /// <returns>MovieSearchResult object containing a list of Movie objects</returns>
        public static MovieSearchResults ParseMovieSearchResults(string json)
        {
            JObject jObject = JObject.Parse(json);

            var result = new MovieSearchResults();

            if (jObject["total"] != null)
            {
                result.ResultCount = (int)jObject["total"];
            }

            var movies = (JArray)jObject["movies"];

            if (movies != null)
            {
                foreach (var movie in movies)
                {
                    Movie m = ParseMovie(movie.ToString());
                    result.Add(m);
                }
            }

            return(result);
        }
        public static MovieSearchResults ParseMovieSearchResults(string json)
        {
            JObject            jObject = JObject.Parse(json);
            MovieSearchResults results = new MovieSearchResults();

            int resultCount = 0;

            int.TryParse(jObject["total"].ToString(), out resultCount);
            results.ResultCount = resultCount;

            var movies = (JArray)jObject["movies"];

            foreach (var movie in movies)
            {
                Result result = new Result();

                result.Title = (string)movie["title"];

                var    tmpIdString    = (string)movie["id"];
                string idInStringForm = movie["id"].ToString().Substring(1, tmpIdString.Length);
                result.RottenTomatoesId = Convert.ToInt32(idInStringForm);

                int year = 0;
                int.TryParse(movie["year"].ToString(), out year);
                result.Year = year;

                int runtime;
                int.TryParse(movie["runtime"].ToString(), out runtime);
                result.Runtime = runtime;

                result.Synopsis = (string)movie["synopsis"];

                var dates = (JObject)movie["release_dates"];
                foreach (var date in dates)
                {
                    ReleaseDate releaseDate = new ReleaseDate();
                    releaseDate.Type = (string)date.Key;
                    var tmpDate = ((string)date.Value).Substring(0, ((string)date.Value).Count());
                    releaseDate.Date = DateTime.Parse(tmpDate);
                    result.ReleaseDates.Add(releaseDate);
                }

                var ratings = (JObject)movie["ratings"];
                foreach (var rating in ratings)
                {
                    Rating newRating = new Rating();
                    newRating.Type = (string)rating.Key;

                    int score = 0;
                    int.TryParse(rating.Value.ToString(), out score);
                    newRating.Score = score;
                    result.Ratings.Add(newRating);
                }

                var posters = (JObject)movie["posters"];
                foreach (var poster in posters)
                {
                    Poster newPoster = new Poster();
                    newPoster.Type = (string)poster.Key;
                    newPoster.Url  = (string)poster.Value;
                    result.Posters.Add(newPoster);
                }

                var castMembers = (JArray)movie["abridged_cast"];
                foreach (var castMember in castMembers)
                {
                    CastMember member = new CastMember();
                    member.Actor = (string)castMember["name"];
                    var characters = (JArray)castMember["characters"];
                    if (characters != null)
                    {
                        foreach (var character in characters)
                        {
                            member.Characters.Add((string)character);
                            result.Cast.Add(member);
                        }
                    }
                }

                var links = (JObject)movie["links"];
                foreach (var link in links)
                {
                    Link newLink = new Link();
                    newLink.Type = (string)link.Key;
                    newLink.Url  = (string)link.Value;
                    result.Links.Add(newLink);
                }

                results.Results.Add(result);
            }

            return(results);
        }