cmu_person 0.0.1 → 0.0.2
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/.travis.yml +5 -0
- data/Gemfile.lock +11 -11
- data/README.markdown +1 -0
- data/cmu_person.gemspec +3 -4
- data/lib/cmu_person/person.rb +64 -65
- metadata +49 -12
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -8,17 +8,17 @@ GEM
|
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.1.3)
|
11
|
-
net-ldap (0.
|
12
|
-
redcarpet (2.
|
13
|
-
rspec (2.
|
14
|
-
rspec-core (~> 2.
|
15
|
-
rspec-expectations (~> 2.
|
16
|
-
rspec-mocks (~> 2.
|
17
|
-
rspec-core (2.
|
18
|
-
rspec-expectations (2.
|
19
|
-
diff-lcs (~> 1.1.
|
20
|
-
rspec-mocks (2.
|
21
|
-
yard (0.
|
11
|
+
net-ldap (0.3.1)
|
12
|
+
redcarpet (2.1.1)
|
13
|
+
rspec (2.10.0)
|
14
|
+
rspec-core (~> 2.10.0)
|
15
|
+
rspec-expectations (~> 2.10.0)
|
16
|
+
rspec-mocks (~> 2.10.0)
|
17
|
+
rspec-core (2.10.0)
|
18
|
+
rspec-expectations (2.10.0)
|
19
|
+
diff-lcs (~> 1.1.3)
|
20
|
+
rspec-mocks (2.10.1)
|
21
|
+
yard (0.8.1)
|
22
22
|
|
23
23
|
PLATFORMS
|
24
24
|
ruby
|
data/README.markdown
CHANGED
data/cmu_person.gemspec
CHANGED
@@ -3,25 +3,24 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'cmu_person'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.2'
|
7
7
|
s.author = 'Seth Vargo'
|
8
8
|
s.email = 'sethvargo@gmail.com'
|
9
9
|
s.homepage = 'https://github.com/sethvargo/cmu_person'
|
10
10
|
s.summary = %q{A simple interface for searching CMU LDAP directory}
|
11
11
|
s.description = %q{This tool is used to search Carnegie Mellon's LDAP directory. Provide an Andrew ID and this will automatically parse the results and return them in a readable format.}
|
12
12
|
|
13
|
-
s.rubyforge_project = 'cmu_person'
|
14
|
-
|
15
13
|
s.files = `git ls-files`.split("\n")
|
16
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
16
|
s.require_paths = ["lib"]
|
19
17
|
|
20
18
|
# development dependencies
|
19
|
+
s.add_development_dependency "rake"
|
21
20
|
s.add_development_dependency 'redcarpet'
|
22
21
|
s.add_development_dependency 'rspec'
|
23
22
|
s.add_development_dependency 'yard'
|
24
|
-
|
23
|
+
|
25
24
|
# runtime dependencies
|
26
25
|
s.add_runtime_dependency 'net-ldap'
|
27
26
|
end
|
data/lib/cmu_person/person.rb
CHANGED
@@ -10,32 +10,31 @@ module CMU
|
|
10
10
|
# @param [String] the Andrew ID to search for
|
11
11
|
# @raise [CMU::RecordNotFound] if the Andrew ID does not exist
|
12
12
|
# @return [CMU::Person] a `CMU::Person` object
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
def self.find(andrew_id)
|
14
|
+
CMU::Person.new(andrew_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Attempts to create and return a new CMU::Person from the CMU LDAP directory.
|
18
|
+
# Unlink (see #find), this method will not raise an exception if the Andrew
|
19
|
+
# ID is not found.
|
20
|
+
#
|
21
|
+
# @param [String] the Andrew ID to search for
|
22
22
|
# @return [CMU::Person] a `CMU::Person` object
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def self.find_by_andrew_id(andrew_id)
|
24
|
+
begin
|
25
|
+
find(andrew_id)
|
26
|
+
rescue
|
27
|
+
nil
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@data = ldap.search(:base => 'ou=Person,dc=cmu,dc=edu',
|
36
|
-
:filter => 'cmuAndrewId=' + andrew_id).first
|
29
|
+
end
|
30
|
+
|
31
|
+
# ::nodoc::
|
32
|
+
# @private
|
33
|
+
def initialize(andrew_id)
|
34
|
+
ldap = Net::LDAP.new(:host => 'ldap.andrew.cmu.edu')
|
35
|
+
@data = ldap.search(:base => 'ou=Person,dc=cmu,dc=edu', :filter => 'cmuAndrewId=' + andrew_id).first
|
37
36
|
raise CMU::RecordNotFound if @data.nil?
|
38
|
-
|
37
|
+
end
|
39
38
|
|
40
39
|
# Returns the Andrew ID of the CMU Person
|
41
40
|
#
|
@@ -43,44 +42,44 @@ module CMU
|
|
43
42
|
def andrew_id
|
44
43
|
@andrew_id ||= @data[:cmuAndrewId].last
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
# Returns the full name of the CMU Person
|
48
47
|
#
|
49
48
|
# @return [String] the full name of the current CMU Person
|
50
49
|
def name
|
51
|
-
|
50
|
+
@name ||= @data[:cn].last
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
# Returns the last name of the CMU Person
|
55
54
|
#
|
56
55
|
# @return [String] the last name of the current CMU Person
|
57
56
|
def last_name
|
58
|
-
|
57
|
+
@last_name ||= @data[:sn].last
|
59
58
|
end
|
60
|
-
|
59
|
+
|
61
60
|
# Returns the first name of the CMU Person
|
62
61
|
#
|
63
62
|
# @return [String] the first name of the current CMU Person
|
64
63
|
def first_name
|
65
|
-
|
64
|
+
@first_name ||= @data[:givenname].last
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
# Returns the email of the CMU Person. If the CMU Person has
|
69
68
|
# listed a preferred email, it will be displayed. Otherwise,
|
70
69
|
# the official Andrew Email will be used.
|
71
70
|
#
|
72
71
|
# @return [String] the email of the current CMU Person
|
73
72
|
def email
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
if @data.attribute_names.include?(:cmupreferredmail)
|
74
|
+
@email ||= @data[:cmupreferredmail].last
|
75
|
+
else
|
76
|
+
@email ||= @data[:mail].last
|
77
|
+
end
|
79
78
|
end
|
80
|
-
|
79
|
+
|
81
80
|
# Returns the phone number for the CMU Person
|
82
81
|
#
|
83
|
-
# @return [String, nil] the phone number of the current CMU Person
|
82
|
+
# @return [String, nil] the phone number of the current CMU Person
|
84
83
|
# or nil if the person did not provide a phone number
|
85
84
|
def phone
|
86
85
|
if @data.attribute_names.include?(:cmupreferredtelephone)
|
@@ -89,49 +88,49 @@ module CMU
|
|
89
88
|
@phone ||= nil
|
90
89
|
end
|
91
90
|
end
|
92
|
-
|
91
|
+
|
93
92
|
# Returns the type for the CMU Person
|
94
93
|
#
|
95
94
|
# @return [String] the type or role of the CMU Person
|
96
|
-
def type
|
97
|
-
|
95
|
+
def type
|
96
|
+
@type ||= @data[:edupersonaffiliation].last
|
98
97
|
end
|
99
|
-
|
98
|
+
|
100
99
|
# Returns the official title for the CMU Person
|
101
100
|
#
|
102
101
|
# @return [String, nil] the official title for the CMU Person or
|
103
102
|
# nil if the CMU Person has not provided a title
|
104
103
|
def title
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
104
|
+
if @data.attribute_names.include?(:title)
|
105
|
+
@title ||= @data[:title].last
|
106
|
+
else
|
107
|
+
if @data.attribute_names.include?(:cmutitle)
|
108
|
+
@title ||= @data[:cmutitle].last
|
109
|
+
else
|
110
|
+
@title ||= nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
116
115
|
# Returns the String representation of the grade of the CMU Person
|
117
116
|
#
|
118
|
-
# @return [String, nil] the String representation of the grade of
|
117
|
+
# @return [String, nil] the String representation of the grade of
|
119
118
|
# the CMU Person ('Freshman', 'Sophomore', 'Junior', 'Senior',
|
120
119
|
# 'Masters', 'Doctorate') or nil for Faculty and Staff
|
121
120
|
def grade
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
121
|
+
if @data.attribute_names.include?(:cmustudentclass)
|
122
|
+
@grade ||= @data[:cmustudentclass].last
|
123
|
+
else
|
124
|
+
@grade ||= nil
|
125
|
+
end
|
126
|
+
end
|
128
127
|
|
129
128
|
# Returns department for the CMU Person
|
130
129
|
#
|
131
|
-
# @return [String, nil] the department for the current CMU Person
|
130
|
+
# @return [String, nil] the department for the current CMU Person
|
132
131
|
# or nil if the CMU Person is a student and/or has no department
|
133
132
|
def department
|
134
|
-
|
133
|
+
@department ||= @data[:cmudepartment].last
|
135
134
|
end
|
136
135
|
|
137
136
|
# Returns the "college" for the CMU Person
|
@@ -139,20 +138,20 @@ module CMU
|
|
139
138
|
# @return [String, nil] the actual college the CMU Person belongs to
|
140
139
|
def school
|
141
140
|
filters = ['Student Employment', 'Undergraduate Admission and Student Aid', 'VP For Campus Affairs']
|
142
|
-
|
141
|
+
@school ||= @data[:edupersonschoolcollegename].reject{|c| filters.include?(c)}.last
|
143
142
|
end
|
144
|
-
|
143
|
+
|
145
144
|
# ::nodoc::
|
146
145
|
# @private
|
147
146
|
def inspect
|
148
147
|
fields = %w(andrew_id first_name last_name email phone type title)
|
149
148
|
@inspect ||= "<CMU::Person #{fields.collect{|f| f + ': ' + self.send(f.to_sym).inspect}.join(', ')}>"
|
150
149
|
end
|
151
|
-
|
150
|
+
|
152
151
|
# ::nodoc::
|
153
152
|
# @private
|
154
153
|
def to_s
|
155
154
|
@to_s ||= "<CMU::Person \"#{self.send(:name)} (#{self.send(:andrew_id)})\">"
|
156
|
-
|
155
|
+
end
|
157
156
|
end
|
158
157
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmu_person
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: redcarpet
|
16
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
17
33
|
none: false
|
18
34
|
requirements:
|
19
35
|
- - ! '>='
|
@@ -21,10 +37,15 @@ dependencies:
|
|
21
37
|
version: '0'
|
22
38
|
type: :development
|
23
39
|
prerelease: false
|
24
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
25
46
|
- !ruby/object:Gem::Dependency
|
26
47
|
name: rspec
|
27
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
28
49
|
none: false
|
29
50
|
requirements:
|
30
51
|
- - ! '>='
|
@@ -32,10 +53,15 @@ dependencies:
|
|
32
53
|
version: '0'
|
33
54
|
type: :development
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
36
62
|
- !ruby/object:Gem::Dependency
|
37
63
|
name: yard
|
38
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
39
65
|
none: false
|
40
66
|
requirements:
|
41
67
|
- - ! '>='
|
@@ -43,10 +69,15 @@ dependencies:
|
|
43
69
|
version: '0'
|
44
70
|
type: :development
|
45
71
|
prerelease: false
|
46
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
47
78
|
- !ruby/object:Gem::Dependency
|
48
79
|
name: net-ldap
|
49
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
50
81
|
none: false
|
51
82
|
requirements:
|
52
83
|
- - ! '>='
|
@@ -54,7 +85,12 @@ dependencies:
|
|
54
85
|
version: '0'
|
55
86
|
type: :runtime
|
56
87
|
prerelease: false
|
57
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
58
94
|
description: This tool is used to search Carnegie Mellon's LDAP directory. Provide
|
59
95
|
an Andrew ID and this will automatically parse the results and return them in a
|
60
96
|
readable format.
|
@@ -65,6 +101,7 @@ extra_rdoc_files: []
|
|
65
101
|
files:
|
66
102
|
- .gitignore
|
67
103
|
- .rspec
|
104
|
+
- .travis.yml
|
68
105
|
- Gemfile
|
69
106
|
- Gemfile.lock
|
70
107
|
- LICENSE
|
@@ -95,8 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
132
|
- !ruby/object:Gem::Version
|
96
133
|
version: '0'
|
97
134
|
requirements: []
|
98
|
-
rubyforge_project:
|
99
|
-
rubygems_version: 1.8.
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.23
|
100
137
|
signing_key:
|
101
138
|
specification_version: 3
|
102
139
|
summary: A simple interface for searching CMU LDAP directory
|