address_book 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "address_book/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "address_book"
7
+ s.version = AddressBook::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Igor Sidorov"]
10
+ s.email = ["igor.cug@gmail.com"]
11
+ s.homepage = "https://github.com/binarycode/address_book"
12
+ s.summary = "Address book export"
13
+ s.description = "Exports address books from various e-mail services (Gmail, Mail.ru, Yandex, Rambler)"
14
+
15
+ s.add_dependency "gdata"
16
+ s.add_dependency "gdata19"
17
+ s.add_dependency "nokogiri"
18
+ s.add_dependency "patron"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.dirname(__FILE__) + "/address_book/"
2
+
3
+ require "base.rb"
4
+ require "error.rb"
5
+ require "mailru.rb"
6
+ require "rambler.rb"
7
+ require "yandex.rb"
8
+ require "gmail.rb"
@@ -0,0 +1,34 @@
1
+ require "patron"
2
+ require "nokogiri"
3
+
4
+ class AddressBook
5
+ @@domains = {}
6
+
7
+ def self.register_service(domains, klass)
8
+ Array(domains).each do |domain|
9
+ @@domains[domain] = klass
10
+ end
11
+ end
12
+
13
+ def self.export(login, password)
14
+ domain = extract_domain login
15
+ klass = @@domains[domain]
16
+ if klass
17
+ klass.new(login, password).contacts
18
+ else
19
+ raise ServiceNotFound, "No service registered for #{domain.inspect} domain"
20
+ end
21
+ end
22
+
23
+ def self.extract_domain(login)
24
+ login.split("@").last
25
+ end
26
+
27
+ class Base
28
+ attr_accessor :contacts
29
+
30
+ def session
31
+ @session ||= Patron::Session.new.handle_cookies
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ class AddressBook
2
+ class ServiceNotFound < StandardError
3
+ end
4
+
5
+ class AuthenticationError < StandardError
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require "gdata"
2
+
3
+ class AddressBook
4
+ class Gmail < Base
5
+ ADDRESS_BOOK_URL = "http://www.google.com/m8/feeds/contacts/default/full/?max-results=1000"
6
+
7
+ AddressBook.register_service "gmail.com", self
8
+
9
+ def initialize(login, password)
10
+ client = GData::Client::Contacts.new
11
+ client.clientlogin login, password
12
+
13
+ self.contacts = Nokogiri::XML.parse(client.get(ADDRESS_BOOK_URL).body).css("entry").map do |e|
14
+ name = (e > "title").first.content
15
+ email = e.at_xpath("gd:email")[:address]
16
+ [name, email]
17
+ end
18
+ rescue GData::Client::AuthorizationError
19
+ raise AuthenticationError, "Username or password are incorrect"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require "csv"
2
+
3
+ class AddressBook
4
+ class MailRu < Base
5
+ LOGIN_URL = "https://auth.mail.ru/cgi-bin/auth"
6
+ ADDRESS_BOOK_URL = "http://e.mail.ru/cgi-bin/abexport/addressbook.csv"
7
+
8
+ AddressBook.register_service %w(mail.ru inbox.ru bk.ru list.ru), self
9
+
10
+ def initialize(login, password)
11
+ response = session.post LOGIN_URL, { :Login => login, :Domain => AddressBook.extract_domain(login), :Password => password }
12
+
13
+ if response.body.index "fail=1"
14
+ raise AuthenticationError, "Username or password are incorrect"
15
+ end
16
+
17
+ response = session.post ADDRESS_BOOK_URL, { :confirm => 1, :abtype => 6 }
18
+
19
+ self.contacts = CSV.parse(response.body).drop(1).map do |row|
20
+ [row[0], row[4]]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ class AddressBook
2
+ class Rambler < Base
3
+ LOGIN_URL = "http://id.rambler.ru/script/auth.cgi"
4
+ ADDRESS_BOOK_URL = "http://mail.rambler.ru/mail/contacts.cgi"
5
+
6
+ AddressBook.register_service %w(rambler.ru lenta.ru myrambler.ru autorambler.ru ro.ru r0.ru), self
7
+
8
+ def initialize(login, password)
9
+ response = session.post LOGIN_URL, { :login => login, :domain => AddressBook.extract_domain(login), :passw => password }
10
+
11
+ if response.body.index "errorbox"
12
+ raise AuthenticationError, "Username or password are incorrect"
13
+ end
14
+
15
+ response = session.get ADDRESS_BOOK_URL
16
+
17
+ self.contacts = Nokogiri::XML.parse(response.body).css("#mailbox-list tbody tr").map do |e|
18
+ name = e.at_css(".mtbox-name").content.strip
19
+ email = e.at_css(".mtbox-email").content.strip
20
+ [name, email]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class AddressBook
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ class AddressBook
2
+ class Yandex < Base
3
+ LOGIN_URL = "http://passport.yandex.ru/passport?mode=auth"
4
+ ADDRESS_BOOK_URL = "https://mail.yandex.ru/neo2/handlers/handlers.jsx"
5
+
6
+ AddressBook.register_service "yandex.ru", self
7
+
8
+ def initialize(login, password)
9
+ response = session.post LOGIN_URL, { :login => login, :passwd => password }
10
+
11
+ if response.body.index "b-login-error"
12
+ raise AuthenticationError, "Username or password are incorrect"
13
+ end
14
+
15
+ response = session.post ADDRESS_BOOK_URL, { :_handlers => "abook-contacts", :all => "yes" }
16
+
17
+ self.contacts = Nokogiri::XML.parse(response.body).css("contact").map do |contact|
18
+ name = contact.at_css "name"
19
+ email = contact.at_css "email"
20
+ [name.values.join(" "), email.content]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: address_book
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Igor Sidorov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-28 00:00:00.000000000 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gdata
17
+ requirement: &77369070 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *77369070
26
+ - !ruby/object:Gem::Dependency
27
+ name: gdata19
28
+ requirement: &77368860 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *77368860
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ requirement: &77368650 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *77368650
48
+ - !ruby/object:Gem::Dependency
49
+ name: patron
50
+ requirement: &77368440 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *77368440
59
+ description: Exports address books from various e-mail services (Gmail, Mail.ru, Yandex,
60
+ Rambler)
61
+ email:
62
+ - igor.cug@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - Rakefile
70
+ - address_book.gemspec
71
+ - lib/address_book.rb
72
+ - lib/address_book/base.rb
73
+ - lib/address_book/error.rb
74
+ - lib/address_book/gmail.rb
75
+ - lib/address_book/mailru.rb
76
+ - lib/address_book/rambler.rb
77
+ - lib/address_book/version.rb
78
+ - lib/address_book/yandex.rb
79
+ has_rdoc: true
80
+ homepage: https://github.com/binarycode/address_book
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.6.2
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Address book export
104
+ test_files: []