Skip to content

Commit

Permalink
parse mail ru user info
Browse files Browse the repository at this point in the history
  • Loading branch information
lexer committed Apr 29, 2011
1 parent 89af23f commit 73bd71a
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions oa-oauth/lib/omniauth/strategies/mailru.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ module Strategies
# http://api.mail.ru/docs/guides/oauth/sites/
#
# @example Basic Usage
# use OmniAuth::Strategies::Mailr, 'API Key', 'Secret Key'
# use OmniAuth::Strategies::Mailru, 'API Key', 'Secret Key'
class Mailru < OAuth2
# @param [Rack Application] app standard middleware application parameter
# @param [String] api_key the application id as [registered in Mailru]
# @param [String] secret_key the application secret as [registered in Mailru]

# @param [String] private_key the application secret as [registered in Mailru]
def initialize(app, api_key = nil, secret_key = nil, private_key = nil, options = {}, &block)
client_options = {
:site => 'https://connect.mail.ru',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/token'
}

@private_key = private_key

#options[:scope] ||= "widget"
@private_key = private_key

super(app, :mailru, api_key, secret_key, client_options, options, &block)
end
Expand Down Expand Up @@ -54,16 +52,54 @@ def user_data
@data ||= MultiJson.decode(client.request(:get, 'http://www.appsmail.ru/platform/api', request_params))[0]
end

#"uid": "15410773191172635989",
#"first_name": "Евгений",
#"last_name": "Маслов",
#"nick": "maslov",
#"sex": 0,
#"birthday": "15.02.1980",
#"has_pic": 1,
#"pic": "http://avt.appsmail.ru/mail/emaslov/_avatar",
#"pic_small": "http://avt.appsmail.ru/mail/emaslov/_avatarsmall",
#"pic_big": "http://avt.appsmail.ru/mail/emaslov/_avatarbig",
#"link": "http://my.mail.ru/mail/emaslov/",
#"referer_type": "",
#"referer_id": "",
#"is_online": 1,
#"vip" : 1,
#"location": {
# "country": {
# "name": "Россия",
# "id": "24"
# },
# "city": {
# "name": "Москва",
# "id": "25"
# },
# "region": {
# "name": "Москва",
# "id": "999999"
# }
#}

def user_info
{
'email' => user_data['email']
'nickname' => user_data['nick'],
'email' => user_data['email'],
'first_name' => user_data["first_name"],
'last_name' => user_data["last_name"],
'name' => "#{user_data['first_name']} #{user_data['last_name']}",
'location' => "#{@data['location']['country']['name']}, #{@data['location']['region']['name']}, #{@data['location']['city']['name']}",
'image' => @data['pic'],
'urls' => {
'Mailru' => user_data["link"]
}
}
end

def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => user_data['id'],
'uid' => user_data['uid'],
'user_info' => user_info,
'extra' => {'user_hash' => user_data}
})
Expand Down

0 comments on commit 73bd71a

Please sign in to comment.