Class Disqus::Thread

  1. lib/disqus/thread.rb
Parent: Object

Methods

public class

  1. list
  2. new

public instance

  1. ==
  2. posts
  3. update

Attributes

allow_comments [R]
created_at [R]
forum [R]
forum [R]
id [R]
identifier [R]
slug [R]
title [R]
url [R]

Public class methods

list (forum, opts = {})

Returns an array of Thread objects representing the threads belonging to the given Forum.

[show source]
# File lib/disqus/thread.rb, line 24
    def self.list(forum, opts = {})
      response = Disqus::Api::get_thread_list(opts.merge(:forum_id =>forum.id, :forum_api_key => forum.key))
      if response["succeeded"]
        list = response["message"].map do |thread| 
          Thread.new(
            thread["id"],
            forum,
            thread["slug"],
            thread["title"],
            thread["created_at"],
            thread["allow_comments"],
            thread["url"],
            thread["identifier"]
          )
        end
      end
    end
new (id, forum, slug, title, created_at, allow_comments, url, identifier)
[show source]
# File lib/disqus/thread.rb, line 6
    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
      @posts = []
    end

Public instance methods

== (other_thread)

Threads are equal if all their attributes are equal.

[show source]
# File lib/disqus/thread.rb, line 12
    def ==(other_thread)
      id             == other_thread.id             &&
      forum          == other_thread.forum          &&
      slug           == other_thread.slug           &&
      title          == other_thread.title          &&
      created_at     == other_thread.created_at     &&
      allow_comments == other_thread.allow_comments &&
      url            == other_thread.url            &&
      identifier     == other_thread.identifier
    end
posts (force_update = false)

Returns an array of posts belonging to this thread.

[show source]
# File lib/disqus/thread.rb, line 43
    def posts(force_update = false)
      if (@posts.nil? or @posts.empty? or force_update)
        @posts = Disqus::Post.list(self)
      end
      @posts
    end
update (opts = {})

Sets the provided values on the thread object.

Options:

  • :thread_id
  • :title
  • :slug
  • :url
  • :allow_comments
[show source]
# File lib/disqus/thread.rb, line 59
    def update(opts = {})
      result = Disqus::Api::update_thread(opts.merge(
        :forum_api_key  => forum.key,
        :thread_id      => id,
        :title          => title,
        :slug           => slug,
        :url            => url,
        :allow_comments => allow_comments)
      )
      return result["succeeded"]
    end