Maximander-AndrewID 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/History.txt +4 -0
  2. data/lib/andrewid/person.rb +78 -0
  3. metadata +66 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-04-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,78 @@
1
+ require 'rubygems';
2
+ require 'net/ldap'
3
+ module Andrew
4
+ class Person
5
+ class RecordNotFound < StandardError
6
+ end
7
+
8
+ def initialize(andrewid)
9
+ raise RecordNotFound, "Invalid AndrewID" unless @data = fetch(andrewid)
10
+ end
11
+
12
+ def fetch(user)
13
+ host = "ldap.andrew.cmu.edu"
14
+ ldap = Net::LDAP.new :host => host, :port => 389
15
+ ldap.search( :base => 'ou=Person,dc=cmu,dc=edu',
16
+ :filter => 'cmuAndrewId='+user )[0]
17
+ end
18
+
19
+ def dump
20
+ @data.each{|i,j| puts i.to_s.ljust(30)+":\t"+(j.is_a?(Array) ? "[ "+j.join(", ")+" ]" : j.to_s)+"\n"}
21
+ nil
22
+ end
23
+
24
+
25
+ def name
26
+ @data[:cn][-1]
27
+ end
28
+
29
+ def last_name
30
+ @data[:sn][-1]
31
+ end
32
+
33
+ def first_name
34
+ @data[:givenname][-1]
35
+ end
36
+
37
+ def email
38
+ if @data.attribute_names.include? :cmupreferredmail then
39
+ @data[:cmupreferredmail][-1]
40
+ else
41
+ @data[:mail][-1]
42
+ end
43
+ end
44
+
45
+ def type
46
+ @data[:edupersonaffiliation][-1]
47
+ end
48
+
49
+ def title
50
+ if @data.attribute_names.include? :title then
51
+ @data[:title][-1]
52
+ else
53
+ if @data.attribute_names.include? :cmutitle then
54
+ @data[:cmutitle][-1]
55
+ else
56
+ nil
57
+ end
58
+ end
59
+ end
60
+
61
+ def grade
62
+ if @data.attribute_names.include? :cmustudentclass then
63
+ @data[:cmustudentclass][-1]
64
+ else
65
+ nil
66
+ end
67
+ end
68
+
69
+ def department
70
+ @data[:cmudepartment][-1]
71
+ end
72
+
73
+ def school
74
+ @data[:edupersonschoolcollegename][-1]
75
+ end
76
+
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Maximander-AndrewID
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-31 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-net-ldap
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.4
24
+ version:
25
+ description: AndrewID provides a ruby interface to CMU student info stored in LDAP
26
+ email: maximander@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - API.txt
35
+ - History.txt
36
+ - lib/andrewid
37
+ - lib/andrewid/person.rb
38
+ has_rdoc: true
39
+ homepage: http://reisub.net/gems/andrewid
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --inline-source
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: andrewid
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Ruby interface to CMU LDAP
65
+ test_files: []
66
+