Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Zeke Sikelianos

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Sample Controller method for using Nico's Contacts gem

  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 
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS