[
  {
    "path": ".gitignore",
    "content": ".DS_Store\npkg/*\ntest/accounts.yml\nnbproject/\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: ruby\nrvm:\n  - 1.9.3\n  - 1.9.2\n  - jruby-18mode\n  - jruby-19mode\n  - rbx-18mode\n  - rbx-19mode\n  - ruby-head\n  - jruby-head\n  - 1.8.7\n  - ree\n\n"
  },
  {
    "path": "Gemfile",
    "content": "source 'https://rubygems.org'\ngem 'json', \">= 1.1.1\"\ngem 'gdata_19', '1.1.5'\ngem 'rspec', :require => 'spec'\ngem 'rake'\ngem 'hpricot'\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2006, Lucas Carlson, MOG\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\nNeither the name of the Lucas Carlson nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n"
  },
  {
    "path": "README.md",
    "content": "Welcome to Contacts\n===================\n\nContacts is a universal interface to grab contact list information from various providers including Hotmail, AOL, Gmail, Plaxo and Yahoo.\n\nDownload\n--------\n\n* gem install contacts\n* http://github.com/cardmagic/contacts\n* git clone git://github.com/cardmagic/contacts.git\n\nBackground\n----------\n\nFor a long time, the only way to get a list of contacts from your free online email accounts was with proprietary PHP scripts that would cost you $50. The act of grabbing that list is a simple matter of screen scrapping and this library gives you all the functionality you need. Thanks to the generosity of the highly popular Rails website MOG (http://mog.com) for allowing this library to be released open-source to the world. It is easy to extend this library to add new free email providers, so please contact the author if you would like to help.\n\nUsage\n-----\n\n<pre>\n <code>\n   Contacts::Hotmail.new(login, password).contacts # => [[\"name\", \"foo@bar.com\"], [\"another name\", \"bow@wow.com\"]]\n   Contacts::Yahoo.new(login, password).contacts\n   Contacts::Gmail.new(login, password).contacts\n   Contacts.new(:gmail, login, password).contacts\n   Contacts.new(:hotmail, login, password).contacts\n   Contacts.new(:yahoo, login, password).contacts\n   Contacts.guess(login, password).contacts\n </code>\n</pre>\n\nNotice there are three ways to use this library so that you can limit the use as much as you would like in your particular application. The Contacts.guess method will automatically concatenate all the address book contacts from each of the successful logins in the case that a username password works across multiple services.\n\nCaptcha error\n-------------\n\nIf there are too many failed attempts with the gmail login info, Google will raise a captcha response. To integrate the captcha handling, pass in the token and response via:\n<pre><code>\n  Contacts::Gmail.new(login, password, :captcha_token => params[:captcha_token], :captcha_response => params[:captcha_response]).contacts\n</code></pre>\n\nExamples\n--------\n\nSee the examples/ directory.\n\nAuthors\n-------\n\n> Lucas Carlson from MOG (mailto:lucas@rufy.com) - http://mog.com\n\nContributors\n------------\n\n* Britt Selvitelle from Twitter (mailto:anotherbritt@gmail.com) - http://twitter.com\n* Tony Targonski from GigPark (mailto:tony@gigpark.com) - http://gigpark.com\n* Waheed Barghouthi from Watwet (mailto:waheed.barghouthi@gmail.com) - http://watwet.com\n* Glenn Sidney from Glenn Fu (mailto:glenn@glennfu.com) - http://glennfu.com\n* Brian McQuay from Onomojo (mailto:brian@onomojo.com) - http://onomojo.com\n* Adam Hunter (mailto:adamhunter@me.com) - http://adamhunter.me/\n* Glenn Ford (mailto:glenn@glennfu.com) - http://www.glennfu.com/\n* Leonardo Wong (mailto:mac@boy.name)\n* Rusty Burchfield\n* justintv\n\nThis library is released under the terms of the BSD.\n\n"
  },
  {
    "path": "Rakefile",
    "content": "require 'rubygems'\nrequire 'bundler/setup'\nrequire 'rake'\nrequire 'rake/testtask'\nrequire 'rake/rdoctask'\nrequire 'rake/gempackagetask'\nrequire 'rake/contrib/rubyforgepublisher'\nrequire './lib/contacts'\n\nPKG_VERSION = Contacts::VERSION\n\nPKG_FILES = FileList[\n    \"lib/**/*\", \"bin/*\", \"test/**/*\", \"[A-Z]*\", \"Rakefile\", \"doc/**/*\", \"examples/**/*\"\n] - [\"test/accounts.yml\"]\n\ndesc \"Default Task\"\ntask :default => [ :test ]\n\n# Run the unit tests\ndesc \"Run all unit tests\"\nRake::TestTask.new(\"test\") { |t|\n  t.libs << \"lib\"\n  t.pattern = 'test/*/*_test.rb'\n  t.verbose = true\n}\n\n# Make a console, useful when working on tests\ndesc \"Generate a test console\"\ntask :console do\n   verbose( false ) { sh \"irb -I lib/ -r 'contacts'\" }\nend\n\n# Genereate the RDoc documentation\ndesc \"Create documentation\"\nRake::RDocTask.new(\"doc\") { |rdoc|\n  rdoc.title = \"Contact List - ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail\"\n  rdoc.rdoc_dir = 'doc'\n  rdoc.rdoc_files.include('README')\n  rdoc.rdoc_files.include('lib/**/*.rb')\n}\n\n# Genereate the package\nspec = Gem::Specification.new do |s|\n\n  #### Basic information.\n\n  s.name = 'adamhunter-contacts'\n  s.version = PKG_VERSION\n  s.summary = <<-EOF\n   Ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail\n  EOF\n  s.description = <<-EOF\n   Ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail\n  EOF\n\n  #### Which files are to be included in this gem?  Everything!  (Except CVS directories.)\n\n  s.files = PKG_FILES\n\n  #### Load-time details: library and application (you will need one or both).\n\n  s.require_path = 'lib'\n  s.autorequire = 'contacts'\n\n  s.add_dependency('json', '>= 0.4.1')\n  s.add_dependency('gdata', '= 1.1.1')\n  s.requirements << \"A json parser, the gdata ruby gem\"\n\n  #### Documentation and testing.\n\n  s.has_rdoc = true\n\n  #### Author and project details.\n\n  s.author = \"Lucas Carlson\"\n  s.email = \"lucas@rufy.com\"\n  s.homepage = \"http://rubyforge.org/projects/contacts\"\nend\n\nRake::GemPackageTask.new(spec) do |pkg|\n  pkg.need_zip = true\n  pkg.need_tar = true\nend\n\ndesc \"Report code statistics (KLOCs, etc) from the application\"\ntask :stats do\n  require 'code_statistics'\n  CodeStatistics.new(\n    [\"Library\", \"lib\"],\n    [\"Units\", \"test\"]\n  ).to_s\nend\n"
  },
  {
    "path": "contacts.gemspec",
    "content": "Gem::Specification.new do |s|\n  s.name = \"contacts\"\n  s.version = \"1.2.4\"\n  s.date = \"2010-07-06\"\n  s.summary = \"A universal interface to grab contact list information from various providers including Yahoo, AOL, Gmail, Hotmail, and Plaxo.\"\n  s.email = \"lucas@rufy.com\"\n  s.homepage = \"http://github.com/cardmagic/contacts\"\n  s.description = \"A universal interface to grab contact list information from various providers including Yahoo, AOL, Gmail, Hotmail, and Plaxo.\"\n  s.has_rdoc = false\n  s.authors = [\"Lucas Carlson\"]\n  s.files = [\"LICENSE\", \"Rakefile\", \"README\", \"examples/grab_contacts.rb\", \"lib/contacts.rb\", \"lib/contacts/base.rb\", \"lib/contacts/json_picker.rb\", \"lib/contacts/gmail.rb\", \"lib/contacts/aol.rb\", \"lib/contacts/hotmail.rb\", \"lib/contacts/plaxo.rb\", \"lib/contacts/yahoo.rb\"]\n  s.add_dependency(\"json\", \">= 1.1.1\")\n  s.add_dependency('gdata', '1.1.2')\nend\n"
  },
  {
    "path": "cruise_config.rb",
    "content": "# Project-specific configuration for CruiseControl.rb\n\nProject.configure do |project|\n\n  # Send email notifications about broken and fixed builds to email1@your.site, email2@your.site (default: send to nobody)\n  # if building this on your own CI box, please remove!\n   project.email_notifier.emails = ['opensource@pivotallabs.com']\n\n  # Set email 'from' field to john@doe.com:\n  # project.email_notifier.from = 'john@doe.com'\n\n  # Build the project by invoking rake task 'custom'\n  # project.rake_task = 'custom'\n\n  # Build the project by invoking shell script \"build_my_app.sh\". Keep in mind that when the script is invoked, current working directory is\n  # [cruise]/projects/your_project/work, so if you do not keep build_my_app.sh in version control, it should be '../build_my_app.sh' instead\n  # project.build_command = 'build_my_app.sh'\n\n  # Ping Subversion for new revisions every 5 minutes (default: 30 seconds)\n  # project.scheduler.polling_interval = 5.minutes\n\nend"
  },
  {
    "path": "examples/grab_contacts.rb",
    "content": "require File.dirname(__FILE__)+\"/../lib/contacts\"\n\nlogin = ARGV[0]\npassword = ARGV[1]\n\nContacts::Gmail.new(login, password).contacts\n\nContacts.new(:gmail, login, password).contacts\n\nContacts.new(\"gmail\", login, password).contacts\n\nContacts.guess(login, password).contacts"
  },
  {
    "path": "geminstaller.yml",
    "content": "---\ndefaults:\n  install_options: --no-ri --no-rdoc\ngems:\n  - name: json\n    version: >= 1.1.1\n  - name: gdata\n    version: >= 1.1.1\n"
  },
  {
    "path": "lib/contacts/aol.rb",
    "content": "class Contacts\n  require 'hpricot'\n  require 'csv'\n  class Aol < Base\n    URL                 = \"http://www.aol.com/\"\n    LOGIN_URL           = \"https://my.screenname.aol.com/_cqr/login/login.psp\"\n    LOGIN_REFERER_URL   = \"http://webmail.aol.com/\"\n    LOGIN_REFERER_PATH = \"sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=0&uitype=mini&loginId=&redirType=js&xchk=false\"\n    AOL_NUM = \"29970-343\" # this seems to change each time they change the protocol\n    \n    CONTACT_LIST_URL    = \"http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ContactList.aspx?folder=Inbox&showUserFolders=False\"\n    CONTACT_LIST_CSV_URL = \"http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ABExport.aspx?command=all\"\n    PROTOCOL_ERROR      = \"AOL 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\"\n    \n    def real_connect\n      if login.strip =~ /^(.+)@aol\\.com$/ # strip off the @aol.com for AOL logins\n        login = $1\n      end\n\n      postdata = {\n        \"loginId\" => login,\n        \"password\" => password,\n        \"rememberMe\" => \"on\",\n        \"_sns_fg_color_\" => \"\",\n        \"_sns_err_color_\" => \"\",\n        \"_sns_link_color_\" => \"\",\n        \"_sns_width_\" => \"\",\n        \"_sns_height_\" => \"\",\n        \"offerId\" => \"mail-second-en-us\",\n        \"_sns_bg_color_\" => \"\",\n        \"sitedomain\" => \"sns.webmail.aol.com\",\n        \"regPromoCode\" => \"\",\n        \"mcState\" => \"initialized\",\n        \"uitype\" => \"std\",\n        \"siteId\" => \"\",\n        \"lang\" => \"en\",\n        \"locale\" => \"us\",\n        \"authLev\" => \"0\",\n        \"siteState\" => \"\",\n        \"isSiteStateEncoded\" => \"false\",\n        \"use_aam\" => \"0\",\n        \"seamless\" => \"novl\",\n        \"aolsubmit\" => CGI.escape(\"Sign In\"),\n        \"idType\" => \"SN\",\n        \"usrd\" => \"\",\n        \"doSSL\" => \"\",\n        \"redirType\" => \"\",\n        \"xchk\" => \"false\"\n      }\n \n      # Get this cookie and stick it in the form to confirm to Aol that your cookies work\n      data, resp, cookies, forward = get(URL)\n      postdata[\"stips\"] = cookie_hash_from_string(cookies)[\"stips\"]\n      postdata[\"tst\"] = cookie_hash_from_string(cookies)[\"tst\"]\n \n      data, resp, cookies, forward, old_url = get(LOGIN_REFERER_URL, cookies) + [URL]\n      until forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n      \n      data, resp, cookies, forward, old_url = get(\"#{LOGIN_URL}?#{LOGIN_REFERER_PATH}\", cookies) + [LOGIN_REFERER_URL]\n      until forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n \n      doc = Hpricot(data)\n      (doc/:input).each do |input|\n        postdata[\"usrd\"] = input.attributes[\"value\"] if input.attributes[\"name\"] == \"usrd\"\n      end\n      # parse data for <input name=\"usrd\" value=\"2726212\" type=\"hidden\"> and add it to the postdata\n \n      postdata[\"SNS_SC\"] = cookie_hash_from_string(cookies)[\"SNS_SC\"]\n      postdata[\"SNS_LDC\"] = cookie_hash_from_string(cookies)[\"SNS_LDC\"]\n      postdata[\"LTState\"] = cookie_hash_from_string(cookies)[\"LTState\"]\n      # raise data.inspect\n      \n      data, resp, cookies, forward, old_url = post(LOGIN_URL, h_to_query_string(postdata), cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]\n      \n      until forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n      \n      if data.index(\"Invalid Username or Password. Please try again.\")\n        raise AuthenticationError, \"Username and password do not match\"\n      elsif data.index(\"Required field must not be blank\")\n        raise AuthenticationError, \"Login and password must not be blank\"\n      elsif data.index(\"errormsg_0_logincaptcha\")\n        raise AuthenticationError, \"Captcha error\"\n      elsif data.index(\"Invalid request\")\n        raise ConnectionError, PROTOCOL_ERROR\n      elsif cookies == \"\"\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n \n      @cookies = cookies\n    end\n \n    def contacts\n      postdata = {\n        \"file\" => 'contacts',\n        \"fileType\" => 'csv'\n      }\n \n      return @contacts if @contacts\n      if connected?\n        data, resp, cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]\n \n        until forward.nil?\n          data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n        end\n        \n        if resp.code_type != Net::HTTPOK\n          raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)\n        end\n \n        # parse data and grab <input name=\"user\" value=\"8QzMPIAKs2\" type=\"hidden\">\n        doc = Hpricot(data)\n        (doc/:input).each do |input|\n          postdata[\"user\"] = input.attributes[\"value\"] if input.attributes[\"name\"] == \"user\"\n        end\n        \n        data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]\n \n        until forward.nil?\n          data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n        end\n        \n        if data.include?(\"error.gif\")\n          raise AuthenticationError, \"Account invalid\"\n        end\n        \n        parse data\n      end\n    end\n  private\n    \n    def parse(data, options={})\n      data = CSV::Reader.parse(data)\n      col_names = data.shift\n      @contacts = data.map do |person|\n        [\"#{person[0]} #{person[1]}\", person[4]] if person[4] && !person[4].empty?\n      end.compact\n    end    \n \n    def h_to_query_string(hash)\n      u = ERB::Util.method(:u)\n      hash.map { |k, v|\n        u.call(k) + \"=\" + u.call(v)\n      }.join(\"&\")\n    end\n  end\n \n  TYPES[:aol] = Aol\nend"
  },
  {
    "path": "lib/contacts/base.rb",
    "content": "require \"cgi\"\nrequire \"net/http\"\nrequire \"net/https\"\nrequire \"uri\"\nrequire \"zlib\"\nrequire \"stringio\"\nrequire \"thread\"\nrequire \"erb\"\n\nclass Contacts\n  TYPES = {}\n  VERSION = \"1.2.4\"\n  \n  class Base\n    def initialize(login, password, options={})\n      @login = login\n      @password = password\n      @captcha_token = options[:captcha_token]\n      @captcha_response = options[:captcha_response]\n      @connections = {}\n      connect\n    end\n    \n    def connect\n      raise AuthenticationError, \"Login and password must not be nil, login: #{@login.inspect}, password: #{@password.inspect}\" if @login.nil? || @login.empty? || @password.nil? || @password.empty?\n      real_connect\n    end\n    \n    def connected?\n      @cookies && !@cookies.empty?\n    end\n\n    def contacts(options = {})\n      return @contacts if @contacts\n      if connected?\n        url = URI.parse(contact_list_url)\n        http = open_http(url)\n        resp, data = http.get(\"#{url.path}?#{url.query}\",\n          \"Cookie\" => @cookies\n        )\n        \n        if resp.code_type != Net::HTTPOK\n          raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)\n        end\n        \n        parse(data, options)\n      end\n    end\n    \n    def login\n      @attempt ||= 0\n      @attempt += 1\n            \n      if @attempt == 1\n        @login\n      else\n        if @login.include?(\"@#{domain}\")\n          @login.sub(\"@#{domain}\",\"\")\n        else\n          \"#{@login}@#{domain}\"\n        end\n      end\n    end\n    \n    def password\n      @password\n    end\n\n    def skip_gzip?\n      false\n    end\n    \n  private\n  \n    def domain\n      @d ||= URI.parse(self.class.const_get(:URL)).host.sub(/^www\\./,'')\n    end\n\n    def contact_list_url\n      self.class.const_get(:CONTACT_LIST_URL)\n    end\n\n    def address_book_url\n      self.class.const_get(:ADDRESS_BOOK_URL)\n    end\n\n    def open_http(url)\n      c = @connections[Thread.current.object_id] ||= {}\n      http = c[\"#{url.host}:#{url.port}\"]\n      unless http\n        http = Net::HTTP.new(url.host, url.port)\n        if url.port == 443\n          http.use_ssl = true\n          http.verify_mode = OpenSSL::SSL::VERIFY_NONE\n        end\n        c[\"#{url.host}:#{url.port}\"] = http\n      end\n      http.start unless http.started?\n      http\n    end\n    \n    def cookie_hash_from_string(cookie_string)\n      cookie_string.split(\";\").map{|i|i.split(\"=\", 2).map{|j|j.strip}}.inject({}){|h,i|h[i[0]]=i[1];h}\n    end\n    \n    def parse_cookies(data, existing=\"\")\n      return existing if data.nil?\n\n      cookies = cookie_hash_from_string(existing)\n      \n      data.gsub!(/ ?[\\w]+=EXPIRED;/,'')\n      data.gsub!(/ ?expires=(.*?, .*?)[;,$]/i, ';')\n      data.gsub!(/ ?(domain|path)=[\\S]*?[;,$]/i,';')\n      data.gsub!(/[,;]?\\s*(secure|httponly)/i,'')\n      data.gsub!(/(;\\s*){2,}/,', ')\n      data.gsub!(/(,\\s*){2,}/,', ')\n      data.sub!(/^,\\s*/,'')\n      data.sub!(/\\s*,$/,'')\n      \n      data.split(\", \").map{|t|t.to_s.split(\";\").first}.each do |data|\n        k, v = data.split(\"=\", 2).map{|j|j.strip}\n        if cookies[k] && v.empty?\n          cookies.delete(k)\n        elsif v && !v.empty?\n          cookies[k] = v\n        end\n      end\n      \n      cookies.map{|k,v| \"#{k}=#{v}\"}.join(\"; \")\n    end\n    \n    def remove_cookie(cookie, cookies)\n      parse_cookies(\"#{cookie}=\", cookies)\n    end\n    \n    def post(url, postdata, cookies=\"\", referer=\"\")\n      url = URI.parse(url)\n      http = open_http(url)\n      http_header = { \"User-Agent\" => \"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\",\n        \"Accept-Encoding\" => \"gzip\",\n        \"Cookie\" => cookies,\n        \"Referer\" => referer,\n        \"Content-Type\" => 'application/x-www-form-urlencoded'\n      }\n      http_header.reject!{|k, v| k == 'Accept-Encoding'} if skip_gzip?\n      resp, data = http.post(url.path, postdata, http_header)\n      data = uncompress(resp, data)\n      cookies = parse_cookies(resp.response['set-cookie'], cookies)\n      forward = resp.response['Location']\n      forward ||= (data =~ /<meta.*?url='([^']+)'/ ? CGI.unescapeHTML($1) : nil)\n\tif (not forward.nil?) && URI.parse(forward).host.nil?\n\t\tforward = url.scheme.to_s + \"://\" + url.host.to_s + forward\n\tend\n      return data, resp, cookies, forward\n    end\n    \n    def get(url, cookies=\"\", referer=\"\")\n      url = URI.parse(url)\n      attempt = 0\n      begin\n        http = open_http(url)\n        resp, data = http.get(\"#{url.path}?#{url.query}\",\n          \"User-Agent\" => \"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\",\n          \"Accept-Encoding\" => \"gzip\",\n          \"Cookie\" => cookies,\n          \"Referer\" => referer\n        )\n      rescue EOFError => err\n        attempt += 1\n        retry if attempt == 1\n      end\n      data = uncompress(resp, data)\n      cookies = parse_cookies(resp.response['set-cookie'], cookies)\n      forward = resp.response['Location']\n\t  if (not forward.nil?) && URI.parse(forward).host.nil?\n\t\tforward = url.scheme.to_s + \"://\" + url.host.to_s + forward\n\t  end\n      return data, resp, cookies, forward\n    end\n    \n    def uncompress(resp, data)\n      case resp.response['content-encoding']\n      when 'gzip'\n        gz = Zlib::GzipReader.new(StringIO.new(data))\n        data = gz.read\n        gz.close\n        resp.response['content-encoding'] = nil\n      # FIXME: Not sure what Hotmail was feeding me with their 'deflate',\n      #        but the headers definitely were not right\n      when 'deflate'\n        data = Zlib::Inflate.inflate(data)\n        resp.response['content-encoding'] = nil\n      end\n\n      data\n    end\n  end\n  \n  class ContactsError < StandardError\n  end\n  \n  class AuthenticationError < ContactsError\n  end\n\n  class ConnectionError < ContactsError\n  end\n  \n  class TypeNotFound < ContactsError\n  end\n  \n  def self.new(type, login, password, options={})\n    if TYPES.include?(type.to_s.intern)\n      TYPES[type.to_s.intern].new(login, password, options)\n    else\n      raise TypeNotFound, \"#{type.inspect} is not a valid type, please choose one of the following: #{TYPES.keys.inspect}\"\n    end\n  end\n  \n  def self.guess(login, password, options={})\n    TYPES.inject([]) do |a, t|\n      begin\n        a + t[1].new(login, password, options).contacts\n      rescue AuthenticationError\n        a\n      end\n    end.uniq\n  end\nend\n"
  },
  {
    "path": "lib/contacts/gmail.rb",
    "content": "require 'gdata'\n\nclass Contacts\n  class Gmail < Base\n    \n    CONTACTS_SCOPE = 'http://www.google.com/m8/feeds/'\n    CONTACTS_FEED = CONTACTS_SCOPE + 'contacts/default/full/?max-results=1000'\n    \n    def contacts\n      return @contacts if @contacts\n    end\n    \n    def real_connect\n      @client = GData::Client::Contacts.new\n      @client.clientlogin(@login, @password, @captcha_token, @captcha_response)\n      \n      feed = @client.get(CONTACTS_FEED).to_xml\n      \n      @contacts = feed.elements.to_a('entry').collect do |entry|\n        title, email = entry.elements['title'].text, nil\n        entry.elements.each('gd:email') do |e|\n          email = e.attribute('address').value if e.attribute('primary')\n        end\n        [title, email] unless email.nil?\n      end\n      @contacts.compact!\n    rescue GData::Client::AuthorizationError => e\n      raise AuthenticationError, \"Username or password are incorrect\"\n    end\n    \n    private\n    \n    TYPES[:gmail] = Gmail\n  end\nend"
  },
  {
    "path": "lib/contacts/hotmail.rb",
    "content": "class Contacts\n  class Hotmail < Base\n    URL                 = \"https://login.live.com/login.srf?id=2\"\n    OLD_CONTACT_LIST_URL = \"http://%s/cgi-bin/addresses\"\n    NEW_CONTACT_LIST_URL = \"http://%s/mail/GetContacts.aspx\"\n    CONTACT_LIST_URL = \"http://mpeople.live.com/default.aspx?pg=0\" \n    COMPOSE_URL         = \"http://%s/cgi-bin/compose?\"\n    PROTOCOL_ERROR      = \"Hotmail has changed its protocols, please upgrade this library first. If that does not work, report this error at http://rubyforge.org/forum/?group_id=2693\"\n    PWDPAD = \"IfYouAreReadingThisYouHaveTooMuchFreeTime\"\n    MAX_HTTP_THREADS    = 8\n    \n    def real_connect\n      data, resp, cookies, forward = get(URL)\n      old_url = URL\n      until forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n      \n      postdata =  \"PPSX=%s&PwdPad=%s&login=%s&passwd=%s&LoginOptions=2&PPFT=%s\" % [\n        CGI.escape(data.split(\"><\").grep(/PPSX/).first[/=\\S+$/][2..-3]),\n        PWDPAD[0...(PWDPAD.length-@password.length)],\n        CGI.escape(login),\n        CGI.escape(password),\n        CGI.escape(data.split(\"><\").grep(/PPFT/).first[/=\\S+$/][2..-3])\n      ]\n      \n      form_url = data.split(\"><\").grep(/form/).first.split[5][8..-2]\n      data, resp, cookies, forward = post(form_url, postdata, cookies)\n      \n      old_url = form_url\n      until cookies =~ /; PPAuth=/ || forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n      \n      if data.index(\"The e-mail address or password is incorrect\")\n        raise AuthenticationError, \"Username and password do not match\"\n      elsif data != \"\"\n        raise AuthenticationError, \"Required field must not be blank\"\n      elsif cookies == \"\"\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n            \n      data, resp, cookies, forward = get(\"http://mail.live.com/mail\", cookies)\n      until forward.nil?\n        data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]\n      end\n      \n      \n      @domain = URI.parse(old_url).host\n      @cookies = cookies\n    rescue AuthenticationError => m\n      if @attempt == 1\n        retry\n      else\n        raise m\n      end\n    end\n    \n    def contacts(options = {})\n      if connected?\n        @contacts = []\n        build_contacts = []\n        go = true\n        index = 0\n        \n        while(go) do\n          go = false\n          \n          data, resp, cookies, forward = get( get_contact_list_url(index), @cookies )\n\n          email_match_text_beginning = Regexp.escape(\"http://m.mail.live.com/?rru=compose&amp;to=\")\n          email_match_text_end = Regexp.escape(\"&amp;ru=\")\n          \n          raw_html = resp.body.split(\"\n\").grep(/(?:e|dn)lk[0-9]+/)\n          raw_html.inject(-1) do |memo, row|\n            c_info = row.match(/(e|dn)lk([0-9])+/)\n            \n            # Same contact, or different?\n            build_contacts << [] if memo != c_info[2]\n            \n            # Grab info\n            case c_info[1]\n              when \"e\" # Email\n                build_contacts.last[1] = row.match(/#{email_match_text_beginning}(.*)#{email_match_text_end}/)[1]\n              when \"dn\" # Name\n                build_contacts.last[0] = row.match(/<a[^>]*>(.+)<\\/a>/)[1]\n            end\n            \n            # Set memo to contact id\n            c_info[2]\n          end\n          \n          go = resp.body.include?(\"ContactList_next\")\n          index += 1\n        end\n        \n        build_contacts.each do |contact|\n          unless contact[1].nil?\n            # Only return contacts with email addresses\n            contact[1] = CGI::unescape CGI::unescape(contact[1])\n            @contacts << contact\n          end\n        end\n        \n        return @contacts\n      end\n    end\n    \n    def get_contact_list_url(index) \n      \"http://mpeople.live.com/default.aspx?pg=#{index}\"\n    end\n    \n    private\n    \n    TYPES[:hotmail] = Hotmail\n  end\nend"
  },
  {
    "path": "lib/contacts/json_picker.rb",
    "content": "if !Object.const_defined?('ActiveSupport')\n  require 'json'\nend\n\nclass Contacts\n  def self.parse_json( string )\n    if Object.const_defined?('ActiveSupport') and\n       ActiveSupport.const_defined?('JSON')\n      ActiveSupport::JSON.decode( string )\n    elsif Object.const_defined?('JSON')\n      JSON.parse( string )\n    else\n      raise 'Contacts requires JSON or Rails (with ActiveSupport::JSON)'\n    end\n  end\nend"
  },
  {
    "path": "lib/contacts/mailru.rb",
    "content": "require 'csv'\n\nclass Contacts\n  class Mailru < Base\n    LOGIN_URL = \"https://auth.mail.ru/cgi-bin/auth\"\n    ADDRESS_BOOK_URL = \"http://win.mail.ru/cgi-bin/abexport/addressbook.csv\"\n\n    attr_accessor :cookies\n\n    def real_connect\n      username = login\n      \n      postdata =  \"Login=%s&Domain=%s&Password=%s\" % [\n        CGI.escape(username),\n        CGI.escape(domain_param(username)),\n        CGI.escape(password)\n      ]\n\n      data, resp, self.cookies, forward = post(LOGIN_URL, postdata, \"\")\n\n      if data.index(\"fail=1\")\n        raise AuthenticationError, \"Username and password do not match\"\n      elsif cookies == \"\" or data == \"\"\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n\n      data, resp, cookies, forward = get(login_token_link(data), login_cookies.join(';'))\n    end\n\n    def contacts\n      postdata = \"confirm=1&abtype=6\"\n      data, resp, cookies, forward = post(ADDRESS_BOOK_URL, postdata, login_cookies.join(';'))\n\n      @contacts = []\n      CSV.parse(data) do |row|\n        @contacts << [row[0], row[4]] unless header_row?(row)\n      end\n\n      @contacts\n    end\n\n    def skip_gzip?\n      true\n    end\n\n    private\n    def login_token_link(data)\n      data.match(/url=(.+)\\\">/)[1]\n    end\n\n    def login_cookies\n      self.cookies.split(';').collect{|c| c if (c.include?('t=') or c.include?('Mpop='))}.compact.collect{|c| c.strip}\n    end\n\n    def header_row?(row)\n      row[0] == 'AB-Name'\n    end\n\n    def domain_param(login)\n      login.include?('@') ?\n        login.match(/.+@(.+)/)[1] :\n        'mail.ru'\n    end\n\n  end\n\n  TYPES[:mailru] = Mailru\nend"
  },
  {
    "path": "lib/contacts/plaxo.rb",
    "content": "require 'rexml/document'\n\nclass Contacts\n  class Plaxo < Base\n    URL                 = \"http://www.plaxo.com/\"\n    LOGIN_URL           = \"https://www.plaxo.com/signin\"\n    ADDRESS_BOOK_URL    = \"http://www.plaxo.com/po3/?module=ab&operation=viewFull&mode=normal\"\n    CONTACT_LIST_URL    = \"http://www.plaxo.com/axis/soap/contact?_action=getContacts&_format=xml\"\n    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\"\n    \n    def real_connect\n      \n    end # real_connect\n    \n    def contacts\n      getdata = \"&authInfo.authByEmail.email=%s\" % CGI.escape(login)\n      getdata += \"&authInfo.authByEmail.password=%s\" % CGI.escape(password)\n      data, resp, cookies, forward = get(CONTACT_LIST_URL + getdata)\n      \n      if resp.code_type != Net::HTTPOK\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n      \n      parse data\n    end # contacts\n    \n  private\n    def parse(data, options={})\n      doc = REXML::Document.new(data)\n      code = doc.elements['//response/code'].text\n      \n      if code == '401'\n        raise AuthenticationError, \"Username and password do not match\"\n      elsif code == '200'\n        @contacts = []\n        doc.elements.each('//contact') do |cont|\n          name = if cont.elements['fullName']\n            cont.elements['fullName'].text\n          elsif cont.elements['displayName']\n            cont.elements['displayName'].text\n          end\n          email = if cont.elements['email1']\n            cont.elements['email1'].text\n          end\n          if name || email\n            @contacts << [name, email]\n          end\n        end\n        @contacts\n      else\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n      \n    end # parse\n\n  end # Plaxo\n  \n  TYPES[:plaxo] = Plaxo\n  \nend # Contacts\n\n\n# sample contacts responses\n=begin\nBad email\n=========\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<ns1:GetContactsResponse xmlns:ns1=\"Plaxo\">\n  <response>\n    <code>401</code>\n    <subCode>1</subCode>\n    <message>User not found.</message>\n  </response>\n</ns1:GetContactsResponse>\n\n\nBad password\n============\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<ns1:GetContactsResponse xmlns:ns1=\"Plaxo\">\n  <response>\n    <code>401</code>\n    <subCode>4</subCode>\n    <message>Bad password or security token.</message>\n  </response>\n</ns1:GetContactsResponse>\n\n\nSuccess\n=======\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<ns1:GetContactsResponse xmlns:ns1=\"Plaxo\">\n\n  <response>\n    <code>200</code>\n    <message>OK</message>\n    <userId>77311236242</userId>\n  </response>\n  \n  <contacts>\n\n    <contact>\n      <itemId>61312569</itemId>\n      <displayName>Joe Blow1</displayName>\n      <fullName>Joe Blow1</fullName>\n      <firstName>Joe</firstName>\n      <lastName>Blow1</lastName>\n      <homeEmail1>joeblow1@mailinator.com</homeEmail1>\n      <email1>joeblow1@mailinator.com</email1>\n      <folderId>5291351</folderId>\n    </contact>\n    \n    <contact>\n      <itemId>61313159</itemId>\n      <displayName>Joe Blow2</displayName>\n      <fullName>Joe Blow2</fullName>\n      <firstName>Joe</firstName>\n      <lastName>Blow2</lastName>\n      <homeEmail1>joeblow2@mailinator.com</homeEmail1>\n      <email1>joeblow2@mailinator.com</email1>\n      <folderId>5291351</folderId>\n    </contact>\n    \n  </contacts>\n  \n  <totalCount>2</totalCount>\n  <editCounter>3</editCounter>\n  \n</ns1:GetContactsResponse>\n=end"
  },
  {
    "path": "lib/contacts/yahoo.rb",
    "content": "class Contacts\n  class Yahoo < Base\n    URL                 = \"http://mail.yahoo.com/\"\n    LOGIN_URL           = \"https://login.yahoo.com/config/login\"\n    ADDRESS_BOOK_URL    = \"http://address.mail.yahoo.com/?.rand=430244936\"\n    CONTACT_LIST_URL    = \"http://address.mail.yahoo.com/?_src=&_crumb=crumb&sortfield=3&bucket=1&scroll=1&VPC=social_list&.r=time\"\n    PROTOCOL_ERROR      = \"Yahoo 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\"\n\n    def real_connect\n      postdata =  \".tries=2&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=\"\n      postdata += \"&.partner=&.u=4eo6isd23l8r3&.v=0&.challenge=gsMsEcoZP7km3N3NeI4mX\"\n      postdata += \"kGB7zMV&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.\"\n      postdata += \"done=#{CGI.escape(URL)}&login=#{CGI.escape(login)}&passwd=#{CGI.escape(password)}\"\n\n      data, resp, cookies, forward = post(LOGIN_URL, postdata)\n\n      if data.index(\"Invalid ID or password\") || data.index(\"This ID is not yet taken\")\n        raise AuthenticationError, \"Username and password do not match\"\n      elsif data.index(\"Sign in\") && data.index(\"to Yahoo!\")\n        raise AuthenticationError, \"Required field must not be blank\"\n      elsif !data.match(/uncompressed\\/chunked/)\n        raise ConnectionError, PROTOCOL_ERROR\n      elsif cookies == \"\"\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n\n      data, resp, cookies, forward = get(forward, cookies, LOGIN_URL)\n\n      if resp.code_type != Net::HTTPOK\n        raise ConnectionError, PROTOCOL_ERROR\n      end\n\n      @cookies = cookies\n    end\n\n    def contacts\n      return @contacts if @contacts\n      @contacts = []\n\n      if connected?\n        # first, get the addressbook site with the new crumb parameter\n        url = URI.parse(address_book_url)\n        http = open_http(url)\n        resp, data = http.get(\"#{url.path}?#{url.query}\",\n          \"Cookie\" => @cookies\n        )\n\n        if resp.code_type != Net::HTTPOK\n          raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)\n        end\n\n        crumb = data.to_s[/dotCrumb:   '(.*?)'/][13...-1]\n\n        # now proceed with the new \".crumb\" parameter to get the csv data\n        url = URI.parse(contact_list_url.sub(\"_crumb=crumb\",\"_crumb=#{crumb}\").sub(\"time\", Time.now.to_f.to_s.sub(\".\",\"\")[0...-2]))\n        http = open_http(url)\n        resp, more_data = http.get(\"#{url.path}?#{url.query}\",\n          \"Cookie\" => @cookies,\n          \"X-Requested-With\" => \"XMLHttpRequest\",\n          \"Referer\" => address_book_url\n        )\n\n        if resp.code_type != Net::HTTPOK\n        raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)\n        end\n\n        if more_data =~ /\"TotalABContacts\":(\\d+)/\n          total = $1.to_i\n          ((total / 50.0).ceil).times do |i|\n            # now proceed with the new \".crumb\" parameter to get the csv data\n            url = URI.parse(contact_list_url.sub(\"bucket=1\",\"bucket=#{i}\").sub(\"_crumb=crumb\",\"_crumb=#{crumb}\").sub(\"time\", Time.now.to_f.to_s.sub(\".\",\"\")[0...-2]))\n            http = open_http(url)\n            resp, more_data = http.get(\"#{url.path}?#{url.query}\",\n              \"Cookie\" => @cookies,\n              \"X-Requested-With\" => \"XMLHttpRequest\",\n              \"Referer\" => address_book_url\n            )\n\n            if resp.code_type != Net::HTTPOK\n            raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)\n            end\n\n            parse more_data\n          end\n        end\n\n        @contacts\n      end\n    end\n\n  private\n\n    def parse(data, options={})\n      @contacts ||= []\n      @contacts += Contacts.parse_json(data)[\"response\"][\"ResultSet\"][\"Contacts\"].to_a.select{|contact|!contact[\"email\"].to_s.empty?}.map do |contact|\n        name = contact[\"contactName\"].split(\",\")\n        [[name.pop, name.join(\",\")].join(\" \").strip, contact[\"email\"]]\n      end if data =~ /^\\{\"response\":/\n      @contacts\n    end\n\n  end\n\n  TYPES[:yahoo] = Yahoo\nend\n"
  },
  {
    "path": "lib/contacts.rb",
    "content": "$:.unshift(File.dirname(__FILE__)+\"/contacts/\")\n\nrequire 'rubygems'\nrequire 'bundler/setup'\n\nrequire 'base'\nrequire 'json_picker'\nrequire 'gmail'\nrequire 'hotmail'\nrequire 'yahoo'\nrequire 'plaxo'\nrequire 'aol'\nrequire 'mailru'\n\n"
  },
  {
    "path": "test/example_accounts.yml",
    "content": "gmail:\n  username: <changeme>\n  password: <changeme>\n  contacts:\n    -\n      name: \"FirstName1 LastName1\"\n      email_address: \"firstname1@example.com\"\n    -\n      name: \"FirstName2 LastName2\"\n      email_address: \"firstname2@example.com\"\nyahoo:\n  username: <changeme>\n  password: <changeme>\n  contacts:\n    -\n      name: \"FirstName1 LastName1\"\n      email_address: \"firstname1@example.com\"\n    -\n      name: \"FirstName2 LastName2\"\n      email_address: \"firstname2@example.com\"\nhotmail:\n  username: <changeme>\n  password: <changeme>\n  contacts:\n    -\n      name: \"FirstName1 LastName1\"\n      email_address: \"firstname1@example.com\"\n    -\n      name: \"FirstName2 LastName2\"\n      email_address: \"firstname2@example.com\"\naol:\n  username: <changeme>\n  password: <changeme>\n  contacts:\n    -\n      name: \"FirstName1 LastName1\"\n      email_address: \"firstname1@example.com\"\n    -\n      name: \"FirstName2 LastName2\"\n      email_address: \"firstname2@example.com\"\nmailru:\n  username: <changeme>\n  password: <changeme>\n  contacts:\n    -\n      name: \"FirstName1 LastName1\"\n      email_address: \"firstname1@example.com\"\n    -\n      name: \"FirstName2 LastName2\"\n      email_address: \"firstname2@example.com\"\n"
  },
  {
    "path": "test/test_helper.rb",
    "content": "dir = File.dirname(__FILE__)\r\n$LOAD_PATH.unshift(dir + \"/../lib/\")\r\nrequire 'test/unit'\r\nrequire 'contacts'\r\nrequire 'yaml'\r\n\r\nclass ContactImporterTestCase < Test::Unit::TestCase\r\n  # Add more helper methods to be used by all tests here...\r\n  def default_test\r\n    assert true\r\n  end\r\nend\r\n\r\nclass TestAccounts\r\n  def self.[](type)\r\n    load[type]\r\n  end\r\n  \r\n  def self.load(file = File.dirname(__FILE__) + \"/accounts.yml\")\r\n    raise \"/test/accounts.yml file not found, please create, see /test/example_accounts.yml for information\" unless File.exist?(file)\r\n    \r\n    accounts = {}\r\n    YAML::load(File.open(file)).each do |type, contents|\r\n      contacts = contents[\"contacts\"].collect {|contact| [contact[\"name\"], contact[\"email_address\"]]}\r\n      accounts[type.to_sym] = Account.new(type.to_sym, contents[\"username\"], contents[\"password\"], contacts)\r\n    end\r\n    accounts\r\n  end\r\n\r\n  Account = Struct.new :type, :username, :password, :contacts\r\nend\r\n"
  },
  {
    "path": "test/test_suite.rb",
    "content": "dir = File.dirname(__FILE__)\r\nDir[\"#{dir}/**/*_test.rb\"].each do |file|\r\n  require file\r\nend"
  },
  {
    "path": "test/unit/aol_contact_importer_test.rb",
    "content": "dir = File.dirname(__FILE__)\nrequire \"#{dir}/../test_helper\"\nrequire 'contacts'\n\nclass AolContactImporterTest < ContactImporterTestCase\n  def setup\n    super\n    @account = TestAccounts[:aol]\n  end\n\n  def test_successful_login\n    Contacts.new(:aol, @account.username, @account.password)\n  end\n\n  def test_importer_fails_with_invalid_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:aol, @account.username, \"wrong_password\")\n    end\n  end\n\n  def test_importer_fails_with_blank_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:aol, @account.username, \"\")\n    end\n  end\n\n  def test_importer_fails_with_blank_username\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:aol, \"\", @account.password)\n    end\n  end\n\n  def test_fetch_contacts\n    contacts = Contacts.new(:aol, @account.username, @account.password).contacts\n    @account.contacts.each do |contact|\n      assert contacts.include?(contact), \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\n    end\n  end\nend"
  },
  {
    "path": "test/unit/gmail_contact_importer_test.rb",
    "content": "dir = File.dirname(__FILE__)\nrequire \"#{dir}/../test_helper\"\nrequire 'contacts'\n\nclass GmailContactImporterTest < ContactImporterTestCase\n  def setup\n    super\n    @account = TestAccounts[:gmail]\n  end\n\n  def test_successful_login\n    Contacts.new(:gmail, @account.username, @account.password)\n  end\n\n  def test_importer_fails_with_invalid_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:gmail, @account.username, \"wrong_password\")\n    end\n  end\n\n  def test_importer_fails_with_blank_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:gmail, @account.username, \"\")\n    end\n  end\n\n  def test_importer_fails_with_blank_username\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:gmail, \"\", @account.password)\n    end\n  end\n\n  def test_fetch_contacts\n    contacts = Contacts.new(:gmail, @account.username, @account.password).contacts\n    @account.contacts.each do |contact|\n      assert contacts.include?(contact), \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\n    end\n  end\nend"
  },
  {
    "path": "test/unit/hotmail_contact_importer_test.rb",
    "content": "dir = File.dirname(__FILE__)\r\nrequire \"#{dir}/../test_helper\"\r\nrequire 'contacts'\r\n\r\nclass HotmailContactImporterTest < ContactImporterTestCase\r\n  def setup\r\n    super\r\n    @account = TestAccounts[:hotmail]\r\n  end\r\n\r\n  def test_successful_login\r\n    Contacts.new(:hotmail, @account.username, @account.password)\r\n  end\r\n\r\n  def test_importer_fails_with_invalid_password\r\n    assert_raise(Contacts::AuthenticationError) do\r\n      Contacts.new(:hotmail, @account.username,\"wrong_password\")\r\n    end\r\n  end\r\n\r\n  def test_fetch_contacts\r\n    contacts = Contacts.new(:hotmail, @account.username, @account.password).contacts\r\n    @account.contacts.each do |contact|\r\n      assert contacts.include?(contact), \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\r\n    end\r\n  end\r\n  \r\n  def test_importer_fails_with_invalid_msn_password\r\n    assert_raise(Contacts::AuthenticationError) do\r\n      Contacts.new(:hotmail, \"test@msn.com\",\"wrong_password\")\r\n    end\r\n  end\r\n  \r\n  # Since the hotmail scraper doesn't read names, test email\r\n  def test_fetch_email\r\n    contacts = Contacts.new(:hotmail, @account.username, @account.password).contacts\r\n    @account.contacts.each do |contact|\r\n      assert contacts.any?{|book_contact| book_contact.last == contact.last }, \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\r\n    end\r\n  end\r\nend\r\n"
  },
  {
    "path": "test/unit/mailru_contact_importer_test.rb",
    "content": "dir = File.dirname(__FILE__)\nrequire \"#{dir}/../test_helper\"\nrequire 'contacts'\n\nclass MailruContactImporterTest < ContactImporterTestCase\n  def setup\n    super\n    @account = TestAccounts[:mailru]\n  end\n\n  def test_successful_login\n    Contacts.new(:mailru, @account.username, @account.password)\n  end\n\n  def test_importer_fails_with_invalid_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:mailru, @account.username, \"wrong_password\")\n    end\n  end\n\n  def test_importer_fails_with_blank_password\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:mailru, @account.username, \"\")\n    end\n  end\n\n  def test_importer_fails_with_blank_username\n    assert_raise(Contacts::AuthenticationError) do\n      Contacts.new(:mailru, \"\", @account.password)\n    end\n  end\n\n  def test_fetch_contacts\n    contacts = Contacts.new(:mailru, @account.username, @account.password).contacts\n    @account.contacts.each do |contact|\n      assert contacts.include?(contact), \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\n    end\n  end\nend"
  },
  {
    "path": "test/unit/test_accounts_test.rb",
    "content": "dir = File.dirname(__FILE__)\nrequire \"#{dir}/../test_helper\"\n\nclass TestAccountsTest < ContactImporterTestCase\n  def test_test_accounts_loads_data_from_example_accounts_file\n    account = TestAccounts.load(File.dirname(__FILE__) + \"/../example_accounts.yml\")[:gmail]\n    \n    assert_equal :gmail, account.type\n    assert_equal \"<changeme>\", account.username\n    assert_equal \"<changeme>\", account.password\n    assert_equal [[\"FirstName1 LastName1\", \"firstname1@example.com\"], [\"FirstName2 LastName2\", \"firstname2@example.com\"]], account.contacts\n  end\n  \n  def test_test_accounts_blows_up_if_file_doesnt_exist\n    assert_raise(RuntimeError) do\n      TestAccounts.load(\"file_that_does_not_exist.yml\")\n    end\n  end\n  \n  def test_we_can_load_from_account_file\n    assert_not_nil TestAccounts[:gmail].username\n  end\nend"
  },
  {
    "path": "test/unit/yahoo_csv_contact_importer_test.rb",
    "content": "dir = File.dirname(__FILE__)\r\nrequire \"#{dir}/../test_helper\"\r\nrequire 'contacts'\r\n\r\nclass YahooContactImporterTest < ContactImporterTestCase\r\n  def setup\r\n    super\r\n    @account = TestAccounts[:yahoo]\r\n  end\r\n\r\n  def test_a_successful_login\r\n    Contacts.new(:yahoo, @account.username, @account.password)\r\n  end\r\n\r\n  def test_importer_fails_with_invalid_password\r\n    assert_raise(Contacts::AuthenticationError) do\r\n      Contacts.new(:yahoo, @account.username, \"wrong_password\")\r\n    end\r\n    # run the \"successful\" login test to ensure we reset yahoo's failed login lockout counter\r\n    # See http://www.pivotaltracker.com/story/show/138210\r\n    # yahoo needs some time to unset the failed login state, apparently... \r\n    # ...1 sec and 5 secs still failed sporadically\r\n    sleep 10\r\n    assert_nothing_raised do\r\n      Contacts.new(:yahoo, @account.username, @account.password)\r\n    end\r\n  end\r\n\r\n  def test_a_fetch_contacts\r\n    contacts = Contacts.new(:yahoo, @account.username, @account.password).contacts\r\n    @account.contacts.each do |contact|\r\n      assert contacts.include?(contact), \"Could not find: #{contact.inspect} in #{contacts.inspect}\"\r\n    end\r\n  end\r\nend"
  }
]