Class: Disqus::Thread

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Thread

Returns a new instance of Thread.



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

def initialize(data)
  data.each { |k, v| send(:"#{k}=", v) }
end

Instance Attribute Details

#allow_commentsObject

Returns the value of attribute allow_comments.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def allow_comments
  @allow_comments
end

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def category
  @category
end

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def created_at
  @created_at
end

#forumObject

Returns the value of attribute forum.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def forum
  @forum
end

#hiddenObject

Returns the value of attribute hidden.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def hidden
  @hidden
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def id
  @id
end

#identifierObject

Returns the value of attribute identifier.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def identifier
  @identifier
end

#slugObject

Returns the value of attribute slug.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def slug
  @slug
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def title
  @title
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/acts_as_disqusable/thread.rb', line 3

def url
  @url
end

Class Method Details

.find_or_create(title, identifier) ⇒ Object



8
9
10
11
# File 'lib/acts_as_disqusable/thread.rb', line 8

def self.find_or_create(title, identifier)
  response = self.post('/thread_by_identifier', :body => { :title => title, :identifier => identifier }.merge(self.default_params))
  Disqus::Thread.new(response["message"]["thread"])
end

.posts(thread_id, opts = {:exclude => 'spam'}) ⇒ Object

Returns an array of posts belonging to this thread. limit — Number of entries that should be included in the response. Default is 25. start — Starting point for the query. Default is 0. filter — Type of entries that should be returned (new, spam or killed). exclude — Type of entries that should be excluded from the response (new, spam or killed).



23
24
25
26
# File 'lib/acts_as_disqusable/thread.rb', line 23

def self.posts(thread_id, opts={:exclude => 'spam'})
  response = self.get('/get_thread_posts', :query => opts.merge(:thread_id => thread_id ))
  response["message"].map { |data| Disqus::Post.new(data) }
end

Instance Method Details

#posts(opts = {:exclude => 'spam'}) ⇒ Object



28
29
30
# File 'lib/acts_as_disqusable/thread.rb', line 28

def posts(opts={:exclude => 'spam'})
  self.class.posts(self.id)
end

#posts_countObject



13
14
15
16
# File 'lib/acts_as_disqusable/thread.rb', line 13

def posts_count
  response = self.class.get('/get_num_posts', :query => { :thread_ids => id })
  response["message"][id].first.to_i
end

#update(opts = {}) ⇒ Object

Sets the provided values on the thread object.



33
34
35
36
# File 'lib/acts_as_disqusable/thread.rb', line 33

def update(opts = {})
  result = self.class.post('/update_thread', :query => opts.merge(:forum_api_key  => forum.key))
  return result["succeeded"]
end