rakutenusa-blackbook 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGES.markdown +44 -0
  2. data/Manifest.txt +59 -0
  3. data/README.markdown +72 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/blackbook/exporter/base.rb +16 -0
  6. data/lib/blackbook/exporter/vcf.rb +45 -0
  7. data/lib/blackbook/exporter/xml.rb +28 -0
  8. data/lib/blackbook/importer/aol.rb +89 -0
  9. data/lib/blackbook/importer/base.rb +39 -0
  10. data/lib/blackbook/importer/csv.rb +71 -0
  11. data/lib/blackbook/importer/freenet.rb +62 -0
  12. data/lib/blackbook/importer/gmail.rb +74 -0
  13. data/lib/blackbook/importer/gmx.rb +68 -0
  14. data/lib/blackbook/importer/hotmail.rb +128 -0
  15. data/lib/blackbook/importer/page_scraper.rb +86 -0
  16. data/lib/blackbook/importer/web.de.rb +67 -0
  17. data/lib/blackbook/importer/yahoo.rb +63 -0
  18. data/lib/blackbook.rb +82 -0
  19. data/test/config/credentials.yml.example +9 -0
  20. data/test/fixtures/aol_application_page.html +566 -0
  21. data/test/fixtures/aol_bad_login_response_stage_3.html +565 -0
  22. data/test/fixtures/aol_contacts.html +102 -0
  23. data/test/fixtures/aol_login_response_stage_1.html +158 -0
  24. data/test/fixtures/aol_login_response_stage_2.html +559 -0
  25. data/test/fixtures/aol_login_response_stage_3.html +48 -0
  26. data/test/fixtures/aol_login_response_stage_4.html +404 -0
  27. data/test/fixtures/aol_new_contacts.html +431 -0
  28. data/test/fixtures/gmail.csv +3 -0
  29. data/test/fixtures/gmail_bad_login_response_stage_2.html +560 -0
  30. data/test/fixtures/gmail_contacts.html +228 -0
  31. data/test/fixtures/gmail_login_response_stage_1.html +556 -0
  32. data/test/fixtures/gmail_login_response_stage_2.html +1 -0
  33. data/test/fixtures/gmail_login_response_stage_2a.html +1 -0
  34. data/test/fixtures/gmail_login_response_stage_3.html +249 -0
  35. data/test/fixtures/gmail_redirect_body.html +10 -0
  36. data/test/fixtures/hotmail_bad_login_response_stage_2.html +31 -0
  37. data/test/fixtures/hotmail_contacts.html +262 -0
  38. data/test/fixtures/hotmail_login_response_stage_1.html +31 -0
  39. data/test/fixtures/hotmail_login_response_stage_2.html +1 -0
  40. data/test/fixtures/hotmail_login_response_stage_3.html +519 -0
  41. data/test/fixtures/hotmail_scrape_first_page.html +77 -0
  42. data/test/fixtures/hotmail_scrape_response_stage_1.html +90 -0
  43. data/test/fixtures/hotmail_scrape_response_stage_2.html +77 -0
  44. data/test/fixtures/hotmail_scrape_response_stage_3.html +0 -0
  45. data/test/fixtures/yahoo_bad_login_response_stage_2.html +443 -0
  46. data/test/fixtures/yahoo_contacts.csv +3 -0
  47. data/test/fixtures/yahoo_contacts_not_logged_in.html +432 -0
  48. data/test/fixtures/yahoo_contacts_stage_1.html +399 -0
  49. data/test/fixtures/yahoo_login_response_stage_1.html +433 -0
  50. data/test/fixtures/yahoo_login_response_stage_2.html +16 -0
  51. data/test/fixtures/yahoo_no_user_response_stage_2.html +574 -0
  52. data/test/freenet_importer_test.rb +53 -0
  53. data/test/gmx_importer_test.rb +53 -0
  54. data/test/scripts/live_test.rb +25 -0
  55. data/test/test_blackbook.rb +60 -0
  56. data/test/test_blackbook_exporter_base.rb +16 -0
  57. data/test/test_blackbook_exporter_vcf.rb +52 -0
  58. data/test/test_blackbook_exporter_xml.rb +16 -0
  59. data/test/test_blackbook_importer_aol.rb +108 -0
  60. data/test/test_blackbook_importer_base.rb +24 -0
  61. data/test/test_blackbook_importer_csv.rb +60 -0
  62. data/test/test_blackbook_importer_gmail.rb +116 -0
  63. data/test/test_blackbook_importer_hotmail.rb +165 -0
  64. data/test/test_blackbook_importer_page_scraper.rb +51 -0
  65. data/test/test_blackbook_importer_yahoo.rb +137 -0
  66. data/test/test_helper.rb +71 -0
  67. data/test/web.de_importer_test.rb +53 -0
  68. metadata +127 -0
