Sha256: 2c3393946b92d37e9efb4fb32a6da38ef0d84fd42ebebefd86b2cd1d245e2752

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

# This is weibo2 client interface
# author alex_tian
require 'typhoeus'

module Weibo2Plugins
  # Weibo2Plugins::Base.get_call_back_url('2154274819','74e4428b7ed95bf47317ee31075ea802',"http://www.tianji.com/api/users/weibo_callback")
  class Base
    def initialize(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
    end
    
    def self.get_call_back_url call_back_url
      Base.new call_back_url
      client = Weibo2::Client.new
      client.auth_code.authorize_url(:response_type => "token")
    end
    
  end
  # Weibo2Plugins::Tools::Base.get_friend('1925715145','/friendships/friends.json','2.00hTG1GCDSHn2C64fbb3f2d30n2pHb')
  module Tools
    class Base
      HOST = "https://api.weibo.com/2"
      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
      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
weibo2_plugins-0.0.1 lib/weibo2_plugins/weibo2_plugins.rb