Class: Disqus::Thread
- Inherits:
-
Object
- Object
- Disqus::Thread
- Defined in:
- lib/disqus/thread.rb
Instance Attribute Summary collapse
-
#allow_comments ⇒ Object
readonly
Returns the value of attribute allow_comments.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#forum ⇒ Object
readonly
Returns the value of attribute forum.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.list(forum, opts = {}) ⇒ Object
Returns an array of Thread objects representing the threads belonging to the given Forum.
Instance Method Summary collapse
-
#==(other_thread) ⇒ Object
Threads are equal if all their attributes are equal.
-
#initialize(id, forum, slug, title, created_at, allow_comments, url, identifier) ⇒ Thread
constructor
A new instance of Thread.
-
#posts(force_update = false) ⇒ Object
Returns an array of posts belonging to this thread.
-
#update(opts = {}) ⇒ Object
Sets the provided values on the thread object.
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_comments ⇒ Object (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_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def created_at @created_at end |
#forum ⇒ Object (readonly)
Returns the value of attribute forum.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def forum @forum end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def id @id end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def identifier @identifier end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def slug @slug end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/disqus/thread.rb', line 4 def title @title end |
#url ⇒ Object (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 |