cmu-person 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +33 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/cmu-person.rb +77 -0
- data/test/helper.rb +18 -0
- data/test/test_cmu-person.rb +14 -0
- metadata +128 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
json (1.6.1)
|
10
|
+
net-ldap (0.2.2)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rcov (0.9.11)
|
13
|
+
rdoc (3.11)
|
14
|
+
json (~> 1.4)
|
15
|
+
shoulda (2.11.3)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (~> 1.0.0)
|
22
|
+
jeweler (~> 1.6.4)
|
23
|
+
net-ldap
|
24
|
+
rcov
|
25
|
+
rdoc
|
26
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Seth Vargo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
CMU Person
|
2
|
+
==========
|
3
|
+
|
4
|
+
Originally inspired by [David Taylor](https://github.com/tinystatemachine)'s [andrewid](https://github.com/tinystatemachine/andrewid), CMU Person is a simple rubygem used for searching Carnegie Mellon's LDAP servers for student information.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
If you want to use this gem for personal use in your terminal, just type the following command in bash:
|
9
|
+
```bash
|
10
|
+
gem install cmu-person
|
11
|
+
```
|
12
|
+
|
13
|
+
If you plan to use this in a Rails project, add the following to your `Gemfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'cmu-person'
|
17
|
+
```
|
18
|
+
|
19
|
+
Don't forget to run the `bundle` command to install the gem!
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
user = CMU::Person.new('svargo')
|
26
|
+
user.first_name #=> "Seth"
|
27
|
+
user.grade #=> "Junior"
|
28
|
+
```
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
user = CMU::Person.new('i_dont_exist')
|
32
|
+
#=> RecordNotFound Exception
|
33
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = 'cmu-person'
|
17
|
+
gem.homepage = 'http://github.com/sethvargo/cmu-person'
|
18
|
+
gem.license = 'MIT'
|
19
|
+
gem.summary = 'A simple interface for searching CMU LDAP directory'
|
20
|
+
gem.description = '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.'
|
21
|
+
gem.email = 'sethvargo@gmail.com'
|
22
|
+
gem.authors = ['Seth Vargo']
|
23
|
+
end
|
24
|
+
Jeweler::RubygemsDotOrgTasks.new
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/test_*.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
test.rcov_opts << '--exclude "gems/*"'
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "cmu-person #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/cmu-person.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'net/ldap'
|
2
|
+
|
3
|
+
module CMU
|
4
|
+
class Person
|
5
|
+
class RecordNotFound < StandardError; end
|
6
|
+
|
7
|
+
def initialize(andrewid)
|
8
|
+
raise RecordNotFound unless @data = fetch(andrewid)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch(user)
|
12
|
+
ldap = Net::LDAP.new(:host => 'ldap.andrew.cmu.edu')
|
13
|
+
ldap.search(:base => 'ou=Person,dc=cmu,dc=edu',
|
14
|
+
:filter => 'cmuAndrewId='+user ).first
|
15
|
+
end
|
16
|
+
|
17
|
+
def andrew_id
|
18
|
+
@data[:cmuAndrewId].last
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
@data[:cn].last
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_name
|
26
|
+
@data[:sn].last
|
27
|
+
end
|
28
|
+
|
29
|
+
def first_name
|
30
|
+
@data[:givenname].last
|
31
|
+
end
|
32
|
+
|
33
|
+
def email
|
34
|
+
if @data.attribute_names.include?(:cmupreferredmail)
|
35
|
+
@data[:cmupreferredmail].last
|
36
|
+
else
|
37
|
+
@data[:mail].last
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def type
|
42
|
+
@data[:edupersonaffiliation].last
|
43
|
+
end
|
44
|
+
|
45
|
+
def title
|
46
|
+
if @data.attribute_names.include?(:title)
|
47
|
+
@data[:title].last
|
48
|
+
else
|
49
|
+
if @data.attribute_names.include?(:cmutitle)
|
50
|
+
@data[:cmutitle].last
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def grade
|
58
|
+
if @data.attribute_names.include?(:cmustudentclass)
|
59
|
+
@data[:cmustudentclass].last
|
60
|
+
else
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def department
|
66
|
+
@data[:cmudepartment].last
|
67
|
+
end
|
68
|
+
|
69
|
+
def school
|
70
|
+
@data[:edupersonschoolcollegename].last
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
@data.collect{|i,j| i.to_s.ljust(30)+":\t"+(j.is_a?(Array) ? "[ "+j.join(", ")+" ]" : j.to_s)+"\n"}.join("\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'cmu-person'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCmuPerson < Test::Unit::TestCase
|
4
|
+
should 'fetch a valid user' do
|
5
|
+
user = CMU::Person.new('svargo')
|
6
|
+
assert user.first_name == 'Seth'
|
7
|
+
assert user.last_name == 'Vargo'
|
8
|
+
assert user.andrew_id == 'svargo'
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'not fetch an invalid user' do
|
12
|
+
assert_raise(CMU::Person::RecordNotFound) { CMU::Person.new('not_a_user') }
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cmu-person
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Seth Vargo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ldap
|
16
|
+
requirement: &70273468779840 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70273468779840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &70273468779360 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70273468779360
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: shoulda
|
38
|
+
requirement: &70273468778880 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70273468778880
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70273468778400 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70273468778400
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70273468777920 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.6.4
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70273468777920
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
requirement: &70273468777440 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70273468777440
|
80
|
+
description: This tool is used to search Carnegie Mellon's LDAP directory. Provide
|
81
|
+
an Andrew ID and this will automatically parse the results and return them in a
|
82
|
+
readable format.
|
83
|
+
email: sethvargo@gmail.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files:
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.markdown
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.markdown
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- lib/cmu-person.rb
|
98
|
+
- test/helper.rb
|
99
|
+
- test/test_cmu-person.rb
|
100
|
+
homepage: http://github.com/sethvargo/cmu-person
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: 589060480960458176
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.11
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: A simple interface for searching CMU LDAP directory
|
128
|
+
test_files: []
|