Permalink
Browse files

cleaned up thread api a little, to match Forum (no more 'load_posts')

  • Loading branch information...
1 parent e9265bc commit d6e1b8ce9e9df7d57106e01565bbd9e0aaea98fe Matthew Van Horn committed Dec 2, 2008
Showing with 10 additions and 7 deletions.
  1. +0 −1 lib/disqus/api.rb
  2. +2 −2 lib/disqus/post.rb
  3. +8 −4 lib/disqus/thread.rb
View
@@ -127,7 +127,6 @@ def get_thread_by_url(opts = {})
# * <tt>:forum_api_key</tt> - the API key for the forum
# * <tt>:thread_id</tt> - the ID of a thread belonging to the given forum
def get_thread_posts(opts = {})
- opts[:api_key] ||= Disqus::defaults[:api_key]
JSON.parse(get('get_thread_posts', :thread_id => opts[:thread_id], :forum_api_key => opts[:forum_api_key]))
end
View
@@ -7,8 +7,8 @@ def initialize(id, forum, thread, created_at, message, parent_post, shown, is_an
@id, @forum, @thread, @created_at, @message, @parent_post, @shown, @is_anonymous, @author = id.to_i, forum, thread, Time.parse(created_at.to_s), message, parent_post, shown, is_anonymous, author
end
- def self.list(thread, opts = {})
- response = Disqus::Api::get_thread_posts(opts.merge(:thread_id =>thread.id, :forum_api_key => thread.forum.key))
+ def self.list(thread)
+ response = Disqus::Api::get_thread_posts(:thread_id =>thread.id, :forum_api_key => thread.forum.key)
if response["succeeded"]
posts = response["message"].map do |post|
author = nil
View
@@ -1,7 +1,7 @@
module Disqus
class Thread
- attr_reader :id, :forum, :slug, :title, :created_at, :allow_comments, :url, :identifier, :forum, :posts
+ attr_reader :id, :forum, :slug, :title, :created_at, :allow_comments, :url, :identifier, :forum
def initialize(id, forum, slug, title, created_at, allow_comments, url, identifier)
@id, @forum, @slug, @title, @created_at, @allow_comments, @url, @identifier = id.to_i, forum, slug, title, Time.parse(created_at.to_s), allow_comments, url, identifier
@@ -34,9 +34,13 @@ def self.list(forum, opts = {})
end
end
end
-
- def load_posts(opts = {})
- @posts = Post.list(self, opts)
+
+ # returns an Array of posts belonging to this thread
+ def posts(force_update = false)
+ if (@posts.nil? or @posts.empty? or force_update)
+ @posts = Disqus::Post.list(self)
+ end
+ @posts
end
def update(opts = {})

0 comments on commit d6e1b8c

Please sign in to comment.