mit_stalker 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/lib/mit_stalker.rb +25 -2
- data/mit_stalker.gemspec +2 -2
- data/test/mit_stalker_test.rb +18 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/mit_stalker.rb
CHANGED
@@ -75,7 +75,7 @@ module MitStalker
|
|
75
75
|
#
|
76
76
|
# Returns a single user information hash, or nil if no user has the given
|
77
77
|
# full name.
|
78
|
-
def self.
|
78
|
+
def self.refine_mitdir_response_by_name(users, full_name)
|
79
79
|
vector = name_vector(full_name)
|
80
80
|
user_base_info = users.find { |user| name_vector(user[:name]) == vector }
|
81
81
|
return nil unless user_base_info
|
@@ -88,6 +88,28 @@ module MitStalker
|
|
88
88
|
users and users.first
|
89
89
|
end
|
90
90
|
|
91
|
+
# Narrows down a MIT directory response to a single user.
|
92
|
+
#
|
93
|
+
# Returns a single user information hash, or nil if no user has the given
|
94
|
+
# e-mail.
|
95
|
+
def self.refine_mitdir_response_by_email(users, user_name)
|
96
|
+
users.each do |user|
|
97
|
+
if user[:email]
|
98
|
+
next unless user[:email].split('@').first == user_name
|
99
|
+
users = parse_mitdir_response finger(user[:alias], 'web.mit.edu')
|
100
|
+
return users && users.first
|
101
|
+
else
|
102
|
+
users = parse_mitdir_response finger(user[:alias], 'web.mit.edu')
|
103
|
+
next unless users
|
104
|
+
user = users.first
|
105
|
+
if user[:email] and user[:email].split('@').first == user_name
|
106
|
+
return user
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
91
113
|
# Retrieves information about an MIT student from an Athena username.
|
92
114
|
#
|
93
115
|
# Returns a hash containing user information, or nil if the user was not
|
@@ -101,7 +123,8 @@ module MitStalker
|
|
101
123
|
users = parse_mitdir_response finger(user_name, 'web.mit.edu')
|
102
124
|
end
|
103
125
|
|
104
|
-
user =
|
126
|
+
user = refine_mitdir_response_by_name(users, full_name)
|
127
|
+
user = refine_mitdir_response_by_email(users, user_name) unless user
|
105
128
|
user and user.merge(:full_name => full_name)
|
106
129
|
end
|
107
130
|
end
|
data/mit_stalker.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{mit_stalker}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Victor Costan"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2010-02-07}
|
10
10
|
s.description = %q{Fetches publicly available information about MIT students.}
|
11
11
|
s.email = %q{victor@zergling.net}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.textile", "lib/mit_stalker.rb"]
|
data/test/mit_stalker_test.rb
CHANGED
@@ -61,16 +61,31 @@ class MitStalkerTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def test_refine_mitdir_response_by_name
|
65
65
|
flexmock(MitStalker).should_receive(:finger).with('Y-li16', 'web.mit.edu').
|
66
|
-
and_return(fixture('single_response.txt'))
|
66
|
+
and_return(fixture('single_response.txt')).once
|
67
67
|
|
68
68
|
multi_response =
|
69
69
|
MitStalker.parse_mitdir_response fixture('multi_response.txt')
|
70
|
-
user = MitStalker.
|
70
|
+
user = MitStalker.refine_mitdir_response_by_name multi_response,
|
71
|
+
'Yan Ping Li'
|
71
72
|
assert_equal 'costan@MIT.EDU', user[:email], 'Wrong user information'
|
72
73
|
end
|
73
74
|
|
75
|
+
def test_refine_mitdir_response_by_email
|
76
|
+
flexmock(MitStalker).should_receive(:finger).with('V-costan', 'web.mit.edu').
|
77
|
+
and_return(fixture('single_response.txt')).once
|
78
|
+
flexmock(MitStalker).should_receive(:finger).with('A-li', 'web.mit.edu').
|
79
|
+
and_return(fixture('single_response2.txt')).once
|
80
|
+
|
81
|
+
mixed_response =
|
82
|
+
MitStalker.parse_mitdir_response fixture('mixed_response.txt')
|
83
|
+
user = MitStalker.refine_mitdir_response_by_email mixed_response.reverse,
|
84
|
+
'aliceli'
|
85
|
+
assert user, 'No user returned'
|
86
|
+
assert_equal 'Li, Alice', user[:name]
|
87
|
+
end
|
88
|
+
|
74
89
|
def test_from_user_name
|
75
90
|
assert_equal nil, MitStalker.from_user_name('no_such_user')
|
76
91
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mit_stalker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|