Exemplo n.º 1
0
        /// <summary>
        /// Finds the movies.
        /// </summary>
        /// <param name="searchRequest">The search request.</param>
        public SearchMovie FindMovies(string searchRequest, int pageNumber)
        {
            var instance = new MovieBoxApiService();
            ApiMoviesResponse response = instance.GetMovies(searchRequest, pageNumber);
            SearchMovie       result   = MapMovieApiEntities(response);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the movies from om database.
        /// </summary>
        /// <param name="searchRequest">The search.</param>
        /// <param name="pageNumber">The page number.</param>
        public ApiMoviesResponse GetMovies(string searchRequest, int pageNumber)
        {
            // validate
            if (string.IsNullOrEmpty(searchRequest))
            {
                throw new ApiException(400, $"Missing required parameter {nameof(searchRequest)}");
            }

            if (string.IsNullOrEmpty(apiKey))
            {
                throw new ApiException(400, $"Missing required parameter {nameof(apiKey)}");
            }

            if (string.IsNullOrEmpty(apiTypeContent))
            {
                throw new ApiException(400, $"Missing required parameter {nameof(apiTypeContent)}");
            }

            var path         = "";
            var queryParams  = new Dictionary <string, string>();
            var headerParams = new Dictionary <string, string>();
            var formParams   = new Dictionary <string, string>();

            queryParams.Add("s", searchRequest);
            queryParams.Add("r", "json");
            queryParams.Add("type", apiTypeContent);
            queryParams.Add("apikey", apiKey);
            queryParams.Add("page", pageNumber.ToString());

            // make the HTTP request
            IRestResponse response = (IRestResponse)apiClient.CallApi(path, Method.GET, queryParams, headerParams, formParams, null);

            if (((int)response.StatusCode) > 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling OMDB API: " + response.Content, response.Content);
            }
            else if (response.StatusCode == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling OMDB API: " + response.ErrorMessage, response.ErrorMessage);
            }

            // deserialize
            ApiMoviesResponse result = JsonConvert.DeserializeObject <ApiMoviesResponse>(response.Content, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Maps the full info movie entities
        /// from api model to Bl model.
        /// </summary>
        /// <param name="movie">The movie.</param>
        private SearchMovie MapMovieApiEntities(ApiMoviesResponse movieResponse)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <ApiMoviesResponse, SearchMovie>();
                cfg.CreateMap <ApiSearch, SearchDetails>();
            });

            config.AssertConfigurationIsValid();

            IMapper     iMapper     = config.CreateMapper();
            SearchMovie destination = iMapper.Map <ApiMoviesResponse, SearchMovie>(movieResponse);

            return(destination);
        }