Collecting Contacts using cardmagic-contacts plug-in in Rails 2.3.8 by Jay December 18, 2012 2 Minutes Read cardmagic-contacts is a rails plug-in which provides an interface to fetch contact list information from various email providers including Hotmail, AOL, Gmail, Plaxo, Yahoo and many more. This example narrates how to extract contact list using Rails 2.3.8 and cardmagic-contacts plug-in Step#1 Download the plug-in by running the command below to store the plug-in in the folder “vendor/plug-ins” Windows ruby script/plugin install git://github.com/cardmagic/contacts Linux ruby script/plugin http://github.com/cardmagic/contacts Step#2 Write down the following code on the top of the controller class require 'contacts' Step#3 Pass the required gmail/yahoo/hotmail/AOL login & password from view <div> <div style="margin-left:25px;" >Invite <img src="../images/yahoo.JPG">Yahoo Friends </div> <div style="margin-left:25px;">Yahoo Email: <input type="text" name="email" id="yahoo_email_id"></div> <div style="margin-left:25px;">Password: <input type="password" name="email" id="yahoo_pwd_id"></div> <div style="margin-left:122px;margin-top:20px;"><input type="button" value="Login" name="btn_submit" id="btn_submit" ></div> </div> Step#4 Create an action to fetch the list of contacts for a specific email id def grab_contacts #Grab gmail contacts @gmail_contacts=Contacts::Gmail.new(login, password).contacts #or @gmail_contacts=Contacts.new(:gmail, login, password).contacts #Grab yahoo contacts @yahoo_contacts = Contacts::Yahoo.new(login, password).contacts #or @yahoo_contacts = Contacts.new(:yahoo, login, password).contacts #Grab hotmail contacts @hotmail_contacts =Contacts::Hotmail.new(login, password).contacts #or @hotmail_contacts = Contacts.new(:hotmail, login, password).contacts end Step#5 Here is also alternate method to get the contacts by providing email_id and password any_mail = Contacts.guess(login, password).contacts The “Contacts.guess” method will automatically concatenate the entire address book from each of the successful logins. If the login and password is working with multiple email accounts then it will grab the contacts from all accounts. Step#6 Display the friends list in your view page <table> <th> <td >Friends Name</td> <td >Friends Email</td> </th> <tr> <% @gmail_contacts.each do |contact| %> <td><%=contact%></td> <td><%=contact%></td> <% end %> </tr> </table> Related Posts: WakeUpSales CRM Suite: Powered by Ruby on Rails Why Choose Ruby on Rails for your Web App How to do tagging in Rails with gem ‘Acts_as_taggable_on’ Tags: Rails App, RoR Jayadev Das firstname.lastname@example.org Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘bout Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!