blackbook 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/Manifest.txt +55 -0
- data/README.txt +71 -0
- data/Rakefile +38 -0
- data/init.rb +1 -0
- data/lib/blackbook.rb +80 -0
- data/lib/blackbook/exporter/base.rb +16 -0
- data/lib/blackbook/exporter/vcf.rb +45 -0
- data/lib/blackbook/exporter/xml.rb +28 -0
- data/lib/blackbook/importer/aol.rb +74 -0
- data/lib/blackbook/importer/base.rb +39 -0
- data/lib/blackbook/importer/csv.rb +61 -0
- data/lib/blackbook/importer/gmail.rb +59 -0
- data/lib/blackbook/importer/hotmail.rb +125 -0
- data/lib/blackbook/importer/page_scraper.rb +86 -0
- data/lib/blackbook/importer/yahoo.rb +61 -0
- data/test/fixtures/aol_bad_login_response_stage_3.html +565 -0
- data/test/fixtures/aol_contacts.html +90 -0
- data/test/fixtures/aol_login_response_stage_1.html +158 -0
- data/test/fixtures/aol_login_response_stage_2.html +559 -0
- data/test/fixtures/aol_login_response_stage_3.html +61 -0
- data/test/fixtures/aol_login_response_stage_4.html +48 -0
- data/test/fixtures/aol_login_response_stage_5.html +404 -0
- data/test/fixtures/gmail.csv +3 -0
- data/test/fixtures/gmail_bad_login_response_stage_2.html +560 -0
- data/test/fixtures/gmail_contacts.html +228 -0
- data/test/fixtures/gmail_login_response_stage_1.html +556 -0
- data/test/fixtures/gmail_login_response_stage_2.html +1 -0
- data/test/fixtures/gmail_login_response_stage_3.html +249 -0
- data/test/fixtures/hotmail_bad_login_response_stage_2.html +31 -0
- data/test/fixtures/hotmail_contacts.html +132 -0
- data/test/fixtures/hotmail_login_response_stage_1.html +31 -0
- data/test/fixtures/hotmail_login_response_stage_2.html +1 -0
- data/test/fixtures/hotmail_login_response_stage_3.html +380 -0
- data/test/fixtures/yahoo_bad_login_response_stage_2.html +443 -0
- data/test/fixtures/yahoo_contacts.csv +3 -0
- data/test/fixtures/yahoo_contacts_not_logged_in.html +432 -0
- data/test/fixtures/yahoo_contacts_stage_1.html +399 -0
- data/test/fixtures/yahoo_login_response_stage_1.html +433 -0
- data/test/fixtures/yahoo_login_response_stage_2.html +16 -0
- data/test/scripts/live_test.rb +25 -0
- data/test/test_blackbook.rb +60 -0
- data/test/test_blackbook_exporter_base.rb +16 -0
- data/test/test_blackbook_exporter_vcf.rb +52 -0
- data/test/test_blackbook_exporter_xml.rb +16 -0
- data/test/test_blackbook_importer_aol.rb +107 -0
- data/test/test_blackbook_importer_base.rb +24 -0
- data/test/test_blackbook_importer_csv.rb +60 -0
- data/test/test_blackbook_importer_gmail.rb +96 -0
- data/test/test_blackbook_importer_hotmail.rb +143 -0
- data/test/test_blackbook_importer_page_scraper.rb +51 -0
- data/test/test_blackbook_importer_yahoo.rb +97 -0
- data/test/test_helper.rb +47 -0
- data/vendor/plugins/blackbook/lib/autotest/blackbook.rb +27 -0
- data/vendor/plugins/blackbook/lib/autotest/discover.rb +3 -0
- metadata +147 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'lib', 'blackbook.rb' )
|
2
|
+
require File.join( File.dirname(__FILE__), 'test_helper.rb' )
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class TestBlackbookImporterPageScraper < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@scraper = Blackbook::Importer::PageScraper.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_mechanize_patch_to_absolute_uri
|
15
|
+
@scraper.create_agent
|
16
|
+
response = {'content-type' => 'text/html'}
|
17
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, '<html></html>', code=nil, mech=nil)
|
18
|
+
url = "http://localhost/?arg=val&jank=AAA%3D"
|
19
|
+
assert_equal URI.parse(url), @scraper.agent.send(:to_absolute_uri, url)
|
20
|
+
# pattern of odd URL created by javascript validator in AOL webmail login
|
21
|
+
url = "http://localhost/?arg=val&jank=AAA%3D%3D"
|
22
|
+
assert_equal URI.parse(url), @scraper.agent.send(:to_absolute_uri, url)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_agent
|
26
|
+
agent = nil
|
27
|
+
assert_nothing_raised do
|
28
|
+
agent = @scraper.create_agent
|
29
|
+
end
|
30
|
+
assert_equal agent, @scraper.agent
|
31
|
+
assert_equal true, agent.is_a?(WWW::Mechanize)
|
32
|
+
assert_equal "Mozilla/4.0 (compatible; Blackbook #{Blackbook::VERSION})", agent.user_agent
|
33
|
+
assert_equal false, agent.keep_alive
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_strip_html
|
37
|
+
assert_equal '', @scraper.strip_html('<foo></foo>')
|
38
|
+
assert_equal 'bar', @scraper.strip_html('<foo>bar</foo>')
|
39
|
+
assert_equal 'bar', @scraper.strip_html('bar</foo>')
|
40
|
+
assert_equal 'bar', @scraper.strip_html('<foo>bar')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_fetch_contacts!
|
44
|
+
@scraper.expects(:create_agent).once
|
45
|
+
@scraper.expects(:prepare).once
|
46
|
+
@scraper.expects(:scrape_contacts).once
|
47
|
+
assert_nothing_raised do
|
48
|
+
agent = @scraper.fetch_contacts!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '../lib/blackbook.rb' )
|
2
|
+
require File.join( File.dirname(__FILE__), 'test_helper.rb' )
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class TestBlackbookImporterYahoo < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@importer = Blackbook::Importer::Yahoo.new
|
12
|
+
@importer.options = {:username => 'user@yahoo.com', :password => 'password'}
|
13
|
+
@importer.create_agent
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_prepare
|
17
|
+
@importer.expects(:login).once
|
18
|
+
@importer.prepare
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_importer_match
|
22
|
+
assert_equal false, @importer =~ nil
|
23
|
+
assert_equal false, @importer =~ {}
|
24
|
+
assert_equal false, @importer =~ {'username' => 'joe@example.com'}
|
25
|
+
assert_equal false, @importer =~ {:username => 'joe@example.com'}
|
26
|
+
assert_equal false, @importer =~ {:username => 'joe'}
|
27
|
+
assert_equal true, @importer =~ {:username => 'joe@yahoo.com'}
|
28
|
+
assert_equal true, @importer =~ {:username => 'JOE@YAHOO.COM'}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_login
|
32
|
+
response = {'content-type' => 'text/html'}
|
33
|
+
|
34
|
+
body = load_fixture('yahoo_login_response_stage_1.html').join
|
35
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
36
|
+
@importer.agent.expects(:get).with('https://login.yahoo.com/config/login_verify2?').once.returns(page)
|
37
|
+
|
38
|
+
body = load_fixture('yahoo_login_response_stage_2.html').join
|
39
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
40
|
+
@importer.agent.expects(:submit).once.returns(page)
|
41
|
+
|
42
|
+
assert_nothing_raised do
|
43
|
+
assert @importer.login
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_bad_login
|
48
|
+
response = {'content-type' => 'text/html'}
|
49
|
+
|
50
|
+
body = load_fixture('yahoo_login_response_stage_1.html').join
|
51
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
52
|
+
@importer.agent.expects(:get).with('https://login.yahoo.com/config/login_verify2?').once.returns(page)
|
53
|
+
|
54
|
+
body = load_fixture('yahoo_bad_login_response_stage_2.html').join
|
55
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
56
|
+
@importer.agent.expects(:submit).once.returns(page)
|
57
|
+
|
58
|
+
assert_raises(Blackbook::BadCredentialsError) do
|
59
|
+
@importer.login
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_scrape_contacts_raises_badcredentialerror_when_not_logged_in
|
64
|
+
response = {'content-type' => 'text/html'}
|
65
|
+
body = load_fixture('yahoo_contacts_not_logged_in.html').join
|
66
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
67
|
+
@importer.agent.expects(:get).with('http://address.yahoo.com/?1=&VPC=import_export'
|
68
|
+
).once.returns(page)
|
69
|
+
|
70
|
+
assert_raises(Blackbook::BadCredentialsError) do
|
71
|
+
@importer.scrape_contacts
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_scrape_contacts
|
76
|
+
response = {'content-type' => 'text/html'}
|
77
|
+
body = load_fixture('yahoo_contacts_stage_1.html').join
|
78
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
79
|
+
@importer.agent.expects(:get).with('http://address.yahoo.com/?1=&VPC=import_export'
|
80
|
+
).once.returns(page)
|
81
|
+
|
82
|
+
response = {'content-type' => 'text/csv; charset=UTF-8'}
|
83
|
+
body = load_fixture('yahoo_contacts.csv').join
|
84
|
+
page = WWW::Mechanize::File.new(uri=nil, response, body, code=nil)
|
85
|
+
@importer.agent.expects(:submit).once.returns(page)
|
86
|
+
|
87
|
+
assert_nothing_raised do
|
88
|
+
contacts = @importer.scrape_contacts
|
89
|
+
assert_equal 2, contacts.size
|
90
|
+
assert contacts.detect{|c| c[:email] == 'joe.user@example.com'}
|
91
|
+
assert contacts.detect{|c| c[:name] == 'Joe User'}
|
92
|
+
assert contacts.detect{|c| c[:email] == 'jane.user@example.com'}
|
93
|
+
assert contacts.detect{|c| c[:name] == 'Jane User'}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module TestHelper
|
2
|
+
|
3
|
+
def fixture_path(name)
|
4
|
+
"#{File.dirname(__FILE__)}/fixtures/#{name}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def load_fixture(file)
|
8
|
+
IO.readlines(fixture_path(file))
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture_file(name)
|
12
|
+
File.new fixture_path(name)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module Net #:nodoc:
|
18
|
+
class HTTP #:nodoc:
|
19
|
+
|
20
|
+
extend TestHelper
|
21
|
+
|
22
|
+
RESPONSES = {}
|
23
|
+
|
24
|
+
def self.responses=(r)
|
25
|
+
RESPONSES.clear
|
26
|
+
r.each{|k,v| RESPONSES[k] = v}
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
alias :old_net_http_request :request
|
31
|
+
|
32
|
+
def request(req, body = nil, &block)
|
33
|
+
prot = use_ssl ? "https" : "http"
|
34
|
+
uri_cls = use_ssl ? URI::HTTPS : URI::HTTP
|
35
|
+
query = req.path.split('?',2)
|
36
|
+
opts = {:host => self.address,
|
37
|
+
:port => self.port, :path => query[0]}
|
38
|
+
opts[:query] = query[1] if query[1]
|
39
|
+
uri = uri_cls.build(opts)
|
40
|
+
raise ArgumentError.new("#{req.method} method to #{uri} not being handled in testing")
|
41
|
+
end
|
42
|
+
|
43
|
+
def connect
|
44
|
+
raise ArgumentError.new("connect not being handled in testing")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'autotest'
|
2
|
+
|
3
|
+
class Autotest::Blackbook < Autotest
|
4
|
+
|
5
|
+
def initialize # :nodoc:
|
6
|
+
super
|
7
|
+
@exceptions = /\.svn|\.html/
|
8
|
+
@test_mappings = {
|
9
|
+
%r%^lib/blackbook/([^\/]+)/([^\/]+)\.rb$% => proc { |_, m|
|
10
|
+
["test/test_blackbook_#{m[1]}_#{m[2]}.rb"]
|
11
|
+
},
|
12
|
+
%r%^lib/blackbook.rb$% => proc { |_, m|
|
13
|
+
["test/test_blackbook.rb"]
|
14
|
+
},
|
15
|
+
%r%^test/test_blackbook_.*\.rb$% => proc { |filename, _|
|
16
|
+
filename
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def path_to_classname(s)
|
22
|
+
f = s.sub(/test\/(.+).rb$/, '\1')
|
23
|
+
f = f.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
|
24
|
+
f.join('::')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blackbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Contentfree
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-02-01 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.0
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: fastercsv
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.2.0
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.0
|
41
|
+
version:
|
42
|
+
description: "== DESCRIPTION: Blackbook automates the nitty-gritty of importing contacts from various services and files and exporting them as VCard, XML, or simple Hash. Utilize those contacts from services like AOL, GMail, Yahoo Mail, Hotmail or CSV to help your social networking site become GIGANTIC overnight! You'll be able to get big and sell for millions before anyone figures out it's just like every other social network."
|
43
|
+
email: dave.myron@contentfree.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
files:
|
53
|
+
- History.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- README.txt
|
56
|
+
- Rakefile
|
57
|
+
- init.rb
|
58
|
+
- lib/blackbook.rb
|
59
|
+
- lib/blackbook/exporter/base.rb
|
60
|
+
- lib/blackbook/exporter/vcf.rb
|
61
|
+
- lib/blackbook/exporter/xml.rb
|
62
|
+
- lib/blackbook/importer/aol.rb
|
63
|
+
- lib/blackbook/importer/base.rb
|
64
|
+
- lib/blackbook/importer/csv.rb
|
65
|
+
- lib/blackbook/importer/gmail.rb
|
66
|
+
- lib/blackbook/importer/hotmail.rb
|
67
|
+
- lib/blackbook/importer/page_scraper.rb
|
68
|
+
- lib/blackbook/importer/yahoo.rb
|
69
|
+
- test/fixtures/aol_bad_login_response_stage_3.html
|
70
|
+
- test/fixtures/aol_contacts.html
|
71
|
+
- test/fixtures/aol_login_response_stage_1.html
|
72
|
+
- test/fixtures/aol_login_response_stage_2.html
|
73
|
+
- test/fixtures/aol_login_response_stage_3.html
|
74
|
+
- test/fixtures/aol_login_response_stage_4.html
|
75
|
+
- test/fixtures/aol_login_response_stage_5.html
|
76
|
+
- test/fixtures/gmail.csv
|
77
|
+
- test/fixtures/gmail_bad_login_response_stage_2.html
|
78
|
+
- test/fixtures/gmail_contacts.html
|
79
|
+
- test/fixtures/gmail_login_response_stage_1.html
|
80
|
+
- test/fixtures/gmail_login_response_stage_2.html
|
81
|
+
- test/fixtures/gmail_login_response_stage_3.html
|
82
|
+
- test/fixtures/hotmail_bad_login_response_stage_2.html
|
83
|
+
- test/fixtures/hotmail_contacts.html
|
84
|
+
- test/fixtures/hotmail_login_response_stage_1.html
|
85
|
+
- test/fixtures/hotmail_login_response_stage_2.html
|
86
|
+
- test/fixtures/hotmail_login_response_stage_3.html
|
87
|
+
- test/fixtures/yahoo_bad_login_response_stage_2.html
|
88
|
+
- test/fixtures/yahoo_contacts.csv
|
89
|
+
- test/fixtures/yahoo_contacts_not_logged_in.html
|
90
|
+
- test/fixtures/yahoo_contacts_stage_1.html
|
91
|
+
- test/fixtures/yahoo_login_response_stage_1.html
|
92
|
+
- test/fixtures/yahoo_login_response_stage_2.html
|
93
|
+
- test/scripts/live_test.rb
|
94
|
+
- test/test_blackbook.rb
|
95
|
+
- test/test_blackbook_exporter_base.rb
|
96
|
+
- test/test_blackbook_exporter_vcf.rb
|
97
|
+
- test/test_blackbook_exporter_xml.rb
|
98
|
+
- test/test_blackbook_importer_aol.rb
|
99
|
+
- test/test_blackbook_importer_base.rb
|
100
|
+
- test/test_blackbook_importer_csv.rb
|
101
|
+
- test/test_blackbook_importer_gmail.rb
|
102
|
+
- test/test_blackbook_importer_hotmail.rb
|
103
|
+
- test/test_blackbook_importer_page_scraper.rb
|
104
|
+
- test/test_blackbook_importer_yahoo.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
- vendor/plugins/blackbook/lib/autotest/blackbook.rb
|
107
|
+
- vendor/plugins/blackbook/lib/autotest/discover.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://rubyforge.org/projects/contentfree/
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options:
|
112
|
+
- --main
|
113
|
+
- README.txt
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: "0"
|
121
|
+
version:
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: "0"
|
127
|
+
version:
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project: contentfree
|
131
|
+
rubygems_version: 1.0.1
|
132
|
+
signing_key:
|
133
|
+
specification_version: 2
|
134
|
+
summary: Blackbook handles the nitty-gritty of importing contacts from various service providers and contact lists and exporting them in a useful format.
|
135
|
+
test_files:
|
136
|
+
- test/test_blackbook_importer_aol.rb
|
137
|
+
- test/test_blackbook_importer_csv.rb
|
138
|
+
- test/test_blackbook_importer_gmail.rb
|
139
|
+
- test/test_blackbook_importer_yahoo.rb
|
140
|
+
- test/test_blackbook_exporter_base.rb
|
141
|
+
- test/test_blackbook_exporter_vcf.rb
|
142
|
+
- test/test_blackbook_exporter_xml.rb
|
143
|
+
- test/test_blackbook_importer_page_scraper.rb
|
144
|
+
- test/test_helper.rb
|
145
|
+
- test/test_blackbook_importer_hotmail.rb
|
146
|
+
- test/test_blackbook.rb
|
147
|
+
- test/test_blackbook_importer_base.rb
|