Module: Douban::OAuth

Defined in:
lib/douban_api/oauth.rb

Overview

Defines HTTP request methods

Instance Method Summary collapse

Instance Method Details

#authorize_url(options = {}) ⇒ Object

Return URL for OAuth authorization



6
7
8
9
10
# File 'lib/douban_api/oauth.rb', line 6

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

#get_access_token(code, options = {}) ⇒ Object

Return an access token from authorization



13
14
15
16
17
18
19
# File 'lib/douban_api/oauth.rb', line 13

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

#refresh(options = {}) ⇒ Object

Note:

返回新的access_token和refresh_token的同时, 它修改client的access_token和refresh_token

Refresh you access token, see OAuth2 spec for more infomation



24
25
26
27
28
29
30
31
32
33
# File 'lib/douban_api/oauth.rb', line 24

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

  response
end