Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created September 17, 2010 07:03
Show Gist options
  • Select an option

  • Save marshluca/583849 to your computer and use it in GitHub Desktop.

Select an option

Save marshluca/583849 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'httparty'
APP_KEY = "48578869"
class Sina
include HTTParty
base_uri "api.t.sina.com.cn"
default_params :source => APP_KEY
def initialize(params)
params["format"] ||= "xml"
@params = params
self.class.basic_auth(params["username"],params["password"])
end
def get(url)
url += @params["format"]
self.class.get(url, :query => @params)
end
def post(url)
url += @params["format"]
self.class.post(url, :query => @params)
end
def build_path
"/" + @params["method"].gsub(".","/") + "."
end
def result
case @params["request"]
when "get"
get(build_path)
when "post"
post(build_path)
else
get(build_path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment