Class: OauthChina::Netease

Inherits:
OAuth
  • Object
show all
Defined in:
lib/oauth_china/strategies/netease.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) ⇒ Netease

Returns a new instance of Netease.



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

def initialize(*args)
  #fuck 163
  #这个authorize path不是authorize,是authenticate呀!!!真变态!
  self.consumer_options = {
    :site               => 'http://api.t.163.com',
    :request_token_path => '/oauth/request_token',
    :access_token_path  => '/oauth/access_token',
    :authorize_path     => '/oauth/authenticate',
    :realm              => url
  }
  super(*args)
end

Instance Method Details

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



29
30
31
32
# File 'lib/oauth_china/strategies/netease.rb', line 29

def add_status(content, options = {})
  options.merge!(:status => content)
  self.post("http://api.t.163.com/statuses/update.json", options)
end

#authorized?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/oauth_china/strategies/netease.rb', line 21

def authorized?
  #TODO
end

#destroyObject



25
26
27
# File 'lib/oauth_china/strategies/netease.rb', line 25

def destroy
  #TODO
end

#nameObject



17
18
19
# File 'lib/oauth_china/strategies/netease.rb', line 17

def name
  :netease
end

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

网易微博发送带图片的微博需要两个步骤: 1.利用上传图片接口上传图片,并取得返回的image url 2.把取来的image url放到微博的内容中,利用发微博接口发送微博。 3.注意:如果把站外图片链接放到微博里发送不会在web页面中显示



38
39
40
41
42
# File 'lib/oauth_china/strategies/netease.rb', line 38

def upload_image(content, image_path, options = {})
  options = options.merge!(:pic => File.open(image_path, "rb")).to_options
  image_url = parse_image_url(just_upload_image(image_path))
  add_status("#{image_url} #{content}", options)
end