disqus 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +38 -0
- data/README.rdoc +116 -0
- data/Rakefile +20 -39
- data/disqus.gemspec +46 -0
- data/init.rb +7 -1
- data/lib/disqus.rb +17 -4
- data/lib/disqus/api.rb +264 -0
- data/lib/disqus/author.rb +27 -0
- data/lib/disqus/forum.rb +126 -0
- data/lib/disqus/post.rb +51 -0
- data/lib/disqus/thread.rb +73 -0
- data/lib/disqus/version.rb +8 -0
- data/lib/disqus/widget.rb +9 -9
- data/tasks/rcov.rake +23 -0
- data/test/api_test.rb +80 -0
- data/test/config.yml +3 -0
- data/test/config.yml.sample +3 -0
- data/test/forum_test.rb +70 -0
- data/test/merb_test.rb +15 -0
- data/test/post_test.rb +18 -0
- data/test/rails_test.rb +18 -0
- data/test/responses/bad_api_key.json +1 -0
- data/test/responses/create_post.json +23 -0
- data/test/responses/get_forum_api_key.json +1 -0
- data/test/responses/get_forum_list.json +12 -0
- data/test/responses/get_num_posts.json +11 -0
- data/test/responses/get_thread_by_url.json +18 -0
- data/test/responses/get_thread_list.json +16 -0
- data/test/responses/get_thread_posts.json +37 -0
- data/test/responses/thread_by_identifier.json +17 -0
- data/test/responses/update_thread.json +5 -0
- data/test/test_helper.rb +32 -0
- data/test/thread_test.rb +28 -0
- metadata +116 -16
- metadata.gz.sig +0 -0
- data/README.textile +0 -94
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
History.txt
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
disqus.gemspec
|
7
|
+
init.rb
|
8
|
+
lib/disqus.rb
|
9
|
+
lib/disqus/api.rb
|
10
|
+
lib/disqus/author.rb
|
11
|
+
lib/disqus/forum.rb
|
12
|
+
lib/disqus/post.rb
|
13
|
+
lib/disqus/thread.rb
|
14
|
+
lib/disqus/version.rb
|
15
|
+
lib/disqus/view_helpers.rb
|
16
|
+
lib/disqus/widget.rb
|
17
|
+
tasks/rcov.rake
|
18
|
+
test/api_test.rb
|
19
|
+
test/config.yml
|
20
|
+
test/config.yml.sample
|
21
|
+
test/forum_test.rb
|
22
|
+
test/merb_test.rb
|
23
|
+
test/post_test.rb
|
24
|
+
test/rails_test.rb
|
25
|
+
test/responses/bad_api_key.json
|
26
|
+
test/responses/create_post.json
|
27
|
+
test/responses/get_forum_api_key.json
|
28
|
+
test/responses/get_forum_list.json
|
29
|
+
test/responses/get_num_posts.json
|
30
|
+
test/responses/get_thread_by_url.json
|
31
|
+
test/responses/get_thread_list.json
|
32
|
+
test/responses/get_thread_posts.json
|
33
|
+
test/responses/thread_by_identifier.json
|
34
|
+
test/responses/update_thread.json
|
35
|
+
test/test_helper.rb
|
36
|
+
test/thread_test.rb
|
37
|
+
test/view_helpers_test.rb
|
38
|
+
test/widget_test.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
== Disqus Ruby Gem
|
2
|
+
|
3
|
+
The Disqus Gem helps you easily integrate the {Disqus}[http://disqus.com]
|
4
|
+
commenting system into your website. It works for any site programmed in Ruby,
|
5
|
+
and has view helpers for Rails and Merb.
|
6
|
+
|
7
|
+
Support for the Disqus Javascript widgets is stable. Disqus API support is
|
8
|
+
"beta."
|
9
|
+
|
10
|
+
=== What is Disqus?
|
11
|
+
|
12
|
+
From the Disqus website:
|
13
|
+
|
14
|
+
"Disqus, pronounced "discuss", is a service and tool for web comments and
|
15
|
+
discussions. The Disqus comment system can be plugged into any website, blog,
|
16
|
+
or application. Disqus makes commenting easier and more interactive, while
|
17
|
+
connecting websites and commenters across a thriving discussion community."
|
18
|
+
|
19
|
+
"Disqus is a free service to the general public with absolutely no inline advertisements."
|
20
|
+
|
21
|
+
=== Get it
|
22
|
+
|
23
|
+
gem install disqus
|
24
|
+
|
25
|
+
==== Bleeding Edge
|
26
|
+
|
27
|
+
gem install norman-disqus --source http://gems.github.com
|
28
|
+
|
29
|
+
=== Use it:
|
30
|
+
|
31
|
+
==== Configure it:
|
32
|
+
|
33
|
+
===== Generic example:
|
34
|
+
|
35
|
+
Disqus::defaults[:account] = "my_disqus_account"
|
36
|
+
# Optional, only if you're using the API
|
37
|
+
Disqus::defaults[:api_key] = "my_disqus_api_key"
|
38
|
+
|
39
|
+
===== Rails-specific example:
|
40
|
+
|
41
|
+
# in config/development.rb (or production.rb, test.rb, etc.)
|
42
|
+
config.after_initialize do
|
43
|
+
Disqus::defaults[:account] = "my_disqus_account"
|
44
|
+
# Optional, only if you're using the API
|
45
|
+
Disqus::defaults[:api_key] = "my_disqus_api_key"
|
46
|
+
end
|
47
|
+
|
48
|
+
Note that here the "after initialize" is necessary, otherwise your settings
|
49
|
+
won't be set properly.
|
50
|
+
|
51
|
+
==== Show the comment threads widget on a post page:
|
52
|
+
|
53
|
+
# Loads the commenting system
|
54
|
+
disqus_thread
|
55
|
+
|
56
|
+
# Or if you're not using Rails/Merb:
|
57
|
+
Disqus::Widget::thread
|
58
|
+
|
59
|
+
# Sets the inner html to the comment count for any links on the page that
|
60
|
+
# have the anchor "disqus_thread". For example, "View Comments" below would
|
61
|
+
# be replaced by "1 comment" or "23 comments" etc.
|
62
|
+
# <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
|
63
|
+
# <a href="http://my.website/different-permalink#disqus_thread">View Comments</a>
|
64
|
+
disqus_comment_counts
|
65
|
+
|
66
|
+
# Or if you're not using Rails/Merb:
|
67
|
+
Disqus::Widget::comment_counts
|
68
|
+
|
69
|
+
==== Show the combo widget on a post page:
|
70
|
+
|
71
|
+
disqus_combo(:color => "blue", :hide_mods => false, :num_items => 20)
|
72
|
+
|
73
|
+
# Or for non-Rails/Merb:
|
74
|
+
Disqus::Widget::combo(:color => "blue", :hide_mods => false, :num_items => 20)
|
75
|
+
|
76
|
+
==== Show the comment count on a permalink:
|
77
|
+
|
78
|
+
link_to("Permalink", post_path(@post, :anchor => "disqus_thread"))
|
79
|
+
...
|
80
|
+
disqus_comment_counts
|
81
|
+
|
82
|
+
# Or for non-Rails/Merb:
|
83
|
+
Disqus::Widget::comment_counts
|
84
|
+
|
85
|
+
==== Work with the Disqus API:
|
86
|
+
|
87
|
+
See the Disqus::Api class for more info on the Disqus API. You can also read
|
88
|
+
the {Disqus developer info here}[http://disqus.com/docs/api/].
|
89
|
+
|
90
|
+
=== Hack it:
|
91
|
+
|
92
|
+
Github repository:
|
93
|
+
|
94
|
+
http://github.com/norman/disqus
|
95
|
+
|
96
|
+
=== Submit bug reports:
|
97
|
+
|
98
|
+
Please use our {Lighthouse}[http://randomba.lighthouseapp.com/projects/16065-disqus/].
|
99
|
+
|
100
|
+
=== Learn more about Disqus:
|
101
|
+
|
102
|
+
{http://disqus.com}[http://disqus.com]
|
103
|
+
|
104
|
+
=== Thanks to the following contributors:
|
105
|
+
|
106
|
+
* {Matt Van Horn}[http://github.com/mattvanhorn] - Disqus API
|
107
|
+
* {Quin Hoxie}[http://github.com/qhoxie] - Merb support
|
108
|
+
|
109
|
+
=== Legal Stuff
|
110
|
+
|
111
|
+
The Disqus Ruby gem was not created by, nor is officially supported by
|
112
|
+
Disqus.com or Big Head Labs, Inc. Use it at your own risk and your own
|
113
|
+
responsibility under the terms of the MIT License.
|
114
|
+
|
115
|
+
Copyright (c) 2008 {Norman Clarke}[mailto:norman@randomba.org], released under
|
116
|
+
the MIT license
|
data/Rakefile
CHANGED
@@ -1,42 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'rake/rdoctask'
|
1
|
+
require 'newgem'
|
2
|
+
require 'lib/disqus/version'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
desc "Run rcov"
|
22
|
-
task :rcov do
|
23
|
-
rm_f "coverage"
|
24
|
-
rm_f "coverage.data"
|
25
|
-
if PLATFORM =~ /darwin/
|
26
|
-
exclude = '--exclude "gems"'
|
27
|
-
else
|
28
|
-
exclude = '--exclude "rubygems"'
|
29
|
-
end
|
30
|
-
rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude} --no-validator-links"
|
31
|
-
cmd = "#{rcov} #{Dir["test/**/*.rb"].join(" ")}"
|
32
|
-
sh cmd
|
4
|
+
$hoe = Hoe.new("disqus", Disqus::Version::STRING) do |p|
|
5
|
+
p.rubyforge_name = "disqus"
|
6
|
+
p.author = ['Norman Clarke', 'Matthew Van Horn']
|
7
|
+
p.email = ['norman@randomba.org', 'mattvanhorn@gmail.com']
|
8
|
+
p.summary = "Integrates Disqus commenting system into your Ruby-powered site."
|
9
|
+
p.description = 'Integrates Disqus into your Ruby-powered site. Works with any Ruby website, and has view helpers for Rails and Merb.'
|
10
|
+
p.url = 'http://disqus.rubyforge.org'
|
11
|
+
p.test_globs = ['test/**/*_test.rb']
|
12
|
+
p.extra_deps << ['json']
|
13
|
+
p.extra_dev_deps = [
|
14
|
+
['newgem', ">= #{::Newgem::VERSION}"],
|
15
|
+
['mocha']
|
16
|
+
]
|
17
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
18
|
+
changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
19
|
+
p.remote_rdoc_dir = ""
|
33
20
|
end
|
34
21
|
|
35
|
-
|
36
|
-
|
37
|
-
rdoc.rdoc_dir = 'rdoc'
|
38
|
-
rdoc.title = 'Disqus'
|
39
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
|
40
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
-
rdoc.rdoc_files.include('README.textile')
|
42
|
-
end
|
22
|
+
require 'newgem/tasks'
|
23
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
data/disqus.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{disqus}
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Norman Clarke", "Matthew Van Horn"]
|
9
|
+
s.cert_chain = ["/Users/norman/.gem/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2009-01-05}
|
11
|
+
s.description = %q{Integrates Disqus into your Ruby-powered site. Works with any Ruby website, and has view helpers for Rails and Merb.}
|
12
|
+
s.email = ["norman@randomba.org", "mattvanhorn@gmail.com"]
|
13
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
14
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "disqus.gemspec", "init.rb", "lib/disqus.rb", "lib/disqus/api.rb", "lib/disqus/author.rb", "lib/disqus/forum.rb", "lib/disqus/post.rb", "lib/disqus/thread.rb", "lib/disqus/version.rb", "lib/disqus/view_helpers.rb", "lib/disqus/widget.rb", "tasks/rcov.rake", "test/api_test.rb", "test/config.yml", "test/config.yml.sample", "test/forum_test.rb", "test/merb_test.rb", "test/post_test.rb", "test/rails_test.rb", "test/responses/bad_api_key.json", "test/responses/create_post.json", "test/responses/get_forum_api_key.json", "test/responses/get_forum_list.json", "test/responses/get_num_posts.json", "test/responses/get_thread_by_url.json", "test/responses/get_thread_list.json", "test/responses/get_thread_posts.json", "test/responses/thread_by_identifier.json", "test/responses/update_thread.json", "test/test_helper.rb", "test/thread_test.rb", "test/view_helpers_test.rb", "test/widget_test.rb"]
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.homepage = %q{http://disqus.rubyforge.org}
|
17
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{disqus}
|
20
|
+
s.rubygems_version = %q{1.3.1}
|
21
|
+
s.signing_key = %q{/Users/norman/.gem/gem-private_key.pem}
|
22
|
+
s.summary = %q{Integrates Disqus commenting system into your Ruby-powered site.}
|
23
|
+
s.test_files = ["test/api_test.rb", "test/forum_test.rb", "test/merb_test.rb", "test/post_test.rb", "test/rails_test.rb", "test/thread_test.rb", "test/view_helpers_test.rb", "test/widget_test.rb"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
32
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
33
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<json>, [">= 0"])
|
36
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
37
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
38
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<json>, [">= 0"])
|
42
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
43
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
44
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
45
|
+
end
|
46
|
+
end
|
data/init.rb
CHANGED
data/lib/disqus.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
require 'disqus/widget'
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
3
|
+
# == From the {Disqus Website}[http://disqus.com]:
|
4
|
+
|
5
|
+
# "Disqus, pronounced "discuss", is a service and tool for web comments and
|
6
|
+
# discussions. The Disqus comment system can be plugged into any website, blog,
|
7
|
+
# or application. Disqus makes commenting easier and more interactive, while
|
8
|
+
# connecting websites and commenters across a thriving discussion community."
|
9
|
+
#
|
10
|
+
# "Disqus is a free service to the general public with absolutely no inline
|
11
|
+
# advertisements."
|
12
|
+
|
13
|
+
# The Disqus gem helps you quickly and easily integrate Disqus's Javascript
|
14
|
+
# widgets into your Ruby-based website. Adding Disqus to your site literally
|
15
|
+
# takes only a few minutes. The Disqus gem also provides a complete
|
16
|
+
# implementation of the Disqus API for more complex applications.
|
17
|
+
|
18
|
+
# To use this code, please first create an account on Disqus[http://disqus.com].
|
7
19
|
module Disqus
|
8
20
|
|
9
21
|
@defaults = {
|
22
|
+
:api_key => "",
|
10
23
|
:account => "",
|
11
24
|
:avatar_size => 48,
|
12
25
|
:color => "grey",
|
data/lib/disqus/api.rb
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Disqus
|
8
|
+
|
9
|
+
# == Disqus API
|
10
|
+
#
|
11
|
+
# The Api class implements the Disqus API directly. It is not really
|
12
|
+
# intended to be used directly, but rather to use the domain objects of
|
13
|
+
# Forum, Thread, Post, Author and AnonymousAuthor. For full information on
|
14
|
+
# the Disqus API, please see the {Disqus developer info}[http://disqus.com/docs/api/].
|
15
|
+
#
|
16
|
+
# Each method in the Api class takes as a single argument a hash of options,
|
17
|
+
# and returns a Hash with 3 keys:
|
18
|
+
#
|
19
|
+
# * 'succeeded' - contains true or false indicating whether the API call succeeded
|
20
|
+
# * 'code' - if the API call did not succeed, this will contain an error code.
|
21
|
+
# * 'message' - contains the object being returned on success, or an error message on failure.
|
22
|
+
#
|
23
|
+
# === API Keys
|
24
|
+
#
|
25
|
+
# There are two different kinds of API keys:
|
26
|
+
#
|
27
|
+
# ==== User Keys
|
28
|
+
#
|
29
|
+
# Every Disqus account has a User Key; it is used to perform actions
|
30
|
+
# associated with that account. This can be passed in as an option, or
|
31
|
+
# configured as follows:
|
32
|
+
#
|
33
|
+
# Disqus::defaults[:api_key] = "the_user_api_key"
|
34
|
+
#
|
35
|
+
# ==== Forum Keys
|
36
|
+
#
|
37
|
+
# Every Disqus forum has a Forum Key. It can be shared among trusted
|
38
|
+
# moderators of a forum, and is used to perform actions associated with that
|
39
|
+
# forum. The creator of a forum can get the forum's key through the API.
|
40
|
+
class Api
|
41
|
+
|
42
|
+
ROOT = 'http://disqus.com/api'
|
43
|
+
|
44
|
+
class << self
|
45
|
+
|
46
|
+
# Creates a new post on the thread. Does not check against spam filters or ban list.
|
47
|
+
# This is intended to allow automated importing of comments.
|
48
|
+
#
|
49
|
+
# Returns a Hash containing a representation of the post just created:
|
50
|
+
#
|
51
|
+
# Required options hash elements:
|
52
|
+
#
|
53
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
54
|
+
# * <tt>:thread_id</tt> - the thread to post to
|
55
|
+
# * <tt>:message</tt> - the content of the post
|
56
|
+
# * <tt>:author_name</tt> - the post creator's name
|
57
|
+
# * <tt>:author_email</tt> - the post creator's email address
|
58
|
+
#
|
59
|
+
# Optional:
|
60
|
+
#
|
61
|
+
# * <tt>:parent_post</tt> - the id of the parent post
|
62
|
+
# * <tt>:created_at</tt> - the UTC date this post was created, in the format <tt>%Y-%m-%dT%H:%M</tt> (the current time will be used by default)
|
63
|
+
# * <tt>:author_url</tt> - the author's homepage
|
64
|
+
# * <tt>:ip_address</tt> - the author's IP address
|
65
|
+
def create_post(opts = {})
|
66
|
+
opts[:api_key] ||= Disqus::defaults[:api_key]
|
67
|
+
JSON.parse(post('create_post',
|
68
|
+
:forum_api_key => opts[:forum_api_key],
|
69
|
+
:thread_id => opts[:thread_id],
|
70
|
+
:message => opts[:message],
|
71
|
+
:author_name => opts[:author_name],
|
72
|
+
:author_email => opts[:author_email],
|
73
|
+
:parent_post => opts[:parent_post],
|
74
|
+
:created_at => opts[:created_at], #UTC timestring, format: %Y-%m-%dT%H:%M
|
75
|
+
:author_url => opts[:author_url],
|
76
|
+
:ip_address => opts[:ip_address])
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns an array of hashes representing all forums the user owns. The
|
81
|
+
# user is determined by the API key.
|
82
|
+
#
|
83
|
+
# Options:
|
84
|
+
#
|
85
|
+
# * <tt>:api_key</tt> - The User's API key (defaults to
|
86
|
+
# Disqus::defaults[:api_key])
|
87
|
+
def get_forum_list(opts = {})
|
88
|
+
opts[:api_key] ||= Disqus::defaults[:api_key]
|
89
|
+
JSON.parse(get('get_forum_list', :user_api_key => opts[:api_key]))
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns A string which is the Forum Key for the given forum.
|
93
|
+
#
|
94
|
+
# Required options hash elements:
|
95
|
+
#
|
96
|
+
# * <tt>:forum_id</tt> - the unique id of the forum
|
97
|
+
#
|
98
|
+
# Optional:
|
99
|
+
#
|
100
|
+
# * <tt>:api_key</tt> - The User's API key (defaults to Disqus::defaults[:api_key])
|
101
|
+
def get_forum_api_key(opts = {})
|
102
|
+
opts[:api_key] ||= Disqus::defaults[:api_key]
|
103
|
+
JSON.parse(get('get_forum_api_key', :user_api_key => opts[:api_key], :forum_id => opts[:forum_id]))
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns: An array of hashes representing all threads belonging to the
|
107
|
+
# given forum.
|
108
|
+
#
|
109
|
+
# Required options hash elements:
|
110
|
+
#
|
111
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
112
|
+
# * <tt>:forum_id</tt> - the unique id of the forum
|
113
|
+
def get_thread_list(opts = {})
|
114
|
+
JSON.parse(get('get_thread_list', :forum_id => opts[:forum_id], :forum_api_key => opts[:forum_api_key]))
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns a hash having thread_ids as keys and 2-element arrays as
|
118
|
+
# values.
|
119
|
+
#
|
120
|
+
# The first array element is the number of visible comments on on the
|
121
|
+
# thread; this would be useful for showing users of the site (e.g., "5
|
122
|
+
# Comments").
|
123
|
+
#
|
124
|
+
# The second array element is the total number of comments on the
|
125
|
+
# thread.
|
126
|
+
#
|
127
|
+
# These numbers are different because some forums require moderator
|
128
|
+
# approval, some messages are flagged as spam, etc.
|
129
|
+
#
|
130
|
+
# Required options hash elements:
|
131
|
+
#
|
132
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
133
|
+
# * <tt>:thread_ids</tt> - an array of thread IDs belonging to the given forum.
|
134
|
+
def get_num_posts(opts = {})
|
135
|
+
opts[:api_key] ||= Disqus::defaults[:api_key]
|
136
|
+
JSON.parse(get('get_num_posts', :thread_ids => opts[:thread_ids].join(","), :forum_api_key => opts[:forum_api_key]))
|
137
|
+
end
|
138
|
+
|
139
|
+
# Returns a hash representing a thread if one was found, otherwise null.
|
140
|
+
#
|
141
|
+
# It only finds threads associated with the given forum.
|
142
|
+
#
|
143
|
+
# Note that there is no one-to-one mapping between threads and URL's; a
|
144
|
+
# thread will only have an associated URL if it was automatically
|
145
|
+
# created by Disqus javascript embedded on that page. Therefore, we
|
146
|
+
# recommend using thread_by_identifier whenever possible. This method is
|
147
|
+
# provided mainly for handling comments from before your forum was using
|
148
|
+
# the API.
|
149
|
+
#
|
150
|
+
# Required options hash elements:
|
151
|
+
#
|
152
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
153
|
+
# * <tt>:url</tt> - the URL to check for an associated thread
|
154
|
+
def get_thread_by_url(opts = {})
|
155
|
+
JSON.parse(get('get_thread_by_url', :url => opts[:url], :forum_api_key => opts[:forum_api_key]))
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns an array of hashes representing representing all posts
|
159
|
+
# belonging to the given forum.
|
160
|
+
#
|
161
|
+
# Required options hash elements:
|
162
|
+
#
|
163
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
164
|
+
# * <tt>:thread_id</tt> - the ID of a thread belonging to the given forum
|
165
|
+
def get_thread_posts(opts = {})
|
166
|
+
JSON.parse(get('get_thread_posts', :thread_id => opts[:thread_id], :forum_api_key => opts[:forum_api_key]))
|
167
|
+
end
|
168
|
+
|
169
|
+
# Create or retrieve a thread by an arbitrary identifying string of your
|
170
|
+
# choice. For example, you could use your local database's ID for the
|
171
|
+
# thread. This method allows you to decouple thread identifiers from the
|
172
|
+
# URL's on which they might be appear. (Disqus would normally use a
|
173
|
+
# thread's URL to identify it, which is problematic when URL's do not
|
174
|
+
# uniquely identify a resource.) If no thread exists for the given
|
175
|
+
# identifier yet (paired with the forum), one will be created.
|
176
|
+
#
|
177
|
+
# Returns a hash with two keys:
|
178
|
+
#
|
179
|
+
# * "thread", which is a hash representing the thread corresponding to the identifier; and
|
180
|
+
# * "created", which indicates whether the thread was created as a result of this method call. If created, it will have the specified title.
|
181
|
+
#
|
182
|
+
# Required options hash elements:
|
183
|
+
#
|
184
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
185
|
+
# * <tt>:title</tt> - the title of the thread to possibly be created
|
186
|
+
# * <tt>:identifier</tt> - a string of your choosing
|
187
|
+
def thread_by_identifier(opts = {})
|
188
|
+
JSON.parse(post('thread_by_identifier', :forum_api_key => opts[:forum_api_key],
|
189
|
+
:identifier => opts[:identifier],
|
190
|
+
:title => opts[:title] ))
|
191
|
+
end
|
192
|
+
|
193
|
+
# Sets the provided values on the thread object.
|
194
|
+
#
|
195
|
+
# Returns an empty success message.
|
196
|
+
#
|
197
|
+
# Required options hash elements:
|
198
|
+
#
|
199
|
+
# * <tt>:forum_api_key</tt> - the API key for the forum
|
200
|
+
# * <tt>:thread_id</tt> - the ID of a thread belonging to the given forum
|
201
|
+
#
|
202
|
+
# Optional:
|
203
|
+
#
|
204
|
+
# * <tt>:title</tt> - the title of the thread
|
205
|
+
# * <tt>:slug</tt> - 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.
|
206
|
+
# * <tt>:url</tt> - the URL this thread is on, if known.
|
207
|
+
# * <tt>:allow_comment</tt> - whether this thread is open to new comments
|
208
|
+
def update_thread(opts = {})
|
209
|
+
raise opts.inspect
|
210
|
+
JSON.parse(post('update_thread',
|
211
|
+
:forum_api_key => opts[:forum_api_key],
|
212
|
+
:thread_id => opts[:thread_id],
|
213
|
+
:title => opts[:title],
|
214
|
+
:slug => opts[:slug],
|
215
|
+
:url => opts[:url],
|
216
|
+
:allow_comments => opts[:allow_comments])
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Widget to includes a comment form suitable for use with the Disqus
|
221
|
+
# API. This is different from the other widgets in that you can specify
|
222
|
+
# the thread identifier being commented on.
|
223
|
+
def comment_form(forum_shortname, thread_identifier)
|
224
|
+
url = 'http://disqus.com/api/reply.js?' +
|
225
|
+
"forum_shortname=#{escape(forum_shortname)}&" +
|
226
|
+
"thread_identifier=#{escape(thread_identifier)}"
|
227
|
+
s = '<div id="dsq-reply">'
|
228
|
+
s << '<script type="text/javascript" src="%s"></script>' % url
|
229
|
+
s << '</div>'
|
230
|
+
return s
|
231
|
+
end
|
232
|
+
|
233
|
+
private
|
234
|
+
|
235
|
+
def escape(string)
|
236
|
+
URI::encode(string, /[^a-z0-9]/i)
|
237
|
+
end
|
238
|
+
|
239
|
+
def get(*args)
|
240
|
+
open(make_url(*args)) {|u| u.read }
|
241
|
+
end
|
242
|
+
|
243
|
+
def post(*args)
|
244
|
+
url = ROOT + '/' + args.shift
|
245
|
+
post_params = {}
|
246
|
+
args.shift.each { |k, v| post_params[k.to_s]=v.to_s }
|
247
|
+
Net::HTTP.post_form(URI.parse(url),post_params)
|
248
|
+
end
|
249
|
+
|
250
|
+
def make_url(*args)
|
251
|
+
url = ROOT + '/' + args.shift + '/?'
|
252
|
+
args.shift.each { |k, v| url += "#{k}=#{escape(v.to_s)}&" }
|
253
|
+
return url.chomp('&')
|
254
|
+
end
|
255
|
+
|
256
|
+
def validate_opts!(opts)
|
257
|
+
raise ArgumentError.new("You must specify an :api_key") if !opts[:api_key]
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|