Copyright:: © 2010 Mike Moore
License:: Distributes under the same terms as Ruby
Disqussion is a library for using the Disqus API.
[sudo] gem install disqussion
or
[sudo] gem sources -a http://gems.github.com
[sudo] gem install blowmage-disqussion
or
git clone git://github.com/blowmage/disqussion.git
cd disqussion
gem build disqussion.gemspec
[sudo] gem install disqussion-0.2.0.gem
Disqussion uses the Disqus terminology of Forums, Threads, and Posts.
For the most typical use a Forum is your blog, a Thread is a blog entry, and a post is a comment.
You need a Disqus account and your Disqus API key to use the Disqussion library.
You can retrieve your Disqus API key here: http://disqus.com/api/get_my_key/
require 'disqussion'
disqus = Disqussion.new 'YWxlaWRzdXRoMzhlbzdydGJna3VhZGpidGdvYThlcnk3YnRvZXVyeWIgb2FlndTh'
Or, you can put your Disqus key in ~./disqus_key and Disqussion will find and use it for you automagically.
The only text in the ~./disqus_key file should be your api key.
require 'disqussion'
disqus = Disqussion.new
Disqussion#new actually retrieves a Disqussion::Session object.
You can call Disqussion::Session#new directly if you like, but Disqussion#new is there to save you from typing more than you need. :)
Disqussion lazilly retrieves all the Forums you are allowed to access and keeps them in Session#forums.
Session#forums is an array of Disqus::Forum objects.
require 'disqussion'
puts "My Disqus Sites:"
Disqussion.new.forums.each do |forum|
puts " forum: #{forum.id} (#{forum.shortname}) - #{forum.name}"
end
If you want to find a specific Forum you can use the Session#[] helper passing in either the forum ID or the shortname.
require 'disqussion'
disqus = Disqussion.new
rubiverse = disqus['123456']
blowmage = disqus['blowmage']
Disqussion lazilly retrieves all the Threads on your Forum.
Forum#threads is an array of Disqus::Thread objects.
require 'disqussion'
puts "My Blog Entries:"
Disqussion.new['blowmage'].threads.each do |thread|
puts " thread: #{thread.id} (#{thread.slug}) - #{thread.title}"
end
If you want to find a specific Thread you can use the Forum#[] helper passing in either the thread ID or the slug.
require 'disqussion'
disqus = Disqussion.new
blowmage = disqus['blowmage']
random_page = blowmage['345678']
another_page = blowmage['announcing-disqussion']
Disqussion lazilly retrieves all the Posts on your Thread.
Thread#posts is an array of Disqus::Post objects.
require 'disqussion'
puts "My Blog Entry Comments:"
Disqussion.new['blowmage']['announcing-disqussion'].posts.each do |post|
puts " post: #{post.id} (#{post.created_at}) - #{post.author.name}"
puts " #{post.message}\n"
end
If you want to find a specific Post you can the Thread#[] helper passing in post ID.
require 'disqussion'
disqus = Disqussion.new
blowmage = disqus['blowmage']
page = blowmage['announcing-disqussion']
comment = page.posts['567890']
You can call the Disqus web API directly using Disqussion::API instead of using the Disqussion Forum, Thread, Post, and Author objects.
You can find more information on the class documentation here.