class Contacts::Plaxo

Constants

ADDRESS_BOOK_URL
CONTACT_LIST_URL
LOGIN_URL
PROTOCOL_ERROR
URL

Public Instance Methods

contacts() click to toggle source
# File lib/contacts/plaxo.rb, line 15
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
real_connect() click to toggle source
# File lib/contacts/plaxo.rb, line 11
def real_connect
  
end

Private Instance Methods

parse(data, options={}) click to toggle source
# File lib/contacts/plaxo.rb, line 28
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