Class: Engagement::CommentCounter::Reddit
- Inherits:
-
Object
- Object
- Engagement::CommentCounter::Reddit
- Defined in:
- lib/engagement/comment_counter/reddit.rb
Instance Method Summary collapse
- #comments_count(url) ⇒ Object
-
#initialize ⇒ Reddit
constructor
A new instance of Reddit.
Constructor Details
#initialize ⇒ Reddit
Returns a new instance of Reddit.
4 5 6 |
# File 'lib/engagement/comment_counter/reddit.rb', line 4 def initialize @client = Snoo::Client.new end |
Instance Method Details
#comments_count(url) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/engagement/comment_counter/reddit.rb', line 8 def comments_count(url) response = @client.search(url).parsed_response # Sometimes the Reddit API returns an Array, sometimes it returns a Hash. unless response.is_a?(Array) response = [response] end response.inject(0) do |count, listing| count + extract_count_from(listing) end end |