Sha256: f1bc64c85b1c15ef9c57d183cca8ed1d4b8c8d83f1b54a493a13a106391aac81

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

require 'blackbook/importer/page_scraper'

class Blackbook::Importer::WebDE < Blackbook::Importer::PageScraper
  LOGIN_URL = "https://freemail.web.de"

  def =~( options )
    options && options[:username] =~ /@web\.de$/i
  end

  def login
    username, password = options[:username], options[:password]

    begin
      page = agent.get LOGIN_URL

      form = page.forms.with.name("login").first
      form.username = username
      form.password = password

      page = form.submit
      # follow logout hint
      if (continue_link = page.links.select { |link| link.text =~ /weiter zu FreeMail/ }.first)
        page = continue_link.click
      end

      if page.uri.to_s.match(/logonfailed/)
        raise Blackbook::BadCredentialsError.new
      end

      # follow content frame
      @next = agent.get page.frames[1].src
    rescue => e
      raise e || Blackbook::BlackbookError.new
    end
  end

  def prepare
    login
  end

  def scrape_contacts
    page = @next

    contacts = [/Posteingang/, /Unbekannt/].map do |folder|
      page = page.links.select { |link| link.text =~ folder }.first.click
      find_contacts(page)
    end

    contacts.inject([]) do |memo, contact|
      memo << contact unless memo.include? contact
      memo
    end
  end

  protected
    def find_contacts(page)
      page.search("span.from a").map do |link|
        recp = link.attributes["title"].gsub(/\n/, "").split(/\s/)
        email = recp.pop
        fullname = recp.join(" ")

        { :name => fullname, :email => email }
      end
    end

    Blackbook.register :webde, self
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
bcardarella-blackbook-1.0.10 lib/blackbook/importer/web.de.rb
bcardarella-blackbook-1.0.11 lib/blackbook/importer/web.de.rb
bcardarella-blackbook-1.0.7 lib/blackbook/importer/web.de.rb
bcardarella-blackbook-1.0.8 lib/blackbook/importer/web.de.rb
bcardarella-blackbook-1.0.9 lib/blackbook/importer/web.de.rb
briancollins-blackbook-1.0.15 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.12 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.13 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.14 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.15 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.16 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.17 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.18 lib/blackbook/importer/web.de.rb
rakutenusa-blackbook-1.0.19 lib/blackbook/importer/web.de.rb