Beispiel #1
0
        /// <summary>
        /// Api info: http://cinemate.cc/help/api/movie.list/
        /// </summary>
        public MovieListResponseModel GetList(
            int? year=null,
            string genre=null,
            string country=null,
            DateTime? dateFrom=null,
            DateTime? dateTo=null,

            int page = 0,
            int perPage = 10,

            MovieTypeEnum? type=null, 
            MovieStateEnum state= MovieStateEnum.Cinema,
            MovieViewModeEnum? mode=null,
            MovieOrderTargetEnum orderBy= MovieOrderTargetEnum.ReleaseDateRus,
            MovieOrderDirectionEnum order=MovieOrderDirectionEnum.Desc)
        {
            #region page values correction
            page = perPage < 0 ? 0 : page;
            perPage = perPage < 1 ? 1 : perPage;
            perPage = perPage > 25 ? 25 : perPage;
            #endregion

            var args = new Dictionary<string, object>
            {
                { "apikey", _cinemate.Properties.ApiKey },
                { "state", MovieEnumsConverter.GetStringValue(state) },
                { "order_by", MovieEnumsConverter.GetStringValue(orderBy) },
                { "order", MovieEnumsConverter.GetStringValue(order) },
                { "page", page },
                { "per_page", perPage },
            };

            if (type.HasValue) args.Add("type", MovieEnumsConverter.GetStringValue(type.Value));
            if (mode.HasValue) args.Add("mode", MovieEnumsConverter.GetStringValue(mode.Value));
            if (year.HasValue) args.Add("year", year);
            if (!string.IsNullOrWhiteSpace(genre)) args.Add("genre", genre);
            if (!string.IsNullOrWhiteSpace(country)) args.Add("country", country);
            if (dateFrom.HasValue) args.Add("from", dateFrom.Value.ToString("yyyy.MM.dd"));
            if (dateTo.HasValue) args.Add("to", dateTo.Value.ToString("yyyy.MM.dd"));

            _cinemate.BeginWaitForNextExecute();
            return RemoteHelper.DownloadJson<MovieListResponseModel>(_cinemate.Properties.BaseUrl, "movie.list", args);
        }
        public static string GetStringValue(MovieViewModeEnum value)
        {
            switch (value)
            {
                case MovieViewModeEnum.Best:
                    return "best";

                default:
                    throw new ArgumentOutOfRangeException(value.ToString(), value, null);
            }
        }