Class: OauthChina::Douban

Inherits:
OAuth
  • Object
show all
Defined in:
lib/oauth_china/strategies/douban.rb

Constant Summary

Constants inherited from OAuth

OAuth::CONFIG

Instance Attribute Summary

Attributes inherited from OAuth

#access_token, #consumer_options, #request_token

Instance Method Summary collapse

Methods inherited from OAuth

#authorize, #authorize_url, #callback, #config, #consumer, #dump, #key, load, #oauth_token, #secret, #url

Methods included from Upload

#params_without_pic_field, #set_multipart_field, #sign_without_pic_field, #upload

Constructor Details

#initialize(*args) ⇒ Douban

Returns a new instance of Douban.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/oauth_china/strategies/douban.rb', line 4

def initialize(*args)
  #豆瓣只支持header方式呀!
  self.consumer_options = {
    :signature_method   => "HMAC-SHA1",
    :site               => "http://www.douban.com",
    :scheme             => :header,
    :request_token_path => '/service/auth/request_token',
    :access_token_path  => '/service/auth/access_token',
    :authorize_path     => '/service/auth/authorize',
    :realm              => url
  }
  super(*args)
end

Instance Method Details

#add_status(content, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/oauth_china/strategies/douban.rb', line 33

def add_status(content, options = {})
  self.post("http://api.douban.com/miniblog/saying", <<-XML, {"Content-Type" =>  "application/atom+xml"})
    <?xml version='1.0' encoding='UTF-8'?>
    <entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/">
    <content>#{content}</content>
    </entry>
    XML
end

#authorized?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/oauth_china/strategies/douban.rb', line 22

def authorized?
  return false if access_token.nil?
  response = self.get("/access_token/#{access_token.token}")
  response.code == '200'
end

#destroyObject



28
29
30
31
# File 'lib/oauth_china/strategies/douban.rb', line 28

def destroy
  destroy_access_key if !access_token.nil?
  request_token = access_token = nil
end

#nameObject



18
19
20
# File 'lib/oauth_china/strategies/douban.rb', line 18

def name
  :douban
end

#upload_image(content, image_path, options = {}) ⇒ Object

TODO



43
44
45
# File 'lib/oauth_china/strategies/douban.rb', line 43

def upload_image(content, image_path, options = {})
  add_status(content, options)
end