Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New connectors #8

Merged
merged 7 commits into from

1 participant

Commits on Mar 14, 2012
  1. @laurynas
Commits on Mar 16, 2012
  1. @laurynas
Commits on Mar 19, 2012
  1. @laurynas
  2. @laurynas

    seznam.cz connector

    laurynas authored
  3. @laurynas

    One.lt connector

    laurynas authored
  4. @laurynas

    Merge one.lt connector

    laurynas authored
  5. @laurynas

    inbox.lt connector

    laurynas authored
This page is out of date. Refresh to see the latest.
View
3  lib/contacts.rb
@@ -12,3 +12,6 @@
require 'mailru'
require 'gmx'
require 'web_de'
+require 'seznam'
+require 'onelt'
+require 'inbox_lt'
View
89 lib/contacts/inbox_lt.rb
@@ -0,0 +1,89 @@
+class Contacts
+ class InboxLt < Base
+ URL = "http://www.inbox.lt/?language=lt"
+ LOGIN_URL = "https://login.inbox.lt/redirect.php"
+ ADDRESS_BOOK_URL = "http://mail.inbox.lt/horde/turba/?char=&sort=name&page=%d"
+ PROTOCOL_ERROR = "inbox.lt has changed its protocols"
+
+ attr_accessor :cookies
+
+ def real_connect
+ data, resp, self.cookies, forward = get(URL, "")
+
+ doc = Nokogiri(data)
+
+ salt_el = doc.at('input[name=salt]')
+
+ if salt_el.nil?
+ raise ConnectionError, PROTOCOL_ERROR
+ end
+
+ salt = salt_el['value']
+
+ postdata = "language=lt&passhash=&salt=%s&redirect_url=%s&redirect_vars=imapuser,usessl&imapuser=%s&pass=%s&usessl=1" % [
+ CGI.escape(salt),
+ CGI.escape('http://www.inbox.lt/index.php?actionID=imp_login'),
+ CGI.escape(username),
+ CGI.escape(password)
+ ]
+
+ data, resp, self.cookies, forward = post(LOGIN_URL, postdata, "")
+
+ if forward.nil? || !forward.match("logged_in=1")
+ raise AuthenticationError, "Username and password do not match"
+ end
+
+ until forward.nil?
+ data, resp, self.cookies, forward = get(forward, self.cookies)
+ end
+ end
+
+ def contacts
+ @contacts = []
+ page = 0
+
+ until page.nil?
+ url = ADDRESS_BOOK_URL % page
+
+ data, resp, self.cookies, forward = get(url, self.cookies)
+
+ doc = Nokogiri(data)
+
+ (doc/"form#contactsForm table table[1] tr").each do |tr|
+ name_td = tr.at('td[2]')
+ email_td = tr.at('td[3]')
+
+ next if name_td.nil? || email_td.nil?
+
+ name = name_td.text.strip
+ email = email_td.text.strip
+
+ next unless email.match('@')
+
+ @contacts << [ name, email ]
+ end
+
+ page+= 1
+ page = nil unless data.match("&page=#{page}")
+ end
+
+ @contacts
+ end
+
+ def skip_gzip?
+ false
+ end
+
+ private
+
+ def username
+ @login.split('@').first
+ end
+
+ def domain
+ @login.split('@').last
+ end
+ end
+
+ TYPES[:inbox_lt] = InboxLt
+end
View
89 lib/contacts/onelt.rb
@@ -0,0 +1,89 @@
+class Contacts
+ class Onelt < Base
+ LOGIN_URL = "http://w33.one.lt/logonSubsite.do?subsite=pastas"
+ EMAIL_URL = "http://email.one.lt/"
+ ADDRESS_BOOK_URL = "http://email.one.lt/index.html?screen=RedirectServer&pane=contacts"
+ PROTOCOL_ERROR = "One.lt 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"
+
+ attr_accessor :cookies
+
+ def real_connect
+ data, resp, self.cookies, forward = get(LOGIN_URL)
+
+ postdata = "username=%s&password=%s&subsite=pastas" % [
+ CGI.escape(username),
+ CGI.escape(password)
+ ]
+
+ data, resp, self.cookies, forward, old_url = post(LOGIN_URL, postdata, self.cookies)
+
+ if data.index("f-login")
+ raise AuthenticationError, "Username and password do not match"
+ elsif !forward.nil? && forward.match('brutecheck')
+ raise AuthenticationError, "Got captcha"
+ elsif forward.nil? || !forward.match('tkn')
+ raise ConnectionError, PROTOCOL_ERROR
+ end
+
+ forward+= '&subsite=pastas' unless forward.match('subsite=pastas')
+ #p forward
+
+ # http://w32.one.lt/logonSubsite.do?subsite=pastas&tkn=3229
+ data, resp, self.cookies, forward, old_url = get(forward, self.cookies, LOGIN_URL) + [forward]
+
+ # http://pastas.one.lt/?tkn=979
+ data, resp, self.cookies, forward, old_url = get(forward, self.cookies, old_url) + [forward]
+
+ # http://email.one.lt/?action=LoginUser
+ data, resp, self.cookies, forward, old_url = get(forward, self.cookies, old_url) + [forward]
+ end
+
+ def contacts
+ data, resp, self.cookies, forward = get(ADDRESS_BOOK_URL, self.cookies)
+
+ doc = Nokogiri(data)
+ int = nil
+
+ (doc/"input[name=int]").each do |input|
+ int = input['value']
+ end
+
+ postdata = "action=LoginUser&pane=contacts&int=#{int}"
+ data, resp, self.cookies, forward = post(EMAIL_URL, postdata, self.cookies)
+
+ contacts = []
+ page = 1
+
+ until page.nil?
+ url = "http://email.one.lt/index.html?pane=contacts&page-number=%d" % page
+
+ data, resp, self.cookies, forward = get(url, self.cookies)
+
+ doc = Nokogiri(data)
+
+ (doc/'form[name=contacts_items]//table[2]//tr[class=whiteBg]').each do |tr|
+ name = tr.at('td[2]').text.strip
+ email = tr.at('td[4]').text.strip
+
+ next if email.empty?
+
+ contacts << [ name, email ]
+ end
+
+ page+= 1
+ page = nil unless data.match("&page-number=#{page}")
+ end
+
+ contacts
+ end
+
+ private
+
+ def username
+ login.split('@').first
+ end
+
+ end
+
+ TYPES[:onelt] = Onelt
+end
View
78 lib/contacts/seznam.rb
@@ -0,0 +1,78 @@
+class Contacts
+ class Seznam < Base
+ LOGIN_URL = "https://login.szn.cz/loginProcess"
+ ADDRESS_BOOK_URL = "http://email.seznam.cz/abookCsvExport?sessionId=&charset=utf-8&eof=windows&export=nameLast&export=nameFirst&export=nick&export=email"
+
+ attr_accessor :cookies
+
+ def real_connect
+ postdata = "disableSSL=0&domain=%s&forceRelogin=0&forceSSL=0&lang=cz&loginType=seznam&returnURL=%s&serviceId=email&username=%s&password=%s" % [
+ CGI.escape(domain),
+ CGI.escape('http://email.seznam.cz/ticket'),
+ CGI.escape(username),
+ CGI.escape(password)
+ ]
+
+ data, resp, self.cookies, forward = post(LOGIN_URL, postdata, "")
+
+ if !forward.nil? && forward.match("badLogin")
+ raise AuthenticationError, "Username and password do not match"
+ end
+
+ doc = Nokogiri(data)
+
+ a = doc.at('body>a')
+ forward = a['href'].to_s
+
+ data, resp, self.cookies, forward = get(forward, self.cookies)
+
+ doc = Nokogiri(data)
+
+ a = doc.at('body>a')
+ forward = a['href'].to_s
+
+ data, resp, self.cookies, forward = get(forward, self.cookies)
+
+ doc = Nokogiri(data)
+
+ a = doc.at('body>a')
+ forward = a['href'].to_s
+
+ data, resp, self.cookies, forward = get(forward, self.cookies)
+ end
+
+ def contacts
+ url = ADDRESS_BOOK_URL
+ @contacts = []
+
+ data, resp, self.cookies, forward = get(url, self.cookies)
+
+ CSV.parse(data, { :col_sep => ';' }) do |row|
+ last_name, first_name, unknown, email = row
+
+ name = "#{first_name} #{last_name}".strip
+ email.strip!
+
+ @contacts << [name, email] unless email.empty?
+ end
+
+ @contacts
+ end
+
+ def skip_gzip?
+ false
+ end
+
+ private
+
+ def username
+ @login.split('@').first
+ end
+
+ def domain
+ @login.split('@').last
+ end
+ end
+
+ TYPES[:seznam] = Seznam
+end
View
34 test/example_accounts.yml
@@ -69,3 +69,37 @@ web_de:
-
name: "FirstName2 LastName2"
email_address: "firstname2@example.com"
+
+seznam:
+ username: <changeme>
+ password: <changeme>
+ contacts:
+ -
+ name: "FirstName1 LastName1"
+ email_address: "firstname1@example.com"
+ -
+ name: "FirstName2 LastName2"
+ email_address: "firstname2@example.com"
+
+onelt:
+ username: <changeme>
+ password: <changeme>
+ contacts:
+ -
+ name: "FirstName1"
+ email_address: "firstname1@example.com"
+ -
+ name: "FirstName2"
+ email_address: "firstname2@example.com"
+
+inbox_lt:
+ username: <changeme>
+ password: <changeme>
+ contacts:
+ -
+ name: "FirstName1 LastName1"
+ email_address: "firstname1@example.com"
+ -
+ name: "FirstName2 LastName2"
+ email_address: "firstname2@example.com"
+
View
39 test/unit/inbox_lt_contact_importer_test.rb
@@ -0,0 +1,39 @@
+dir = File.dirname(__FILE__)
+require "#{dir}/../test_helper"
+require 'contacts'
+
+class InboxLtContactImporterTest < ContactImporterTestCase
+ def setup
+ super
+ @account = TestAccounts[:inbox_lt]
+ end
+
+ def test_successful_login
+ Contacts.new(:inbox_lt, @account.username, @account.password)
+ end
+
+ def test_importer_fails_with_invalid_password
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:inbox_lt, @account.username, "wrong_password")
+ end
+ end
+
+ def test_importer_fails_with_blank_password
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:inbox_lt, @account.username, "")
+ end
+ end
+
+ def test_importer_fails_with_blank_username
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:inbox_lt, "", @account.password)
+ end
+ end
+
+ def test_fetch_contacts
+ contacts = Contacts.new(:inbox_lt, @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
View
39 test/unit/onelt_contact_importer_test.rb
@@ -0,0 +1,39 @@
+dir = File.dirname(__FILE__)
+require "#{dir}/../test_helper"
+require 'contacts'
+
+class OneltContactImporterTest < ContactImporterTestCase
+ def setup
+ super
+ @account = TestAccounts[:onelt]
+ end
+
+ def test_successful_login
+ Contacts.new(:onelt, @account.username, @account.password)
+ end
+
+ # def test_importer_fails_with_invalid_password
+ # assert_raise(Contacts::AuthenticationError) do
+ # Contacts.new(:onelt, @account.username, "wrong_password")
+ # end
+ # end
+
+ # def test_importer_fails_with_blank_password
+ # assert_raise(Contacts::AuthenticationError) do
+ # Contacts.new(:onelt, @account.username, "")
+ # end
+ # end
+
+ # def test_importer_fails_with_blank_username
+ # assert_raise(Contacts::AuthenticationError) do
+ # Contacts.new(:onelt, "", @account.password)
+ # end
+ # end
+
+ def test_fetch_contacts
+ contacts = Contacts.new(:onelt, @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
View
39 test/unit/seznam_contact_importer_test.rb
@@ -0,0 +1,39 @@
+dir = File.dirname(__FILE__)
+require "#{dir}/../test_helper"
+require 'contacts'
+
+class SeznamContactImporterTest < ContactImporterTestCase
+ def setup
+ super
+ @account = TestAccounts[:seznam]
+ end
+
+ def test_successful_login
+ Contacts.new(:seznam, @account.username, @account.password)
+ end
+
+ def test_importer_fails_with_invalid_password
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:seznam, @account.username, "wrong_password")
+ end
+ end
+
+ def test_importer_fails_with_blank_password
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:seznam, @account.username, "")
+ end
+ end
+
+ def test_importer_fails_with_blank_username
+ assert_raise(Contacts::AuthenticationError) do
+ Contacts.new(:seznam, "", @account.password)
+ end
+ end
+
+ def test_fetch_contacts
+ contacts = Contacts.new(:seznam, @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
Something went wrong with that request. Please try again.