/// <summary> /// Return a <see cref="Listing{T}"/> of items matching search with a given time period. /// </summary> /// <typeparam name="T"><see cref="Thing"/></typeparam> /// <param name="from">DateTime from</param> /// <param name="to">DateTime to</param> /// <param name="query">string to query</param> /// <param name="subreddit">subreddit in which to search</param> /// <param name="sortE">Order by <see cref="Sorting"/></param> /// <param name="timeE">Order by <see cref="TimeSorting"/></param> /// <returns></returns> public Listing <T> SearchByTimestamp <T>(DateTime from, DateTime to, string query = "", string subreddit = "", Sorting sortE = Sorting.Relevance, TimeSorting timeE = TimeSorting.All) where T : Thing { string sort = sortE.ToString().ToLower(); string time = timeE.ToString().ToLower(); var fromUnix = (from - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var toUnix = (to - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; string searchQuery = "(and+timestamp:" + fromUnix + ".." + toUnix + "+'" + query + "'+" + "subreddit:'" + subreddit + "')&syntax=cloudsearch"; return(new Listing <T>(this, string.Format(SearchUrl, searchQuery, sort, time), WebAgent)); }
public Listing<Post> Search(string terms, Sorting sortE = Sorting.Relevance, TimeSorting timeE = TimeSorting.All) { string sort = sortE.ToString().ToLower(); string time = timeE.ToString().ToLower(); return new Listing<Post>(Reddit, string.Format(SearchUrl, Name, Uri.EscapeUriString(terms), sort, time), WebAgent); }
/// <summary> /// Return a <see cref="Listing{T}"/> of items matching search. /// </summary> /// <typeparam name="T"><see cref="Thing"/></typeparam> /// <param name="query">string to query</param> /// <param name="sortE">Order by <see cref="Sorting"/></param> /// <param name="timeE">Order by <see cref="TimeSorting"/></param> /// <param name="author">The user who submitted the post</param> /// <param name="flair">The text of the link flair on the post.</param> /// <param name="nsfw">include NSFW posts.</param> /// <param name="self">includ eText post.</param> /// <param name="selfText">For self-posts, the body of the post.</param> /// <param name="site">The domain of the submitted URL.</param> /// <param name="subreddit">The submission's subreddit.</param> /// <param name="title">The submission title.</param> /// <param name="url">The submission's URL (the website's address)</param> /// <remarks>https://www.reddit.com/wiki/search#wiki_field_search</remarks> /// <returns></returns> public Listing <T> Search <T>(string query, Sorting sortE = Sorting.Relevance, TimeSorting timeE = TimeSorting.All, string author = null, string flair = null, bool?nsfw = null, bool?self = null, string selfText = null, string site = null, string subreddit = null, string title = null, string url = null ) where T : Thing { StringBuilder queryBuilder = new StringBuilder(query); if (author != null) { queryBuilder.Append($"+author:{author}"); } if (flair != null) { queryBuilder.Append($"+flair:{flair}"); } if (nsfw != null) { queryBuilder.Append($"+nsfw:{Convert.ToInt16(nsfw.Value)}"); } if (self != null) { queryBuilder.Append($"+self:{Convert.ToInt16(self.Value)}"); } if (selfText != null) { queryBuilder.Append($"+selftext:{selfText}"); } if (site != null) { queryBuilder.Append($"+site:{site}"); } if (subreddit != null) { queryBuilder.Append($"+subreddit:{subreddit}"); } if (title != null) { queryBuilder.Append($"+title:{title}"); } if (url != null) { queryBuilder.Append($"+url:{url}"); } string sort = sortE.ToString().ToLower(); string time = timeE.ToString().ToLower(); string final = string.Format(SearchUrl, queryBuilder.ToString(), sort, time); return(new Listing <T>(this, final, WebAgent)); }