Sha256: 69697c040ed38b6d63253b75a929809a64f297e855db2bc9ffd9a52e3108e06a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Douban
  # Defines HTTP request methods
  module OAuth
    # Return URL for OAuth authorization
    def authorize_url(options={})
      options[:response_type] ||= "code"
      params = access_token_params.merge(options)
      connection.build_url("https://www.douban.com/service/auth2/auth", params).to_s
    end

    # Return an access token from authorization
    def get_access_token(code, options={})
      options[:grant_type] ||= "authorization_code"
      params = access_token_params.merge(options)
      post("https://www.douban.com/service/auth2/token", params.merge(:code => code), raw=false)
    end

    def refresh(options={})
      options[:grant_type] ||= "refresh_token"
      params = access_token_params.merge(options)
      post("https://www.douban.com/service/auth2/token",
            params.merge(:refresh_token => refresh_token),
            raw=false)
    end
    
    private

    def access_token_params
      {
        :client_id => client_id,
        :client_secret => client_secret
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
douban_api-0.1.2 lib/douban_api/oauth.rb