Class: Oauth::Weibo
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Provider
#expired?, #fetch_info!, request, type
Class Method Details
.authenticate?(access_token, uid) ⇒ Boolean
33
34
35
36
37
38
39
40
|
# File 'lib/oauth/provider/weibo.rb', line 33
def self.authenticate?(access_token, uid)
result = postJSON('https://api.weibo.com/oauth2/get_token_info', {access_token: access_token})
if result.try(:[], 'uid').to_i == uid.to_i
uid.to_i > 0
else
false
end
end
|
.authorize_url ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/oauth/provider/weibo.rb', line 42
def authorize_url
get_params = {
'client_id' => Configure['weibo']['appid'],
'redirect_uri' => Configure['weibo']['callback'],
'response_type' => 'code',
'display' => 'default'
}
"https://api.weibo.com/oauth2/authorize?#{URI.encode_www_form(get_params)}";
end
|
.detail_of_code(code) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/oauth/provider/weibo.rb', line 52
def detail_of_code(code)
url = 'https://api.weibo.com/oauth2/access_token'
post_params = {
'client_id' => Configure['weibo']['appid'],
'client_secret' => Configure['weibo']['secret'],
'grant_type' => 'authorization_code',
'code' => code,
'redirect_uri' => Configure['weibo']['callback']
}
response = postJSON(url,post_params)
if response
response["created_at"] = Time.now
response.delete('remind_in')
end
response
end
|
Instance Method Details
#api_access(api, http_params, http_method = 'get') ⇒ Object
17
18
19
20
21
22
|
# File 'lib/oauth/provider/weibo.rb', line 17
def api_access(api, http_params, http_method = 'get')
return nil if expired?
url = 'https://api.weibo.com/2/' + api + '.json'
http_params.merge!({"access_token" => access_token})
Oauth::Weibo.request(url, http_params, http_method, 'json')
end
|
#fetch_info ⇒ Object
13
14
15
|
# File 'lib/oauth/provider/weibo.rb', line 13
def fetch_info
api_access('users/show',{'uid' => uid})
end
|
#follow(uid = nil) ⇒ Object
4
5
6
7
|
# File 'lib/oauth/provider/weibo.rb', line 4
def follow(uid = nil)
uid = Configure['weibo']['official'] if uid.nil?
api_access('friendships/create', {'uid'=> uid}, 'post')
end
|
#publish(content) ⇒ Object
9
10
11
|
# File 'lib/oauth/provider/weibo.rb', line 9
def publish(content)
api_access('statuses/update', {'status'=>content}, 'post')
end
|
#refresh ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/oauth/provider/weibo.rb', line 24
def refresh
info = Oauth::Weibo.postJSON('https://api.weibo.com/oauth2/get_token_info', {access_token: access_token})
if info
self.created_at = info["create_at"]
user.save!
end
end
|