0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Douban API reference: http://www.douban.com/service/apidoc/reference/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 0
>= 0
~> 2.0

Runtime

>= 0
 Project Readme

Douban Ruby Client¶ ↑

github.com/lidaobing/douban-ruby

Description¶ ↑

douban ruby client. including OAuth support.

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.