How to use the Disqus API with Ruby
Ruby posted almost 2 years ago by christian
1 require 'httparty' 2 3 # See http://disqus.com/api/docs/ 4 module Disqus 5 class Base 6 include HTTParty 7 format :json 8 base_uri 'http://disqus.com/api/3.0' 9 debug_output $stderr 10 end 11 12 class Forum < Base 13 # http://disqus.com/api/docs/forums/create/ 14 def create(options) 15 url = "/forums/create.json" 16 self.class.post(url, :body => options.merge({ :api_secret => API_SECRET })) 17 end 18 19 def posts(id) 20 url = "/forums/listPosts.json?api_secret=#{API_SECRET}&forum=#{id}" 21 self.class.get(url) 22 end 23 24 def threads(id) 25 url = "http://disqus.com/api/3.0/threads/list.json?api_secret=#{API_SECRET}&forum=#{id}" 26 self.class.get(url) 27 end 28 end 29 30 class Post < Base 31 # http://disqus.com/api/docs/posts/create/ 32 def create(message) 33 url = "/posts/create.json" 34 self.class.post(url, :body => message.merge({ :api_secret => API_SECRET })) 35 end 36 end 37 end 38 39 # Secret key from http://disqus.com/api/applications/ 40 Disqus::API_SECRET = '...'
