# This is weibo2 client interface # author alex_tian require 'typhoeus' module Weibo2Plugins class Base # Weibo2Plugins::Base.get_call_back_url('2154274819','74e4428b7ed95bf47317ee31075ea802',"http://www.tianji.com/api/users/weibo_callback") def self.get_call_back_url weibo_key,weibo_secret,call_back_url Weibo2::Config.api_key = weibo_key Weibo2::Config.api_secret = weibo_secret Weibo2::Config.redirect_uri = call_back_url client = Weibo2::Client.new client.auth_code.authorize_url(:response_type => "token") end end module Tools class Base HOST = "https://api.weibo.com/2" def self.get_date(url,access_token,params) atts = { headers: {"Content-Type" => "application/json","Accept"=>"application/json;charset=utf-8","User-Agent"=>"Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}, method: :get, timeout: 3000, :cache_timeout => 0, params: params } request = Typhoeus::Request.new("#{HOST}#{url}",atts) hydra = Typhoeus::Hydra.new hydra.queue(request) hydra.run result = $json.decode(request.response.body) end def self.post_date(url,access_token,params) atts = { headers: {"Content-Type" => "application/json","Accept"=>"application/json;charset=utf-8","User-Agent"=>"Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}, method: :post, timeout: 3000, :cache_timeout => 0, params: params } request = Typhoeus::Request.new("#{HOST}#{url}",atts) hydra = Typhoeus::Hydra.new hydra.queue(request) hydra.run result = $json.decode(request.response.body) end end class Api # Weibo2Plugins::Tools::Api.get_friend('1925715145','/friendships/friends.json','2.00hTG1GCDSHn2C64fbb3f2d30n2pHb') def self.get_friend(uid,url,access_token) params = {uid: uid, access_token: access_token, count: 200} atts = { headers: {"Content-Type" => "application/json","Accept"=>"application/json;charset=utf-8","User-Agent"=>"Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}, method: :get, timeout: 3000, :cache_timeout => 0, params: params } request = Typhoeus::Request.new("#{HOST}#{url}",atts) hydra = Typhoeus::Hydra.new hydra.queue(request) hydra.run result = $json.decode(request.response.body) end # Weibo2Plugins::Tools::Api.post_statuses('1925715145','/statuses/update.json','2.00hTG1GCDSHn2C64fbb3f2d30n2pHb','test') def self.post_statuses(uid,url,access_token,status) params = {uid: uid, access_token: access_token, status: URI.escape(status).to_json} atts = { headers: {"Content-Type" => "application/x-www-form-urlencoded","Accept"=>"application/json;charset=utf-8","User-Agent"=>"Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}, method: :post, timeout: 3000, cache_timeout: 0, params: params } request = Typhoeus::Request.new("#{HOST}#{url}",atts) hydra = Typhoeus::Hydra.new hydra.queue(request) hydra.run result = $json.decode(request.response.body) end end end end