Skip to content

Instantly share code, notes, and snippets.

@prepor
Created January 24, 2010 01:57
Show Gist options
  • Save prepor/284953 to your computer and use it in GitHub Desktop.
Save prepor/284953 to your computer and use it in GitHub Desktop.
Little wrapper for vkonrakte.ru secure API.
# VKRequest.get :method => 'secure.getAppBalance'
require 'digest/md5'
require 'open-uri'
class VKRequest
SECURE_SECRET = 'ololo'
API_ID = 1807324
API_SERVER = 'http://api.vkontakte.ru/api.php'
DEFAULT_FORMAT = 'json'
VERSION = '2.0'
def self.get(options = {})
options = { :api_id => API_ID, :random => rand(1000000), :timestamp => Time.now.to_i, :format => DEFAULT_FORMAT, :v => VERSION }.merge(options)
options[:sig] = Digest::MD5.hexdigest(options.keys.map{ |k| k.to_s }.sort.map { |k| "#{k}=#{options[k.to_sym]}" } * '' + SECURE_SECRET)
url = API_SERVER + '?' + options.map { |k, v| "#{k}=#{v}" } * '&'
puts url
open(url).read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment