예제 #1
0
        private static async Task Main(string[] args)
        {
            var theMovieDbApiClient  = new TheMovieDbApiClient();
            var movieDbLiteApiClient = new MovieDbLiteApiClient();

            string movieName = "The Dark Knight";

            if (args.Length > 0)
            {
                // if passed via CLI, use over default
                movieName = args[0];
            }

            DbOrgMovieResults movieResults = await theMovieDbApiClient.GetMovieResults(movieName);

            if (movieResults.Results.Length == 0)
            {
                throw new Exception("No movie results were found from the search");
            }

            // For these purposes, get the top-most movie id based on the search.  Ignore other results.
            long topMostMovieId = movieResults.Results[0].Id;

            DbOrgMovie movie = await theMovieDbApiClient.GetMovie(topMostMovieId);

            await movieDbLiteApiClient.AddNewMovie(movie);

            theMovieDbApiClient.Dispose();
            movieDbLiteApiClient.Dispose();
        }
예제 #2
0
        public async Task <DbOrgMovieResults> GetMovieResults(string queryString)
        {
            string escapedQuery          = Uri.EscapeUriString(queryString);
            HttpResponseMessage response = await MovieDbHttpClient.GetAsync($"search/movie?{ApiKeyParam}&query={escapedQuery}");

            string json = await response.Content.ReadAsStringAsync();

            DbOrgMovieResults movieResults = DbOrgMovieResults.FromJson(json);

            return(movieResults);
        }