Acts-As-Disqusable Ruby Gem

The Acts-As-Disqusable Gem helps you easily integrate the Disqus commenting system into your website. It should work for any site programmed in Ruby.

It’s a fork of Norman Clarke’s Disqus Gem and incorporates Thomas Reynolds’s DisqusParty changes (namely, switching to HTTParty and using Jeweler for gem creation, as well as ditching the view helpers).

Disqus API support is “beta.” Right now we’re using API version 1.1.

What is Disqus?

From the Disqus website:

“Disqus, pronounced ”discuss“, is a service and tool for web comments and discussions. The Disqus comment system can be plugged into any website, blog, or application. Disqus makes commenting easier and more interactive, while connecting websites and commenters across a thriving discussion community.”

“Disqus is a free service to the general public with absolutely no inline advertisements.”

Get it

gem install ideaoforder-acts_as_disqusable

Use it:

# easy! class YOUR_MODEL acts_as_disqusable end

# For multiple forums class YOUR_MODEL acts_as_disqusable, :forum_id => X, :forum_shortname => X, :forum_api_key => X end

# with nonstandard DB fields class YOUR_MODEL # title, slug, and thread_id default to title, slug, and thread_id…surprise! acts_as_disqusable, :title_column => ‘name’, :slug_column => ‘permalink’, :thread_id => ‘your_mom’, :prefix => false # this defaults to the associated controller # so Post would create a link like: ‘/posts/slug/ # you can set this to false for just: ’/slug’ # or to a different path: ‘/blog/slug’ end

OPTIONAL: You should create a :thread_id field in the database for each model that is disqusable. This will result in fewer requests to Disqus. Everything but YOUR_MODEL.comment_count() should work without it.

Configure it:

Example - This goes in config/disqus.yml:

- :api_key: YOUR_API_KEY - :account: YOUR_ACCOUNT_NAME - :developer: true or false If you’re only connecting 1 forum to your site: - :forum_api_key: YOUR_FORUM_API_KEY - :forum_id: YOUR_FORUM_ID - :forum_shortname: YOUR_FORUM_SHORTNAME Otherwise, the forum info goes in the model that’s disqusable. You could use a different forum for each model. It would be better to use the new category feature, however. Sadly, I haven’t had time to program that yet.

Options
:api_key => "" # your api key
:account => "", # your disqus account
:developer => false, # allows for threads to work on localhost if set to true
:container_id => 'disqus_thread', # desired thread container
:avatar_size => 48, # squared pixel size of avatars
:num_items => 5, # number of comments to display / this is just the default

:forum_api_key => “” # your forum api key :forum_id => “” # your forum id :forum_shortname => “” # your forum shortname

To get your forum info, in the console:

f = Disqus::Forum.all

# find your forum, let’s say it’s the first

f.first.id f.first.key f.first.shortname

So:

Let’s say Post are disqusable. Then Post.comments(:limit => 5, :exclude => ‘spam’) # class level Will grab the 5 most recent non-spam comments. The default limit and exclude are 5 and ‘spam’. @post.comments Will grab the comments for a post. @post.comment_count

Will grab the number of comments for a given post.

@post.comment_form Will create a comment form appropriate to the @post. This still uses the older javascript form.

There are lots of other options for Threads/Forums etc.

Work with the Disqus API:

See the Disqus::Api class for more info on the Disqus API. You can also read the Disqus developer info here.

Hack it:

Github repository:

http://github.com/ideaoforder/acts_as_disqusable/

Learn more about Disqus:

disqus.com

Thanks to the following contributors:

Legal Stuff

The Disqus Ruby gem was not created by, nor is officially supported by Disqus.com or Big Head Labs, Inc. Use it at your own risk and your own responsibility under the terms of the MIT License.

Copyright © 2008 Mark Dickson, released under the MIT license