@@ -0,0 +1,165 @@
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
+ require 'mechanize'
6
+
7
+ class TestBlackbookImporterHotmail < Test::Unit::TestCase
8
+
9
+ include TestHelper
10
+
11
+
12
+ def setup
13
+ @importer = Blackbook::Importer::Hotmail.new
14
+ @importer.options = {:username => 'user@hotmail.com', :password => 'password'}
15
+ @importer.create_agent
16
+ end
17
+
18
+ def test_bad_login
19
+ response = {'content-type' => 'text/html'}
20
+
21
+ body = load_fixture('hotmail_login_response_stage_1.html').join
22
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
23
+ @importer.agent.expects(:get).with('http://login.live.com/login.srf?id=2'
24
+ ).once.returns(page)
25
+
26
+ body = load_fixture('hotmail_bad_login_response_stage_2.html').join
27
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
28
+ @importer.agent.expects(:submit).once.returns(page)
29
+
30
+ assert_raises(Blackbook::BadCredentialsError) do
31
+ @importer.login
32
+ end
33
+
34
+ end
35
+
36
+ def test_login
37
+ response = {'content-type' => 'text/html'}
38
+
39
+ body = load_fixture('hotmail_login_response_stage_1.html').join
40
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
41
+ @importer.agent.expects(:get).with('http://login.live.com/login.srf?id=2'
42
+ ).once.returns(page)
43
+
44
+ body = load_fixture('hotmail_login_response_stage_2.html').join
45
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
46
+ @importer.agent.expects(:submit).once.returns(page)
47
+
48
+ body = load_fixture('hotmail_login_response_stage_3.html').join
49
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
50
+ @importer.agent.expects(:get).with(
51
+ 'http://www.hotmail.msn.com/cgi-bin/sbox?t=9m9!oYK!qAKigHv8qDw1X1CMCqcbK10gIMWFQjyEK5dofUz!Aneq2zVs58p30sL*Vn8LAwVDD7952o!s1iny8uLHnZxso8YLLoQo4Z3CxhDx11tpPojydwUvwNF9zLFas7&p=9ZiSOOa!3CzsA5AbkqScGrB6w0zuXf!S*UaqQfk0fTM54toklVx51mUYcS3O8JAxjQmsQiwdEBIueipsTADcMs!2RRit547E5MtOMhA6NdiUNkoRvaGsSXK*j1iKAm7Z5jpdKpvW8oSv5yNpN5mWoULuD6lUEqC7i0KHR22e3NJ95C8uGbIGfgxkCjluo7Ye0eJcGraNIAbG0$&lc=1033&id=2'
52
+ ).once.returns(page)
53
+
54
+ assert_nothing_raised do
55
+ @importer.login
56
+ end
57
+ end
58
+
59
+ def test_scrape_contacts_not_logged_in
60
+ @importer.agent.expects(:cookies).once.returns([])
61
+ assert_raises(Blackbook::BadCredentialsError) do
62
+ @importer.scrape_contacts
63
+ end
64
+ end
65
+
66
+ def test_scrape_contacts
67
+ cookie = WWW::Mechanize::Cookie.new('MSPPre', 'user@hotmail.com')
68
+ cookie.domain = 'localhost'
69
+ @importer.agent.expects(:cookies).once.returns([cookie])
70
+
71
+ response = {'content-type' => 'text/html'}
72
+ uri = URI.parse('http://by135w.bay135.mail.live.com/mail/')
73
+
74
+ body = load_fixture('hotmail_scrape_first_page.html').join
75
+ page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
76
+ @importer.instance_variable_set("@first_page", page)
77
+
78
+ body = load_fixture('hotmail_scrape_response_stage_1.html').join
79
+ page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
80
+ @importer.agent.expects(:get).with('http://by118w.bay118.mail.live.com/mail/TodayLight.aspx?&ip=10.1.106.216&d=d952&mf=0&n=1587813607').once.returns(page)
81
+
82
+ body = load_fixture('hotmail_scrape_response_stage_2.html').join
83
+ page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
84
+ @importer.agent.expects(:click).once.returns(page)
85
+
86
+ body = load_fixture('hotmail_scrape_response_stage_3.html').join
87
+ page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
88
+ @importer.agent.expects(:get).with('http://by118w.bay118.mail.live.com/mail/TodayLight.aspx?rru=inbox&n=650062209').once.returns(page)
89
+
90
+ body = load_fixture('hotmail_contacts.html').join
91
+ page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
92
+ @importer.agent.expects(:get).with('/mail/PrintShell.aspx?type=contact').once.returns(page)
93
+
94
+ assert_nothing_raised do
95
+ contacts = @importer.scrape_contacts
96
+ assert_equal 3, contacts.size
97
+
98
+ # Joe doesn't have a name
99
+ assert contacts.detect{|c| c[:email] == 'joe.user@example.com' && c[:name].nil? }
100
+
101
+ # Jane has both a name and an email
102
+ assert contacts.detect{|c| c[:email] == 'jane.user@example.com' && c[:name] == 'Jane User'}
103
+
104
+ # John doesn't have a name, just a Windows Live ID treated as a name
105
+ assert contacts.detect{|c| c[:email] == 'john.user@example.com' && c[:name].nil? }
106
+ end
107
+ end
108
+
109
+ def test_prepare
110
+ @importer.expects(:login).once
111
+ @importer.prepare
112
+ end
113
+
114
+ def test_importer_match
115
+ assert_equal false, @importer =~ nil
116
+ assert_equal false, @importer =~ {}
117
+ assert_equal false, @importer =~ {'username' => 'joe@example.com'}
118
+ assert_equal false, @importer =~ {:username => 'joe@example.com'}
119
+ assert_equal false, @importer =~ {:username => 'joe'}
120
+
121
+ domains = ["compaq.net",
122
+ "hotmail.co.jp",
123
+ "hotmail.co.uk",
124
+ "hotmail.com",
125
+ "hotmail.de",
126
+ "hotmail.fr",
127
+ "hotmail.it",
128
+ "messengeruser.com",
129
+ "msn.com",
130
+ "passport.com",
131
+ "webtv.net"]
132
+ domains.each do |domain|
133
+ assert_equal true, @importer =~ {:username => "joe@#{domain}"}
134
+ assert_equal true, @importer =~ {:username => "joe@#{domain}".upcase}
135
+ end
136
+ end
137
+
138
+
139
+ def test_login_url
140
+ assert_equal "https://login.live.com/ppsecure/post.srf", @importer.login_url
141
+ @importer.options = {:username => 'user@msn.com', :password => 'password'}
142
+ assert_equal "https://msnia.login.live.com/ppsecure/post.srf", @importer.login_url
143
+ end
144
+
145
+ def test_current_host
146
+ response = {'content-type' => 'text/html'}
147
+ page = WWW::Mechanize::Page.new(URI.parse('http://localhost/'), response, '<html></html>', code=nil, mech=nil)
148
+
149
+ importer = Blackbook::Importer::Hotmail.new
150
+ assert_nil importer.current_host
151
+ importer.create_agent
152
+ assert_nil importer.current_host
153
+ importer.agent.expects(:current_page).times(2).returns(page)
154
+ assert_equal 'http://localhost', importer.current_host
155
+ end
156
+
157
+ def test_username_domain(username = nil)
158
+ importer = Blackbook::Importer::Hotmail.new
159
+ assert_nil importer.username_domain
160
+ assert_equal 'example.com', importer.username_domain('user@example.com')
161
+ assert_equal 'example.com', @importer.username_domain('user@example.com')
162
+ assert_equal 'hotmail.com', @importer.username_domain
163
+ end
164
+
165
+ end
@@ -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,137 @@
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.co.uk'}
29
+ assert_equal true, @importer =~ {:username => 'JOE@YAHOO.COM'}
30
+ end
31
+
32
+ def test_login
33
+ response = {'content-type' => 'text/html'}
34
+
35
+ body = load_fixture('yahoo_login_response_stage_1.html').join
36
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
37
+ @importer.agent.expects(:get).with('https://login.yahoo.com/config/login_verify2?').once.returns(page)
38
+
39
+ body = load_fixture('yahoo_login_response_stage_2.html').join
40
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
41
+ @importer.agent.expects(:submit).once.returns(page)
42
+
43
+ assert_nothing_raised do
44
+ assert @importer.login
45
+ end
46
+ end
47
+
48
+ def test_bad_login
49
+ response = {'content-type' => 'text/html'}
50
+
51
+ body = load_fixture('yahoo_login_response_stage_1.html').join
52
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
53
+ @importer.agent.expects(:get).with('https://login.yahoo.com/config/login_verify2?').once.returns(page)
54
+
55
+ body = load_fixture('yahoo_bad_login_response_stage_2.html').join
56
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
57
+ @importer.agent.expects(:submit).once.returns(page)
58
+
59
+ assert_raises(Blackbook::BadCredentialsError) do
60
+ @importer.login
61
+ end
62
+ end
63
+
64
+ def test_no_such_user
65
+ response = {'content-type' => 'text/html'}
66
+
67
+ body = load_fixture('yahoo_login_response_stage_1.html').join
68
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
69
+ @importer.agent.expects(:get).with('https://login.yahoo.com/config/login_verify2?').once.returns(page)
70
+
71
+ body = load_fixture('yahoo_no_user_response_stage_2.html').join
72
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
73
+ @importer.agent.expects(:submit).once.returns(page)
74
+
75
+ assert_raises(Blackbook::BadCredentialsError) do
76
+ @importer.login
77
+ end
78
+ end
79
+
80
+ def test_scrape_contacts_raises_badcredentialerror_when_not_logged_in
81
+ response = {'content-type' => 'text/html'}
82
+ body = load_fixture('yahoo_contacts_not_logged_in.html').join
83
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
84
+ @importer.agent.expects(:get).with('http://address.yahoo.com/?1=&VPC=import_export'
85
+ ).once.returns(page)
86
+
87
+ assert_raises(Blackbook::BadCredentialsError) do
88
+ @importer.scrape_contacts
89
+ end
90
+ end
91
+
92
+ def test_scrape_contacts
93
+ response = {'content-type' => 'text/html'}
94
+ body = load_fixture('yahoo_contacts_stage_1.html').join
95
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
96
+ @importer.agent.expects(:get).with('http://address.yahoo.com/?1=&VPC=import_export'
97
+ ).once.returns(page)
98
+
99
+ response = {'content-type' => 'text/csv; charset=UTF-8'}
100
+ body = load_fixture('yahoo_contacts.csv').join
101
+ page = WWW::Mechanize::File.new(uri=nil, response, body, code=nil)
102
+ @importer.agent.expects(:submit).once.returns(page)
103
+
104
+ assert_nothing_raised do
105
+ contacts = @importer.scrape_contacts
106
+ assert_equal 2, contacts.size
107
+ assert contacts.detect{|c| c[:email] == 'joe.user@example.com'}
108
+ assert contacts.detect{|c| c[:name] == 'Joe User'}
109
+ assert contacts.detect{|c| c[:email] == 'jane.user@example.com'}
110
+ assert contacts.detect{|c| c[:name] == 'Jane User'}
111
+ end
112
+ end
113
+
114
+
115
+ def test_scrape_contacts_with_invalid_regex_character_in_email
116
+ response = {'content-type' => 'text/html'}
117
+ body = load_fixture('yahoo_contacts_stage_1.html').join
118
+ page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
119
+ @importer.agent.expects(:get).with('http://address.yahoo.com/?1=&VPC=import_export'
120
+ ).once.returns(page)
121
+
122
+ response = {'content-type' => 'text/csv; charset=UTF-8'}
123
+ body = load_fixture('yahoo_contacts.csv').join
124
+ body.gsub!(/joe\.user\@example\.com/, "joe+user@example.com")
125
+ page = WWW::Mechanize::File.new(uri=nil, response, body, code=nil)
126
+ @importer.agent.expects(:submit).once.returns(page)
127
+
128
+ assert_nothing_raised do
129
+ contacts = @importer.scrape_contacts
130
+ assert_equal 2, contacts.size
131
+ assert contacts.detect{|c| c[:email] == 'joe+user@example.com'}
132
+ assert contacts.detect{|c| c[:name] == 'Joe User'}
133
+ assert contacts.detect{|c| c[:email] == 'jane.user@example.com'}
134
+ assert contacts.detect{|c| c[:name] == 'Jane User'}
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,71 @@
1
+ require 'ruby-debug'
2
+
3
+ module TestHelper
4
+
5
+ def fixture_path(name)
6
+ "#{File.dirname(__FILE__)}/fixtures/#{name}"
7
+ end
8
+
9
+ def load_fixture(file)
10
+ IO.readlines(fixture_path(file))
11
+ end
12
+
13
+ def fixture_file(name)
14
+ File.new fixture_path(name)
15
+ end
16
+
17
+ end
18
+
19
+ module Net #:nodoc:
20
+ class HTTP #:nodoc:
21
+
22
+ extend TestHelper
23
+
24
+ RESPONSES = {}
25
+
26
+ def self.responses=(r)
27
+ RESPONSES.clear
28
+ r.each{|k,v| RESPONSES[k] = v}
29
+ end
30
+
31
+
32
+ alias :old_net_http_request :request
33
+
34
+ def request(req, body = nil, &block)
35
+ prot = use_ssl ? "https" : "http"
36
+ uri_cls = use_ssl ? URI::HTTPS : URI::HTTP
37
+ query = req.path.split('?',2)
38
+ opts = {:host => self.address,
39
+ :port => self.port, :path => query[0]}
40
+ opts[:query] = query[1] if query[1]
41
+ uri = uri_cls.build(opts)
42
+ raise ArgumentError.new("#{req.method} method to #{uri} not being handled in testing")
43
+ end
44
+
45
+ def connect
46
+ raise ArgumentError.new("connect not being handled in testing")
47
+ end
48
+ end
49
+ end
50
+
51
+ plugin_root = "#{ File.dirname(__FILE__) }/.."
52
+
53
+ require 'rubygems'
54
+ require 'mocha'
55
+
56
+ module BlackbookExtensions
57
+ module TestHelper
58
+ class Credentials
59
+ attr_accessor :network, :config
60
+
61
+ def initialize(network)
62
+ self.network = network.to_s
63
+ self.config = YAML.load_file( File.join(File.dirname(__FILE__), "config/credentials.yml") )
64
+ end
65
+
66
+ def get
67
+ [ self.config[self.network]["username"], self.config[self.network]["password"] ]
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ context "The Web.de importer" do
4
+
5
+ setup do
6
+ @username, @password = BlackbookExtensions::TestHelper::Credentials.new(:webde).get
7
+
8
+ @importer = Blackbook::Importer::WebDE.new
9
+ @importer.create_agent
10
+ end
11
+
12
+ specify "should match emails" do
13
+ @importer.=~(nil).should.not.be
14
+ @importer.=~({}).should.not.be
15
+ @importer.=~({ 'username' => "john@foo.com" }).should.not.be
16
+ @importer.=~({ :username => "john@foo.com" }).should.not.be
17
+ @importer.=~({ :username => "john" }).should.not.be
18
+ @importer.=~({ :username => "john@web.de" }).should.be
19
+ @importer.=~({ :username => "JOHN@WEB.DE" }).should.be
20
+ end
21
+
22
+ specify "should be able to login with correct credentials" do
23
+ should.not.raise Exception do
24
+ login(@username, @password)
25
+ end
26
+ end
27
+
28
+ specify "should raise BadCredentialsError on login with wrong credentials" do
29
+ should.raise Blackbook::BadCredentialsError do
30
+ login
31
+ end
32
+ end
33
+
34
+ specify "should raise BadCredentialsError on login with correct username and wrong password" do
35
+ should.raise Blackbook::BadCredentialsError do
36
+ login(@username)
37
+ end
38
+ end
39
+
40
+ specify "should able to get contacts" do
41
+ login(@username, @password)
42
+
43
+ contacts = @importer.scrape_contacts
44
+ contacts.should.not.be.empty
45
+ contacts.should.be.all { |contact| contact.is_a? Hash }
46
+ end
47
+
48
+ private
49
+ def login(username = "foo", password = "bar")
50
+ @importer.options = { :username => username, :password => password }
51
+ @importer.login
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rakutenusa-blackbook
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.12
5
+ platform: ruby
6
+ authors:
7
+ - Rany Keddo
8
+ - Brian Cardarella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-03-10 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: TODO
18
+ email: bcardarella@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - CHANGES.markdown
27
+ - Manifest.txt
28
+ - README.markdown
29
+ - VERSION.yml
30
+ - lib/blackbook
31
+ - lib/blackbook/exporter
32
+ - lib/blackbook/exporter/base.rb
33
+ - lib/blackbook/exporter/vcf.rb
34
+ - lib/blackbook/exporter/xml.rb
35
+ - lib/blackbook/importer
36
+ - lib/blackbook/importer/aol.rb
37
+ - lib/blackbook/importer/base.rb
38
+ - lib/blackbook/importer/csv.rb
39
+ - lib/blackbook/importer/freenet.rb
40
+ - lib/blackbook/importer/gmail.rb
41
+ - lib/blackbook/importer/gmx.rb
42
+ - lib/blackbook/importer/hotmail.rb
43
+ - lib/blackbook/importer/page_scraper.rb
44
+ - lib/blackbook/importer/web.de.rb
45
+ - lib/blackbook/importer/yahoo.rb
46
+ - lib/blackbook.rb
47
+ - test/config
48
+ - test/config/credentials.yml.example
49
+ - test/fixtures
50
+ - test/fixtures/aol_application_page.html
51
+ - test/fixtures/aol_bad_login_response_stage_3.html
52
+ - test/fixtures/aol_contacts.html
53
+ - test/fixtures/aol_login_response_stage_1.html
54
+ - test/fixtures/aol_login_response_stage_2.html
55
+ - test/fixtures/aol_login_response_stage_3.html
56
+ - test/fixtures/aol_login_response_stage_4.html
57
+ - test/fixtures/aol_new_contacts.html
58
+ - test/fixtures/gmail.csv
59
+ - test/fixtures/gmail_bad_login_response_stage_2.html
60
+ - test/fixtures/gmail_contacts.html
61
+ - test/fixtures/gmail_login_response_stage_1.html
62
+ - test/fixtures/gmail_login_response_stage_2.html
63
+ - test/fixtures/gmail_login_response_stage_2a.html
64
+ - test/fixtures/gmail_login_response_stage_3.html
65
+ - test/fixtures/gmail_redirect_body.html
66
+ - test/fixtures/hotmail_bad_login_response_stage_2.html
67
+ - test/fixtures/hotmail_contacts.html
68
+ - test/fixtures/hotmail_login_response_stage_1.html
69
+ - test/fixtures/hotmail_login_response_stage_2.html
70
+ - test/fixtures/hotmail_login_response_stage_3.html
71
+ - test/fixtures/hotmail_scrape_first_page.html
72
+ - test/fixtures/hotmail_scrape_response_stage_1.html
73
+ - test/fixtures/hotmail_scrape_response_stage_2.html
74
+ - test/fixtures/hotmail_scrape_response_stage_3.html
75
+ - test/fixtures/yahoo_bad_login_response_stage_2.html
76
+ - test/fixtures/yahoo_contacts.csv
77
+ - test/fixtures/yahoo_contacts_not_logged_in.html
78
+ - test/fixtures/yahoo_contacts_stage_1.html
79
+ - test/fixtures/yahoo_login_response_stage_1.html
80
+ - test/fixtures/yahoo_login_response_stage_2.html
81
+ - test/fixtures/yahoo_no_user_response_stage_2.html
82
+ - test/freenet_importer_test.rb
83
+ - test/gmx_importer_test.rb
84
+ - test/scripts
85
+ - test/scripts/live_test.rb
86
+ - test/test_blackbook.rb
87
+ - test/test_blackbook_exporter_base.rb
88
+ - test/test_blackbook_exporter_vcf.rb
89
+ - test/test_blackbook_exporter_xml.rb
90
+ - test/test_blackbook_importer_aol.rb
91
+ - test/test_blackbook_importer_base.rb
92
+ - test/test_blackbook_importer_csv.rb
93
+ - test/test_blackbook_importer_gmail.rb
94
+ - test/test_blackbook_importer_hotmail.rb
95
+ - test/test_blackbook_importer_page_scraper.rb
96
+ - test/test_blackbook_importer_yahoo.rb
97
+ - test/test_helper.rb
98
+ - test/web.de_importer_test.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/bcardarella/blackbook
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --inline-source
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ version:
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.2.0
123
+ signing_key:
124
+ specification_version: 2
125
+ summary: TODO
126
+ test_files: []
127
+