Class: Disqus::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/disqus/thread.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, forum, slug, title, created_at, allow_comments, url, identifier) ⇒ Thread

Returns a new instance of Thread.


6
7
8
9
# 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

Instance Attribute Details

#allow_commentsObject (readonly)

Returns the value of attribute allow_comments


4
5
6
# File 'lib/disqus/thread.rb', line 4

def allow_comments
  @allow_comments
end

#created_atObject (readonly)

Returns the value of attribute created_at


4
5
6
# File 'lib/disqus/thread.rb', line 4

def created_at
  @created_at
end

#forumObject (readonly)

Returns the value of attribute forum


4
5
6
# File 'lib/disqus/thread.rb', line 4

def forum
  @forum
end

#idObject (readonly)

Returns the value of attribute id


4
5
6
# File 'lib/disqus/thread.rb', line 4

def id
  @id
end

#identifierObject (readonly)

Returns the value of attribute identifier


4
5
6
# File 'lib/disqus/thread.rb', line 4

def identifier
  @identifier
end

#slugObject (readonly)

Returns the value of attribute slug


4
5
6
# File 'lib/disqus/thread.rb', line 4

def slug
  @slug
end

#titleObject (readonly)

Returns the value of attribute title


4
5
6
# File 'lib/disqus/thread.rb', line 4

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url


4
5
6
# File 'lib/disqus/thread.rb', line 4

def url
  @url
end

Class Method Details

.list(forum, opts = {}) ⇒ Object

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


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Method Details

#==(other_thread) ⇒ Object

Threads are equal if all their attributes are equal.


12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object

Returns an array of posts belonging to this thread.


43
44
45
46
47
48
# 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 = {}) ⇒ Object

Sets the provided values on the thread object.

Options:

  • :thread_id

  • :title

  • :slug

  • :url

  • :allow_comments


59
60
61
62
63
64
65
66
67
68
69
# 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