Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contacts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.description = "A universal interface to grab contact list information from various providers including Yahoo, AOL, Gmail, Hotmail, and Plaxo."
s.has_rdoc = false
s.authors = ["Lucas Carlson"]
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"]
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", "lib/contacts/mailru.rb", "lib/contacts/wp.rb"]
s.add_dependency("json", ">= 1.1.1")
s.add_dependency('gdata', '>= 1.1.1')
end
1 change: 1 addition & 0 deletions lib/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
require 'plaxo'
require 'aol'
require 'mailru'
require 'wp'
41 changes: 41 additions & 0 deletions lib/contacts/wp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'csv'
require 'mechanize'

class Contacts
class WP < Base

LOGIN_URL = "https://poczta.wp.pl"
AUTH_ERROR_URL = "http://profil.wp.pl/login_poczta.html"
ADDRESS_BOOK_URL = "http://ksiazka-adresowa.wp.pl/import-export.html"

def real_connect
begin
@agent = Mechanize.new
page = @agent.get(LOGIN_URL)
form = page.forms.first
form.login_username = @login
form.login_password = @password
@page = form.submit
if page.uri.to_s == AUTH_ERROR_URL
raise AuthenticationError, "Username and password do not match"
end
end
end

def contacts
page = @agent.get(ADDRESS_BOOK_URL)
form = page.forms.last
form.gr_id = 0
form.program = 'gm'
con = CSV.parse(form.submit.body)
@contacts = []
con[1..-1].each do |row|
@contacts << [row[0], row[1]]
end
@contacts
end

end

TYPES[:wp] = WP
end
18 changes: 14 additions & 4 deletions test/example_accounts.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
gmail:
username: <changeme>
password: <changeme>
contacts:
contacts:
-
name: "FirstName1 LastName1"
email_address: "[email protected]"
Expand All @@ -11,7 +11,7 @@ gmail:
yahoo:
username: <changeme>
password: <changeme>
contacts:
contacts:
-
name: "FirstName1 LastName1"
email_address: "[email protected]"
Expand All @@ -21,7 +21,7 @@ yahoo:
hotmail:
username: <changeme>
password: <changeme>
contacts:
contacts:
-
name: "FirstName1 LastName1"
email_address: "[email protected]"
Expand All @@ -31,7 +31,7 @@ hotmail:
aol:
username: <changeme>
password: <changeme>
contacts:
contacts:
-
name: "FirstName1 LastName1"
email_address: "[email protected]"
Expand All @@ -48,3 +48,13 @@ mailru:
-
name: "FirstName2 LastName2"
email_address: "[email protected]"
wp:
username: <changeme>
password: <changeme>
contacts:
-
name: "FirstName1 LastName1"
email_address: "[email protected]"
-
name: "FirstName2 LastName2"
email_address: "[email protected]"
39 changes: 39 additions & 0 deletions test/unit/wp_contact_importer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
dir = File.dirname(__FILE__)
require "#{dir}/../test_helper"
require 'contacts'

class WPContactImporterTest < ContactImporterTestCase
def setup
super
@account = TestAccounts[:wp]
end

def test_successful_login
Contacts.new(:wp, @account.username, @account.password)
end

def test_importer_fails_with_invalid_password
assert_raise(Contacts::AuthenticationError) do
Contacts.new(:wp, @account.username, "wrong_password")
end
end

def test_importer_fails_with_blank_password
assert_raise(Contacts::AuthenticationError) do
Contacts.new(:wp, @account.username, "")
end
end

def test_importer_fails_with_blank_username
assert_raise(Contacts::AuthenticationError) do
Contacts.new(:wp, "", @account.password)
end
end

def test_fetch_contacts
contacts = Contacts.new(:wp, @account.username, @account.password).contacts
@account.contacts.each do |contact|
assert contacts.include?(contact), "Could not find: #{contact.inspect} in #{contacts.inspect}"
end
end
end