Class: Disqus::Forum
- Inherits:
-
Object
- Object
- Disqus::Forum
- Defined in:
- lib/acts_as_disqusable/forum.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#shortname ⇒ Object
Returns the value of attribute shortname.
Class Method Summary collapse
- .all ⇒ Object
- .find(id) ⇒ Object
-
.get_thread_by_url(url, key) ⇒ Object
Returns a thread associated with the given URL.
-
.posts(key, opts = {:exclude => 'spam'}) ⇒ Object
Returns an array of posts belonging to this thread.
- .posts_count(thread_ids, key) ⇒ Object
- .thread_by_identifier(identifier, title, key) ⇒ Object
-
.threads(id, key) ⇒ Object
Returns an array of threads belonging to this forum.
-
.update_thread(thread_id, key, opts = {}) ⇒ Object
Sets the provided values on the thread object.
Instance Method Summary collapse
- #get_thread_by_url(url) ⇒ Object
-
#initialize(data) ⇒ Forum
constructor
A new instance of Forum.
-
#key(user_api_key = nil) ⇒ Object
Returns the forum API Key for this forum.
- #posts(opts = {:exclude => 'spam'}) ⇒ Object
- #posts_count(thread_ids) ⇒ Object
- #thread_by_identifier(identifier, title) ⇒ Object
- #threads ⇒ Object
- #update_thread(thread_id, opts = {}) ⇒ Object
Constructor Details
#initialize(data) ⇒ Forum
Returns a new instance of Forum.
5 6 7 |
# File 'lib/acts_as_disqusable/forum.rb', line 5 def initialize(data) data.each { |k, v| send(:"#{k}=", v) } end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/acts_as_disqusable/forum.rb', line 4 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/acts_as_disqusable/forum.rb', line 4 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/acts_as_disqusable/forum.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/acts_as_disqusable/forum.rb', line 4 def name @name end |
#shortname ⇒ Object
Returns the value of attribute shortname.
4 5 6 |
# File 'lib/acts_as_disqusable/forum.rb', line 4 def shortname @shortname end |
Class Method Details
.all ⇒ Object
9 10 11 12 13 14 |
# File 'lib/acts_as_disqusable/forum.rb', line 9 def self.all @@all ||= begin response = get('/get_forum_list') response["succeeded"] ? response["message"].map { |data| Disqus::Forum.new(data) } : nil end end |
.find(id) ⇒ Object
16 17 18 19 20 |
# File 'lib/acts_as_disqusable/forum.rb', line 16 def self.find(id) id = id.to_s if !id.is_a? String grouped = self.all.group_by(&:id) grouped[id].first if grouped[id] end |
.get_thread_by_url(url, key) ⇒ Object
Returns a thread associated with the given URL.
A thread will only have an associated URL if it was automatically created by Disqus javascript embedded on that page.
50 51 52 53 |
# File 'lib/acts_as_disqusable/forum.rb', line 50 def self.get_thread_by_url(url, key) response = self.get('/get_thread_by_url', :query => { :url => url, :forum_api_key => key }) response["succeeded"] ? Thread.new(response["message"]) : nil end |
.posts(key, opts = {:exclude => 'spam'}) ⇒ Object
Returns an array of posts belonging to this thread.
108 109 110 111 112 |
# File 'lib/acts_as_disqusable/forum.rb', line 108 def self.posts(key, opts={:exclude => 'spam'}) response = self.get('/get_forum_posts', :query => opts.merge(:forum_api_key => key )) out = Hash.new response["message"].map { |data| Disqus::Post.new(data) } end |
.posts_count(thread_ids, key) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/acts_as_disqusable/forum.rb', line 92 def self.posts_count(thread_ids, key) response = self.get('/get_num_posts', :query => { :thread_ids => thread_ids, :forum_api_key => key }) out = Hash.new response["message"].each { |id, data| out[id] = data.first } if out.length == 1 return out.values.first else return out end end |
.thread_by_identifier(identifier, title, key) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/acts_as_disqusable/forum.rb', line 59 def self.thread_by_identifier(identifier, title, key) response = self.post('/thread_by_identifier', :query => { :forum_api_key => key, :identifier => identifier, :title => title }) response["succeeded"] ? Thread.new(response["message"]["thread"]) : nil end |
.threads(id, key) ⇒ Object
Returns an array of threads belonging to this forum.
34 35 36 37 38 39 40 |
# File 'lib/acts_as_disqusable/forum.rb', line 34 def self.threads(id, key) response = self.get('/get_thread_list', :query => { :forum_api_key => key, :forum_id => id }) response["succeeded"] ? response["message"].map { |data| Disqus::Thread.new(data) } : nil end |
.update_thread(thread_id, key, opts = {}) ⇒ Object
Sets the provided values on the thread object.
Returns an empty success message.
Options:
-
:title
- the title of the thread -
:slug
- the per-forum-unique string used for identifying this thread in disqus.com URL’s relating to this thread. Composed of underscore-separated alphanumeric strings. -
:url
- the URL this thread is on, if known. -
:allow_comment
- whether this thread is open to new comments
83 84 85 86 |
# File 'lib/acts_as_disqusable/forum.rb', line 83 def self.update_thread(thread_id, key, opts = {}) response = self.post('/update_thread', :query => opts.merge(:forum_api_key => key)) response["succeeded"] end |
Instance Method Details
#get_thread_by_url(url) ⇒ Object
55 56 57 |
# File 'lib/acts_as_disqusable/forum.rb', line 55 def get_thread_by_url(url) self.class.get_thread_by_url(url, self.key) end |
#key(user_api_key = nil) ⇒ Object
Returns the forum API Key for this forum.
23 24 25 26 27 28 29 30 31 |
# File 'lib/acts_as_disqusable/forum.rb', line 23 def key(user_api_key = nil) @key ||= begin response = self.class.get('/get_forum_api_key', :query => { :api_key => user_api_key, :forum_id => id }) response["succeeded"] ? response["message"] : nil end end |
#posts(opts = {:exclude => 'spam'}) ⇒ Object
114 115 116 |
# File 'lib/acts_as_disqusable/forum.rb', line 114 def posts(opts={:exclude => 'spam'}) self.class.posts(self.key) end |
#posts_count(thread_ids) ⇒ Object
103 104 105 |
# File 'lib/acts_as_disqusable/forum.rb', line 103 def posts_count(thread_ids) self.class.posts_count(thread_ids, self.key) end |
#thread_by_identifier(identifier, title) ⇒ Object
69 70 71 |
# File 'lib/acts_as_disqusable/forum.rb', line 69 def thread_by_identifier(identifier, title) self.class.thread_by_identifier(identifier, title, self.key) end |
#threads ⇒ Object
42 43 44 |
# File 'lib/acts_as_disqusable/forum.rb', line 42 def threads self.class.threads(self.id, self.key) end |
#update_thread(thread_id, opts = {}) ⇒ Object
88 89 90 |
# File 'lib/acts_as_disqusable/forum.rb', line 88 def update_thread(thread_id, opts = {}) self.class.update_thread(thread_id, self.key, opts = {}) end |