Created
May 23, 2011 18:06
-
-
Save gumayunov/987186 to your computer and use it in GitHub Desktop.
This file contains 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
module SocialConnect | |
module Providers | |
class Vkontakte < Base | |
config_readers :app_id, :app_secret | |
config_readers :group_id | |
js_config :app_id, :group_id | |
cookie_key do | |
"vk_app_#{app_id}" | |
end | |
uid_key :vk_id | |
session_uid_key :mid | |
human_name "ВКонтакте" | |
def guess_user | |
posible_record = User.find_by_vk_id(uid) | |
logger.info "found by vk_id: #{uid}" if posible_record | |
posible_record | |
end | |
private | |
def fetch_attributes | |
params = { | |
:api_id => app_id, | |
:v => "3.0", | |
:method => "getProfiles", | |
:format => "json", | |
:fields => "photo,sex,city,country", | |
#:fields => CGI.escape("photo,sex,city,country"), | |
:uids => uid | |
} | |
params[:sig] = calc_signature(params) | |
http = Net::HTTP.new("api.vkontakte.ru"); | |
path = "/api.php?" + params.to_query | |
resp, data = http.get(path, nil) | |
data = data ? JSON.parse(data).with_indifferent_access : {} | |
# TODO: error handling | |
if data[:response] | |
data[:response].first.with_indifferent_access.merge( uid_key => uid ) | |
else | |
{} | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment