Class: Pedicab::RedditQuery
- Inherits:
-
Object
- Object
- Pedicab::RedditQuery
- Includes:
- HTTParty
- Defined in:
- lib/pedicab/query.rb
Instance Method Summary collapse
-
#get_subreddit_posts(subreddit, limit: 25, sort: 'hot') ⇒ Object
Get hot posts from a subreddit.
-
#initialize(topic) ⇒ RedditQuery
constructor
A new instance of RedditQuery.
-
#search(limit: 25, sort: 'relevance', time: 'all') ⇒ Object
Search for posts about the topic.
-
#search_subreddit(subreddit, limit: 25, sort: 'hot') ⇒ Object
Get posts from a specific subreddit about the topic.
Constructor Details
#initialize(topic) ⇒ RedditQuery
9 10 11 |
# File 'lib/pedicab/query.rb', line 9 def initialize(topic) @topic = topic end |
Instance Method Details
#get_subreddit_posts(subreddit, limit: 25, sort: 'hot') ⇒ Object
Get hot posts from a subreddit
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pedicab/query.rb', line 43 def get_subreddit_posts(subreddit, limit: 25, sort: 'hot') = { query: { limit: limit, raw_json: 1 } } response = self.class.get("/r/#{subreddit}/#{sort}.json", ) parse_response(response) end |
#search(limit: 25, sort: 'relevance', time: 'all') ⇒ Object
Search for posts about the topic
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pedicab/query.rb', line 14 def search(limit: 25, sort: 'relevance', time: 'all') = { query: { q: @topic, limit: limit, sort: sort, t: time, raw_json: 1 } } response = self.class.get('/search.json', ) parse_response(response) end |
#search_subreddit(subreddit, limit: 25, sort: 'hot') ⇒ Object
Get posts from a specific subreddit about the topic
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pedicab/query.rb', line 30 def search_subreddit(subreddit, limit: 25, sort: 'hot') = { query: { limit: limit, raw_json: 1 } } response = self.class.get("/r/#{subreddit}/search.json?q=#{@topic}&restrict_sr=1", ) parse_response(response) end |