require 'rexml/document' class Contacts class Plaxo < Base URL = "http://www.plaxo.com/" LOGIN_URL = "https://www.plaxo.com/signin" ADDRESS_BOOK_URL = "http://www.plaxo.com/po3/?module=ab&operation=viewFull&mode=normal" CONTACT_LIST_URL = "http://www.plaxo.com/axis/soap/contact?_action=getContacts&_format=xml" PROTOCOL_ERROR = "Plaxo has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts" def real_connect end # real_connect def contacts getdata = "&authInfo.authByEmail.email=%s" % CGI.escape(login) getdata += "&authInfo.authByEmail.password=%s" % CGI.escape(password) data, resp, cookies, forward = get(CONTACT_LIST_URL + getdata) if resp.code_type != Net::HTTPOK raise ConnectionError, PROTOCOL_ERROR end parse data end # contacts private def parse(data, options={}) doc = REXML::Document.new(data) code = doc.elements['//response/code'].text if code == '401' raise AuthenticationError, "Username and password do not match" elsif code == '200' @contacts = [] doc.elements.each('//contact') do |cont| name = if cont.elements['fullName'] cont.elements['fullName'].text elsif cont.elements['displayName'] cont.elements['displayName'].text end email = if cont.elements['email1'] cont.elements['email1'].text end if name || email @contacts << [name, email] end end @contacts else raise ConnectionError, PROTOCOL_ERROR end end # parse end # Plaxo TYPES[:plaxo] = Plaxo end # Contacts # sample contacts responses =begin Bad email ========= 401 1 User not found. Bad password ============ 401 4 Bad password or security token. Success ======= 200 OK 77311236242 61312569 Joe Blow1 Joe Blow1 Joe Blow1 joeblow1@mailinator.com joeblow1@mailinator.com 5291351 61313159 Joe Blow2 Joe Blow2 Joe Blow2 joeblow2@mailinator.com joeblow2@mailinator.com 5291351 2 3 =end