class Engagement::CommentCounter::Disqus
Public Class Methods
new(forum_api_key)
click to toggle source
# File lib/engagement/comment_counter/disqus.rb, line 7 def initialize(forum_api_key) @forum_api_key = forum_api_key end
Public Instance Methods
comments_count(url)
click to toggle source
When we don’t own the thread we currently return 0 to prevent an exception from being raised. We’re not sure that this is the best long-term solution.
# File lib/engagement/comment_counter/disqus.rb, line 14 def comments_count(url) if (thread_id = thread_id_for(url)) comments_count_for_thread_id thread_id else 0 end end
Private Instance Methods
comments_count_for_thread_id(thread_id)
click to toggle source
# File lib/engagement/comment_counter/disqus.rb, line 24 def comments_count_for_thread_id(thread_id) counts = ::Disqus::Api.get_num_posts(thread_ids:[thread_id], forum_api_key: @forum_api_key)["message"] counts[thread_id].last end
thread_id_for(url)
click to toggle source
# File lib/engagement/comment_counter/disqus.rb, line 29 def thread_id_for(url) thread = ::Disqus::Api.get_thread_by_url(forum_api_key: @forum_api_key, url: url) thread['message'] && thread['message']['id'] end