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); }
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); }
public async Task <SearchList> GetSearchListAsync(int?year, string query, OmdbType type, int page = 1) { var editedQuery = QueryBuilder.GetSearchListQuery(year, query, type, page); var searchList = await GetOmdbDataAsync <SearchList>(editedQuery); if (searchList.Response.Equals("False")) { throw new HttpRequestException(searchList.Error); } return(searchList); }
public async Task <Item> GetItemByTitleAsync(string title, OmdbType type, int?year, bool fullPlot = false) { var query = QueryBuilder.GetItemByTitleQuery(title, type, year, fullPlot); var item = await GetOmdbDataAsync <Item>(query); if (item.Response.Equals("False")) { throw new HttpRequestException(item.Error); } return(item); }
public void ParseCommand(string command) { var containsSearchParameter = command.Trim().StartsWith("?"); if (containsSearchParameter) { var isMovieSearch = command.ToLower().StartsWith("?movie"); if (isMovieSearch) { this.Type = OmdbType.Movie; } var isTvSearch = command.ToLower().StartsWith("?tv"); if (isTvSearch) { this.Type = OmdbType.Tv; } } }
public Task <SearchList> GetSearchListAsync(string query, OmdbType type, int page = 1) { return(GetSearchListAsync(null, query, type, page)); }
public Task <Item> GetItemByTitleAsync(string title, OmdbType type, bool fullPlot = false) { return(GetItemByTitleAsync(title, type, null, fullPlot)); }
public SearchList GetSearchList(string query, OmdbType type, int page = 1) { return(GetSearchList(null, query, type, page)); }
public Item GetItemByTitle(string title, OmdbType type, bool fullPlot = false) { return(GetItemByTitle(title, type, null, fullPlot)); }