class Oauth::Weibo
Public Class Methods
authenticate?(access_token, uid)
click to toggle source
# File lib/oauth/provider/weibo.rb, line 42 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
detail_of_code(code)
click to toggle source
# File lib/oauth/provider/weibo.rb, line 61 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.select!{|k, v| %w{access_token uid expires_in}.include?(k)} end response end
Public Instance Methods
api_access(api, http_params, http_method = 'get')
click to toggle source
# File lib/oauth/provider/weibo.rb, line 26 def api_access(api, http_params, http_method = 'get') return nil if expired? # 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
basic_info()
click to toggle source
# File lib/oauth/provider/weibo.rb, line 16 def basic_info info && { "name" => info.data["name"], "avatar" => info.data["avatar_hd"] || info.data["avatar_large"], "gender" => info.data["gender"], "location" => info.data["location"], "description" => info.data["description"] } end
fetch_info()
click to toggle source
# File lib/oauth/provider/weibo.rb, line 12 def fetch_info api_access('users/show',{'uid' => uid}) end
follow(uid)
click to toggle source
# File lib/oauth/provider/weibo.rb, line 4 def follow(uid) api_access('friendships/create', {'uid' => uid}, 'post') end
publish(content)
click to toggle source
# File lib/oauth/provider/weibo.rb, line 8 def publish(content) api_access('statuses/update', {'status'=>content}, 'post') end
refresh()
click to toggle source
# File lib/oauth/provider/weibo.rb, line 33 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