Пример #1
0
        public static string GetSearchListQuery(int?year, string query, OmdbType type, int page)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(query));
            }

            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page), "Page has to be greater than zero.");
            }

            var editedQuery = $"&s={Regex.Replace(query, @"\s+", "+")}&page={page}";

            if (type != OmdbType.None)
            {
                editedQuery += $"&type={type.ToString()}";
            }

            if (year != null)
            {
                if (year > 1800)
                {
                    editedQuery += $"&y={year}";
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(year), "Year has to be greater than 1800.");
                }
            }

            return(editedQuery);
        }
Пример #2
0
        public static string GetItemByTitleQuery(string title, OmdbType type, int?year, bool fullPlot)
        {
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(title));
            }

            var editedTitle = Regex.Replace(title, @"\s+", "+");
            var plot        = fullPlot ? "full" : "short";

            var query = $"&t={editedTitle}&plot={plot}";

            if (year != null)
            {
                if (year > 1800)
                {
                    query += $"&y={year}";
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(year), "Year has to be greater than 1800.");
                }
            }

            if (type != OmdbType.None)
            {
                query += $"&type={type.ToString()}";
            }

            return(query);
        }