def import
begin
@sites = {"gmail" => Contacts::Gmail, "yahoo" => Contacts::Yahoo, "hotmail" => Contacts::Hotmail}
@contacts = @sites[params[:from]].new(params[:login], params[:password]).contacts
@users , @no_users = [], []
@contacts.each do |contact|
if u = User.find(:first , :conditions => "accounts.email = '#{contact[1]}'" , :include =>[:account])
@users << u
else
@no_users << {:name => contact[0] , :email => contact[1]}
end
end
respond_to do |format|
format.html {render :template => 'shared/_contact_list' , :layout => false}
format.xml {render :xml => @contacts.to_xml}
end
end
rescue Contacts::AuthenticationError
respond_to do |format|
format.html {render :text => "Username and password do not match"}
format.xml {head :bad_request , :bad_account_login}
end
end