/// <summary> /// Determines whether the current mapping can map market with provided specifiers associated with provided producer and sport /// </summary> /// <param name="producer">The <see cref="IProducer" /> associated with the market</param> /// <param name="sportId">The <see cref="URN" /> specifying the sport associated with the market</param> /// <param name="specifiers">The market specifiers</param> /// <returns>True if the current mapping can be used to map the specified market. False otherwise</returns> /// <exception cref="InvalidOperationException">The provided specifiers are not valid</exception> public bool CanMap(IProducer producer, URN sportId, IReadOnlyDictionary <string, string> specifiers) { if (!ProducerIds.Contains(producer.Id) || SportId != null && !SportId.Equals(sportId)) { return(false); } return(_validator?.Validate(specifiers) ?? true); }
/// <summary> /// Create query from current parameters for search request. /// </summary> /// <returns>Query from current parameters for search request</returns> public string ConfigToString() { var builder = new StringBuilder().Append('?'); if (Page.HasValue) { Guard.IsGreaterThanZero(Page.Value, nameof(Page.Value)); builder.Append($"page={Page.Value}&"); } if (PageSize.HasValue) { Guard.IsGreaterThanZero(PageSize.Value, nameof(PageSize.Value)); Guard.IsLesserOrEqualThan(PageSize.Value, ParameterConsts.MaximumPageSize, nameof(PageSize.Value)); builder.Append($"limit={PageSize.Value}&"); } if (!string.IsNullOrWhiteSpace(Query)) { builder.Append($"q={Query}&"); } if (Letter.HasValue) { Guard.IsLetter(Letter.Value, nameof(Letter.Value)); builder.Append($"letter={Letter.Value}&"); } if (Type != AnimeType.EveryType) { Guard.IsValidEnum(Type, nameof(Type)); builder.Append($"type={Type.GetDescription()}&"); } if (MinimumScore.HasValue) { builder.Append($"min_score={MinimumScore}&"); } if (MaximumScore.HasValue) { builder.Append($"max_score={MaximumScore}&"); } if (Rating != AnimeAgeRating.EveryRating) { Guard.IsValidEnum(Rating, nameof(Rating)); builder.Append($"rated={Rating.GetDescription()}&"); } if (Status != AiringStatus.EveryStatus) { Guard.IsValidEnum(Status, nameof(Status)); builder.Append($"status={Status.GetDescription()}&"); } if (Genres.Count > 0) { var genresIds = Genres.Select(genreSearch => { Guard.IsValidEnum(genreSearch, nameof(genreSearch)); return(genreSearch.GetDescription()); }).ToArray(); builder.Append($"genres={string.Join(",", genresIds)}&"); } if (ExcludedGenres.Count > 0) { var genresIds = ExcludedGenres.Select(genreSearch => { Guard.IsValidEnum(genreSearch, nameof(genreSearch)); return(genreSearch.GetDescription()); }).ToArray(); builder.Append($"genre_exclude={string.Join(",", genresIds)}&"); } if (OrderBy != AnimeSearchOrderBy.NoSorting) { Guard.IsValidEnum(OrderBy, nameof(OrderBy)); Guard.IsValidEnum(SortDirection, nameof(SortDirection)); builder.Append($"order_by={OrderBy.GetDescription()}&"); builder.Append($"sort={SortDirection.GetDescription()}&"); } if (ProducerIds.Any()) { builder.Append($"producers={string.Join(",", ProducerIds)}&"); } if (Sfw) { builder.Append("sfw"); } return(builder.ToString().Trim('&')); }