Module: Snoo::Listings
- Defined in:
- lib/snoo/listings.rb
Overview
Methods for getting thing listings. Comments, links, etc
Instance Method Summary collapse
-
#get_comments(opts = {}) ⇒ Object
Get a comment listing from the site.
-
#get_listing(opts = {}) ⇒ Object
Gets a listing of links from reddit.
-
#search(query, opts = {}) ⇒ Object
Search reddit.
Instance Method Details
#get_comments(opts = {}) ⇒ Object
Get a comment listing from the site
18 19 20 21 22 23 |
# File 'lib/snoo/listings.rb', line 18 def get_comments opts = {} query = { limit: 100 } query.merge! opts url = "%s/comments/%s%s.json" % [('/r/' + opts[:subreddit] if opts[:subreddit]), opts[:link_id], ('/blah/' + opts[:comment_id] if opts[:comment_id])] get(url, query: query) end |
#get_listing(opts = {}) ⇒ Object
Gets a listing of links from reddit.
36 37 38 39 40 41 42 43 44 |
# File 'lib/snoo/listings.rb', line 36 def get_listing opts = {} # Build the basic url url = "%s/%s.json" % [('/r/' + opts[:subreddit] if opts[:subreddit] ), (opts[:page] if opts[:page])] # Delete subreddit and page from the hash, they dont belong in the query [:subreddit, :page].each {|k| opts.delete k} query = opts # Make the request get(url, query: query) end |
#search(query, opts = {}) ⇒ Object
Search reddit
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/snoo/listings.rb', line 58 def search query, opts = {} # This supports searches with and without a subreddit url = "%s/search.json" % ('/r/' + opts[:subreddit] if opts[:subreddit]) # Construct the query httpquery = {q: query} opts.delete :subreddit httpquery.merge! opts get(url, query: httpquery) end |