Class: Disqus::Post
- Inherits:
-
Object
- Object
- Disqus::Post
- Defined in:
- lib/disqus/post.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#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.
-
#is_anonymous ⇒ Object
readonly
Returns the value of attribute is_anonymous.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#parent_post ⇒ Object
readonly
Returns the value of attribute parent_post.
-
#shown ⇒ Object
readonly
Returns the value of attribute shown.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
-
.list(thread) ⇒ Object
Returns an array of Post objects representing all posts belonging to the given thread.
Instance Method Summary collapse
-
#initialize(id, forum, thread, created_at, message, parent_post, shown, is_anonymous, author) ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize(id, forum, thread, created_at, message, parent_post, shown, is_anonymous, author) ⇒ Post
Returns a new instance of Post.
6 7 8 |
# File 'lib/disqus/post.rb', line 6 def initialize(id, forum, thread, created_at, , parent_post, shown, is_anonymous, ) @id, @forum, @thread, @created_at, @message, @parent_post, @shown, @is_anonymous, @author = id.to_i, forum, thread, Time.parse(created_at.to_s), , parent_post, shown, is_anonymous, end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def @author end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def created_at @created_at end |
#forum ⇒ Object (readonly)
Returns the value of attribute forum.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def forum @forum end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def id @id end |
#is_anonymous ⇒ Object (readonly)
Returns the value of attribute is_anonymous.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def is_anonymous @is_anonymous end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def @message end |
#parent_post ⇒ Object (readonly)
Returns the value of attribute parent_post.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def parent_post @parent_post end |
#shown ⇒ Object (readonly)
Returns the value of attribute shown.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def shown @shown end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
4 5 6 |
# File 'lib/disqus/post.rb', line 4 def thread @thread end |
Class Method Details
.list(thread) ⇒ Object
Returns an array of Post objects representing all posts belonging to the given thread. The array is sorted by the “created_at” date descending.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/disqus/post.rb', line 12 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| = nil if post["is_anonymous"] = AnonymousAuthor.new( post["anonymous_author"]["name"], post["anonymous_author"]["url"], post["anonymous_author"]["email_hash"] ) else = Author.new( post["author"]["id"].to_i, post["author"]["username"], post["author"]["display_name"], post["author"]["url"], post["author"]["email_hash"], post["author"]["has_avatar"] ) end Post.new( post["id"], thread.forum, thread, post["created_at"], post["message"], post["parent_post"], post["shown"], post["is_anonymous"], ) end posts.sort!{|a,b| a.created_at <=> b.created_at} end end |