Douban Ruby Client¶ ↑
github.com/lidaobing/douban-ruby
Description¶ ↑
douban ruby client. including OAuth support.
-
RDoc: rubydoc.info/github/lidaobing/douban-ruby/master/frames
-
Douban API reference: www.douban.com/service/apidoc/reference/
Installation¶ ↑
gem install douban-ruby
Usage¶ ↑
Basic Process¶ ↑
require 'douban' douban = Douban::Authorize.new(apikey, secret) puts "please open #{douban.get_authorize_url}" puts "after login, press Enter to continue" gets puts douban.get_people
Async Process (or Server Process)¶ ↑
class DoubanController < ApplicationController DOUBAN_APIKEY = '0fb6d0a851af01a12f2471f8f50d04e3' DOUBAN_SECRET = 'c59e3be2ccdde999' def index unless params[:oauth_token] unless session[:access_token] # step 1, initial state, store request_token to session callback_url = url_for :action => :index redirect_url = douban.get_authorize_url(callback_url) session[:request_token] = douban.request_token :as_hash redirect_to redirect_url else # step 3, have access_token, now you can use douban API douban.access_token = session[:access_token] render :text => douban.get_people.inspect end else if session[:request_token] # step 2, return from douban, store access_token to session douban.request_token = session[:request_token] douban.auth reset_session session[:access_token] = douban.access_token :as_hash redirect_to :action => :index else # error branch, you return from douban, but no request_token in session logger.info "return from oauth but no request_token" redirect_to :action => :index end end end private def douban @douban ||= Douban::Authorize.new DOUBAN_APIKEY, DOUBAN_SECRET end end
LICENSE:¶ ↑
licensed under Artistic License or GPL license.