Class: Disqus::Post

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, message, parent_post, shown, is_anonymous, author)
     @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

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author


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

def author
  @author
end

#created_atObject (readonly)

Returns the value of attribute created_at


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

def created_at
  @created_at
end

#forumObject (readonly)

Returns the value of attribute forum


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

def forum
  @forum
end

#idObject (readonly)

Returns the value of attribute id


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

def id
  @id
end

#is_anonymousObject (readonly)

Returns the value of attribute is_anonymous


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

def is_anonymous
  @is_anonymous
end

#messageObject (readonly)

Returns the value of attribute message


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

def message
  @message
end

#parent_postObject (readonly)

Returns the value of attribute parent_post


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

def parent_post
  @parent_post
end

#shownObject (readonly)

Returns the value of attribute shown


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

def shown
  @shown
end

#threadObject (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|
      author = nil
      if post["is_anonymous"] 
        author = AnonymousAuthor.new(
          post["anonymous_author"]["name"],
          post["anonymous_author"]["url"],
          post["anonymous_author"]["email_hash"]
        )
      else
        author = 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"],
        author
      )
    end
    posts.sort!{|a,b| a.created_at <=> b.created_at}
  end
end