lib/reddit/reddit.rb in bterlson-reddit-0.2.1 vs lib/reddit/reddit.rb in bterlson-reddit-0.3.0

- old
+ new

@@ -7,35 +7,39 @@ def initialize(name = nil) @name = name @url = @name.nil? ? BASE_URL : SUBREDDIT_URL.gsub('[subreddit]', @name) end - def hot - articles 'hot' + def hot(options = {}) + articles 'hot', options end - def top - articles 'top' + def top(options = {}) + articles 'top', options end - def new - articles 'new' + def new(options = {}) + options[:querystring] = 'sort=new' + articles 'new', options end - def controversial - articles 'controversial' + def rising(options = {}) + options[:querystring] = 'sort=rising' + articles 'new', options end + def controversial(options = {}) + articles 'controversial', options + end + # Returns the articles found in this reddit. - def articles(page = 'hot') - resources = get_resources("#{@url}#{page}/") - - articles = [] - - resources.each do |article| - articles << Article.new(article['data']) + # Options are: + # Count: Return at least this many articles. + # Querystring: Querystring to append to resource request + + def articles(page = 'hot', options = {}) + get_resources("#{@url}#{page}", options) do |resource_json| + Article.new(resource_json['data']) end - - return articles end end end \ No newline at end of file