Method: Contacts::Aol#contacts

Defined in:
lib/contacts/aol.rb

#contactsObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/contacts/aol.rb', line 98

def contacts
  postdata = {
    "file" => 'contacts',
    "fileType" => 'csv'
  }
 
  return @contacts if @contacts
  if connected?
    data, resp, cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]
 
    until forward.nil?
      data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
    end
    
    if resp.code_type != Net::HTTPOK
      raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
    end
 
    # parse data and grab <input name="user" value="8QzMPIAKs2" type="hidden">
    doc = Hpricot(data)
    (doc/:input).each do |input|
      postdata["user"] = input.attributes["value"] if input.attributes["name"] == "user"
    end
    
    data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]
 
    until forward.nil?
      data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
    end
    
    if data.include?("error.gif")
      raise AuthenticationError, "Account invalid"
    end
    
    parse data
  end
end