Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created September 20, 2010 05:17
Show Gist options
  • Save marshluca/587453 to your computer and use it in GitHub Desktop.
Save marshluca/587453 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/http'
require 'digest/md5'
require 'json'
API_KEY = "679826437258ff2c66d19e28a96c55fa"
SECRET_KEY = "830f73caf91179b68106fa5bcf0de4ce"
SESSION_KEY = "23536043_100001974_23536043_1284951867_701ca12bcf155352212387aec74c99e6"
API_SERVER = "http://rest.kaixin001.com/api/rest.php"
class Kaixin
BASE_PARAMS = {
"api_key" => API_KEY,
"session_key" => SESSION_KEY,
"v" => "1.0"
}
def initialize(options = {})
@params = BASE_PARAMS.merge(options).merge(:call_id => Time.now.to_f.to_s)
end
def signature
p = @params.to_a.collect {|i| "#{i.first}=#{i.last}"}
str = p.sort.join("").concat(SECRET_KEY)
Digest::MD5.hexdigest(str)
end
def post
uri = URI.parse(API_SERVER)
params = @params.merge(:sig => signature)
response = Net::HTTP.post_form(uri, params)
JSON.parse(response.body)
end
end
puts Kaixin.new({:method => "users.getLoggedInUser", :format => "json"}).post.inspect
puts Kaixin.new({:method => "users.getInfo", :uids => "100099,100100"}).post.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment