Skip to content

Instantly share code, notes, and snippets.

@ramon-sg
Last active December 3, 2018 22:01
Show Gist options
  • Save ramon-sg/5871254 to your computer and use it in GitHub Desktop.
Save ramon-sg/5871254 to your computer and use it in GitHub Desktop.
# config/initializers/omnicontacts.rb
Rails.application.middleware.use OmniContacts::Builder do
importer :live, 'client_id', 'client_secret', {redirect_path: "/invitations/live/contact_callback"}
end
class OmniContacts::Importer::Live < OmniContacts::Importer::Hotmail
def initialize *args
super *args
@auth_host = 'login.live.com' #"oauth.live.com"
@authorize_path = '/oauth20_authorize.srf' #"/authorize"
@scope = 'wl.basic, wl.contacts_emails' #"wl.signin, wl.basic, wl.birthday , wl.emails ,wl.contacts_birthday , wl.contacts_photos"
@auth_token_path = "/oauth20_token.srf"
@contacts_host = "apis.live.net"
@contacts_path = "/v5.0/me/contacts"
@self_path = "/v5.0/me"
end
def contacts_from_response response_as_json
response = JSON.parse(response_as_json)
contacts = []
response['data'].each do |entry|
# creating nil fields to keep the fields consistent across other networks
contact = {:id => nil, :first_name => nil, :last_name => nil, :name => nil, :email => nil, :gender => nil, :birthday => nil, :profile_picture=> nil, :relation => nil}
contact[:id] = entry['user_id'] ? entry['user_id'] : entry['id']
if valid_email? entry["emails"]["preferred"]
contact[:email] = entry["emails"]["preferred"]
contact[:first_name], contact[:last_name] = email_to_name(contact[:email])
else
contact[:first_name] = normalize_name(entry['first_name'])
contact[:last_name] = normalize_name(entry['last_name'])
end
contact[:name] = normalize_name(entry['name'])
contact[:birthday] = birthday_format(entry['birth_month'], entry['birth_day'], entry['birth_year'])
contact[:gender] = entry['gender']
contact[:profile_picture] = 'https://apis.live.net/v5.0/' + entry['user_id'] + '/picture' if entry['user_id']
contacts << contact if contact[:name] || contact[:first_name]
end
contacts
end
end
@SergeiStruk
Copy link

thanks, it helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment