Created
September 17, 2010 07:03
-
-
Save marshluca/583849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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