Esempio n. 1
0
        public Listing <T> Search <T>(string query, Sorting sortE, TimeSorting timeE) where T : Thing
        {
            string sort = sortE.ToString().ToLower();
            string time = timeE.ToString().ToLower();

            return(new Listing <T>(this, string.Format(SearchUrl, query, sort, time), WebAgent));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 /// <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">When to begin. </param>
 /// <param name="to">When to end. </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
 {
     return(SearchByTimestamp <T>(new DateTimeOffset(from), new DateTimeOffset(to), query, subreddit, sortE, timeE));
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        /// <summary>
        /// Search using specific terms from a specified time to now
        /// </summary>
        /// <param name="terms">Terms you want to search for</param>
        /// <param name="sortE">Sort the way you want to, see <see cref="Sorting"/></param>
        /// <param name="timeE">Time sorting you want to see</param>
        /// <param name="max">Number of records to return.  -1 for unliminted.</param>
        /// <returns>A list of posts</returns>
        public Listing <Post> Search(string terms, Sorting sortE = Sorting.Relevance, TimeSorting timeE = TimeSorting.All, int max = -1)
        {
            string sort = sortE.ToString().ToLower();
            string time = timeE.ToString().ToLower();

            return(Listing <Post> .Create(WebAgent, SearchUrl(Uri.EscapeUriString(terms), sort, time), max, 100));
        }
Esempio n. 7
0
        /// <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));
        }