cmu-person 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile CHANGED
@@ -1,11 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'net-ldap'
4
- gem 'rdoc'
5
-
6
- group :development do
7
- gem "shoulda", ">= 0"
8
- gem "bundler", "~> 1.0.0"
9
- gem "jeweler", "~> 1.6.4"
10
- gem "rcov", ">= 0"
11
- end
3
+ gemspec
@@ -1,26 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cmu-person (0.0.3)
5
+ net-ldap
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  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
+ diff-lcs (1.1.3)
10
11
  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)
12
+ redcarpet (2.0.1)
13
+ rspec (2.7.0)
14
+ rspec-core (~> 2.7.0)
15
+ rspec-expectations (~> 2.7.0)
16
+ rspec-mocks (~> 2.7.0)
17
+ rspec-core (2.7.1)
18
+ rspec-expectations (2.7.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.7.0)
21
+ yard (0.7.4)
16
22
 
17
23
  PLATFORMS
18
24
  ruby
19
25
 
20
26
  DEPENDENCIES
21
- bundler (~> 1.0.0)
22
- jeweler (~> 1.6.4)
23
- net-ldap
24
- rcov
25
- rdoc
26
- shoulda
27
+ cmu-person!
28
+ redcarpet
29
+ rspec
30
+ yard
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Seth Vargo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -10,24 +10,32 @@ If you want to use this gem for personal use in your terminal, just type the fol
10
10
  gem install cmu-person
11
11
  ```
12
12
 
13
- If you plan to use this in a Rails project, add the following to your `Gemfile`:
13
+ If you plan to use this in a Rails project (or other project managed by Bundler), add the following to your `Gemfile`:
14
14
 
15
- ```ruby
16
- gem 'cmu-person'
17
- ```
15
+ gem 'cmu-person'
18
16
 
19
17
  Don't forget to run the `bundle` command to install the gem!
20
18
 
21
19
  Usage
22
20
  -----
23
21
 
24
- ```ruby
25
- user = CMU::Person.new('svargo')
26
- user.first_name #=> "Seth"
27
- user.grade #=> "Junior"
28
- ```
22
+ user = CMU::Person.find('svargo')
23
+ user.first_name #=> "Seth"
24
+ user.grade #=> "Junior"
25
+
26
+  
27
+
28
+ user = CMU::Person.new('i_dont_exist')
29
+ #=> CMU::RecordNotFound Exception
30
+
31
+ For a complete list of methods, view the [YARD Documentation](http://rubydoc.info/gems/cmu-person/0.0.3/frames)
32
+
33
+ License
34
+ -------
35
+ Copyright (c) 2012 Seth Vargo
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
29
40
 
30
- ```ruby
31
- user = CMU::Person.new('i_dont_exist')
32
- #=> RecordNotFound Exception
33
- ```
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,51 +1,5 @@
1
- # encoding: utf-8
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
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
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -1,65 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = "cmu-person"
8
- s.version = "0.0.2"
5
+ s.name = 'cmu-person'
6
+ s.version = '0.0.4'
7
+ s.author = 'Seth Vargo'
8
+ s.email = 'sethvargo@gmail.com'
9
+ s.homepage = 'https://github.com/sethvargo/cmu-person'
10
+ s.summary = %q{A simple interface for searching CMU LDAP directory}
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.}
9
12
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Seth Vargo"]
12
- s.date = "2011-11-17"
13
- s.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."
14
- s.email = "sethvargo@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- "Gemfile",
21
- "Gemfile.lock",
22
- "LICENSE.txt",
23
- "README.markdown",
24
- "Rakefile",
25
- "SAMPLE",
26
- "VERSION",
27
- "cmu-person.gemspec",
28
- "lib/cmu-person.rb",
29
- "test/helper.rb",
30
- "test/test_cmu-person.rb"
31
- ]
32
- s.homepage = "http://github.com/sethvargo/cmu-person"
33
- s.licenses = ["MIT"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = "1.8.11"
36
- s.summary = "A simple interface for searching CMU LDAP directory"
37
-
38
- if s.respond_to? :specification_version then
39
- s.specification_version = 3
13
+ s.rubyforge_project = 'cmu-person'
40
14
 
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<net-ldap>, [">= 0"])
43
- s.add_runtime_dependency(%q<rdoc>, [">= 0"])
44
- s.add_development_dependency(%q<shoulda>, [">= 0"])
45
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
- s.add_development_dependency(%q<rcov>, [">= 0"])
48
- else
49
- s.add_dependency(%q<net-ldap>, [">= 0"])
50
- s.add_dependency(%q<rdoc>, [">= 0"])
51
- s.add_dependency(%q<shoulda>, [">= 0"])
52
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
- s.add_dependency(%q<rcov>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<net-ldap>, [">= 0"])
58
- s.add_dependency(%q<rdoc>, [">= 0"])
59
- s.add_dependency(%q<shoulda>, [">= 0"])
60
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
- s.add_dependency(%q<rcov>, [">= 0"])
63
- end
64
- end
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
65
19
 
20
+ # development dependencies
21
+ s.add_development_dependency 'redcarpet'
22
+ s.add_development_dependency 'rspec'
23
+ s.add_development_dependency 'yard'
24
+
25
+ # runtime dependencies
26
+ s.add_runtime_dependency 'net-ldap'
27
+ end
@@ -0,0 +1,2 @@
1
+ require 'cmu_person/person'
2
+ require 'cmu_person/exceptions'
@@ -0,0 +1,6 @@
1
+ # ::nodoc::
2
+ # @private
3
+ module CMU
4
+ # Simple error
5
+ class RecordNotFound < StandardError; end
6
+ end
@@ -0,0 +1,158 @@
1
+ require 'net/ldap'
2
+
3
+ # ::nodoc::
4
+ # @private
5
+ module CMU
6
+ # A CMU::Person class
7
+ class Person
8
+ # Attempts to create and return a new CMU::Person from the CMU LDAP directory.
9
+ #
10
+ # @param [String] the Andrew ID to search for
11
+ # @raise [CMU::RecordNotFound] if the Andrew ID does not exist
12
+ # @return [CMU::Person] a `CMU::Person` object
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
+ # @return [CMU::Person] a `CMU::Person` object
23
+ def self.find_by_andrew_id(andrew_id)
24
+ begin
25
+ find(andrew_id)
26
+ rescue
27
+ nil
28
+ end
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',
36
+ :filter => 'cmuAndrewId=' + andrew_id).first
37
+ raise CMU::RecordNotFound if @data.nil?
38
+ end
39
+
40
+ # Returns the Andrew ID of the CMU Person
41
+ #
42
+ # @return [String] the Andrew ID of the CMU Person
43
+ def andrew_id
44
+ @andrew_id ||= @data[:cmuAndrewId].last
45
+ end
46
+
47
+ # Returns the full name of the CMU Person
48
+ #
49
+ # @return [String] the full name of the current CMU Person
50
+ def name
51
+ @name ||= @data[:cn].last
52
+ end
53
+
54
+ # Returns the last name of the CMU Person
55
+ #
56
+ # @return [String] the last name of the current CMU Person
57
+ def last_name
58
+ @last_name ||= @data[:sn].last
59
+ end
60
+
61
+ # Returns the first name of the CMU Person
62
+ #
63
+ # @return [String] the first name of the current CMU Person
64
+ def first_name
65
+ @first_name ||= @data[:givenname].last
66
+ end
67
+
68
+ # Returns the email of the CMU Person. If the CMU Person has
69
+ # listed a preferred email, it will be displayed. Otherwise,
70
+ # the official Andrew Email will be used.
71
+ #
72
+ # @return [String] the email of the current CMU Person
73
+ def email
74
+ if @data.attribute_names.include?(:cmupreferredmail)
75
+ @email ||= @data[:cmupreferredmail].last
76
+ else
77
+ @email ||= @data[:mail].last
78
+ end
79
+ end
80
+
81
+ # Returns the phone number for the CMU Person
82
+ #
83
+ # @return [String, nil] the phone number of the current CMU Person
84
+ # or nil if the person did not provide a phone number
85
+ def phone
86
+ if @data.attribute_names.include?(:cmupreferredtelephone)
87
+ @phone ||= @data[:cmupreferredtelephone].last.gsub(/[^0-9]/,'')
88
+ else
89
+ @phone ||= nil
90
+ end
91
+ end
92
+
93
+ # Returns the type for the CMU Person
94
+ #
95
+ # @return [String] the type or role of the CMU Person
96
+ def type
97
+ @type ||= @data[:edupersonaffiliation].last
98
+ end
99
+
100
+ # Returns the official title for the CMU Person
101
+ #
102
+ # @return [String, nil] the official title for the CMU Person or
103
+ # nil if the CMU Person has not provided a title
104
+ def title
105
+ if @data.attribute_names.include?(:title)
106
+ @title ||= @data[:title].last
107
+ else
108
+ if @data.attribute_names.include?(:cmutitle)
109
+ @title ||= @data[:cmutitle].last
110
+ else
111
+ @title ||= nil
112
+ end
113
+ end
114
+ end
115
+
116
+ # Returns the String representation of the grade of the CMU Person
117
+ #
118
+ # @return [String, nil] the String representation of the grade of
119
+ # the CMU Person ('Freshman', 'Sophomore', 'Junior', 'Senior',
120
+ # 'Masters', 'Doctorate') or nil for Faculty and Staff
121
+ def grade
122
+ if @data.attribute_names.include?(:cmustudentclass)
123
+ @grade ||= @data[:cmustudentclass].last
124
+ else
125
+ @grade ||= nil
126
+ end
127
+ end
128
+
129
+ # Returns department for the CMU Person
130
+ #
131
+ # @return [String, nil] the department for the current CMU Person
132
+ # or nil if the CMU Person is a student and/or has no department
133
+ def department
134
+ @department ||= @data[:cmudepartment].last
135
+ end
136
+
137
+ # Returns the "college" for the CMU Person
138
+ #
139
+ # @return [String, nil] the actual college the CMU Person belongs to
140
+ def school
141
+ filters = ['Student Employment', 'Undergraduate Admission and Student Aid', 'VP For Campus Affairs']
142
+ @school ||= @data[:edupersonschoolcollegename].reject{|c| filters.include?(c)}.last
143
+ end
144
+
145
+ # ::nodoc::
146
+ # @private
147
+ def inspect
148
+ fields = %w(andrew_id first_name last_name email phone type title)
149
+ @inspect ||= "<CMU::Person #{fields.collect{|f| f + ': ' + self.send(f.to_sym).inspect}.join(', ')}>"
150
+ end
151
+
152
+ # ::nodoc::
153
+ # @private
154
+ def to_s
155
+ @to_s ||= "<CMU::Person \"#{self.send(:name)} (#{self.send(:andrew_id)})\">"
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe CMU::Person do
4
+ before(:all) do
5
+ @seth = CMU::Person.find('svargo')
6
+ @bryan = CMU::Person.find('bleach')
7
+ @dano = CMU::Person.find('dorbegoz')
8
+ @profh = CMU::Person.find('lheimann')
9
+ @kaycee = CMU::Person.find('kpalko')
10
+ end
11
+
12
+ it 'should fetch a valid user' do
13
+ @seth.first_name.should eql('Seth')
14
+ @seth.last_name.should eql('Vargo')
15
+ @seth.andrew_id.should eql('svargo')
16
+ end
17
+
18
+ it 'should fetch another valid user' do
19
+ @bryan.first_name.should eql('Bryan')
20
+ @bryan.last_name.should eql('Leach')
21
+ @bryan.andrew_id.should eql('bleach')
22
+ end
23
+
24
+ it 'new/find should raise an exception for an invalid user' do
25
+ lambda { CMU::Person.new('not_a_real_user') }.should raise_exception(CMU::RecordNotFound)
26
+ lambda { CMU::Person.find('not_a_real_user') }.should raise_exception(CMU::RecordNotFound)
27
+ end
28
+
29
+ it 'find_by_andrew_id not raise an exception for an an invalid user' do
30
+ lambda { CMU::Person.find_by_andrew_id('not_a_real_user') }.should_not raise_exception
31
+ end
32
+
33
+ it 'should return the user\'s email' do
34
+ @seth.email.should eql('svargo@andrew.cmu.edu')
35
+ end
36
+
37
+ it 'should return the user\'s phone' do
38
+ @seth.phone.should eql('8144211811')
39
+ end
40
+
41
+ it 'should return nil if phone is blank' do
42
+ @bryan.phone.should be_nil
43
+ end
44
+
45
+ it 'should return the correct student type' do
46
+ @seth.type.should eql('Student')
47
+ end
48
+
49
+ it 'should return the correct faculty type' do
50
+ @profh.type.should eql('Faculty')
51
+ end
52
+
53
+ it 'should return the correct staff type' do
54
+ @kaycee.type.should eql('Staff')
55
+ end
56
+
57
+ it 'should return the correct title' do
58
+ @seth.title.should eql('Head Grader')
59
+ @profh.title.should eql('Teaching Professor')
60
+ @kaycee.title.should eql('Housefellow/cdtr. of Student Activities')
61
+ end
62
+
63
+ it 'should return nil if title is blank' do
64
+ @dano.title.should be_nil
65
+ end
66
+
67
+ it 'should return the user\'s grade' do
68
+ @seth.grade.should eql('Senior')
69
+ @bryan.grade.should eql('Sophomore')
70
+ end
71
+
72
+ it 'should return nil if grade is blank' do
73
+ @profh.grade.should be_nil
74
+ @kaycee.grade.should be_nil
75
+ end
76
+
77
+ it 'should return the correct department' do
78
+ @profh.department.should eql('Is Program In Dietrich')
79
+ @kaycee.department.should eql('Student Campus Activities')
80
+ @seth.department.should eql('H&SS Interdisciplinary')
81
+ @bryan.department.should eql('Mechanical Engineering')
82
+ @dano.department.should eql('Civil & Environmental Engineering')
83
+ end
84
+
85
+ it 'should return the correct school' do
86
+ @profh.school.should eql('Dietrich College of Humanities and Social Sciences')
87
+ @seth.school.should eql('Dietrich College of Humanities and Social Sciences')
88
+ @bryan.school.should eql('Carnegie Institute of Technology')
89
+ end
90
+
91
+ it 'should return nil if school is blank' do
92
+ @kaycee.school.should be_nil
93
+ end
94
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default)
4
+
5
+ require 'cmu_person'
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.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-17 00:00:00.000000000Z
12
+ date: 2012-01-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: net-ldap
16
- requirement: &70322387074460 !ruby/object:Gem::Requirement
15
+ name: redcarpet
16
+ requirement: &70322315030420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
- version_requirements: *70322387074460
24
+ version_requirements: *70322315030420
25
25
  - !ruby/object:Gem::Dependency
26
- name: rdoc
27
- requirement: &70322387073980 !ruby/object:Gem::Requirement
26
+ name: rspec
27
+ requirement: &70322315029980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
- type: :runtime
33
+ type: :development
34
34
  prerelease: false
35
- version_requirements: *70322387073980
35
+ version_requirements: *70322315029980
36
36
  - !ruby/object:Gem::Dependency
37
- name: shoulda
38
- requirement: &70322387073500 !ruby/object:Gem::Requirement
37
+ name: yard
38
+ requirement: &70322315029560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,64 +43,41 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70322387073500
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: &70322387073020 !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: *70322387073020
46
+ version_requirements: *70322315029560
58
47
  - !ruby/object:Gem::Dependency
59
- name: jeweler
60
- requirement: &70322387072540 !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: *70322387072540
69
- - !ruby/object:Gem::Dependency
70
- name: rcov
71
- requirement: &70322387072060 !ruby/object:Gem::Requirement
48
+ name: net-ldap
49
+ requirement: &70322315029140 !ruby/object:Gem::Requirement
72
50
  none: false
73
51
  requirements:
74
52
  - - ! '>='
75
53
  - !ruby/object:Gem::Version
76
54
  version: '0'
77
- type: :development
55
+ type: :runtime
78
56
  prerelease: false
79
- version_requirements: *70322387072060
57
+ version_requirements: *70322315029140
80
58
  description: This tool is used to search Carnegie Mellon's LDAP directory. Provide
81
59
  an Andrew ID and this will automatically parse the results and return them in a
82
60
  readable format.
83
61
  email: sethvargo@gmail.com
84
62
  executables: []
85
63
  extensions: []
86
- extra_rdoc_files:
87
- - LICENSE.txt
88
- - README.markdown
64
+ extra_rdoc_files: []
89
65
  files:
66
+ - .gitignore
67
+ - .rspec
90
68
  - Gemfile
91
69
  - Gemfile.lock
92
- - LICENSE.txt
70
+ - LICENSE
93
71
  - README.markdown
94
72
  - Rakefile
95
- - SAMPLE
96
- - VERSION
97
73
  - cmu-person.gemspec
98
- - lib/cmu-person.rb
99
- - test/helper.rb
100
- - test/test_cmu-person.rb
101
- homepage: http://github.com/sethvargo/cmu-person
102
- licenses:
103
- - MIT
74
+ - lib/cmu_person.rb
75
+ - lib/cmu_person/exceptions.rb
76
+ - lib/cmu_person/person.rb
77
+ - spec/cmu_person_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: https://github.com/sethvargo/cmu-person
80
+ licenses: []
104
81
  post_install_message:
105
82
  rdoc_options: []
106
83
  require_paths:
@@ -111,9 +88,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
88
  - - ! '>='
112
89
  - !ruby/object:Gem::Version
113
90
  version: '0'
114
- segments:
115
- - 0
116
- hash: -4328825784842371156
117
91
  required_rubygems_version: !ruby/object:Gem::Requirement
118
92
  none: false
119
93
  requirements:
@@ -121,9 +95,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
95
  - !ruby/object:Gem::Version
122
96
  version: '0'
123
97
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 1.8.11
98
+ rubyforge_project: cmu-person
99
+ rubygems_version: 1.8.10
126
100
  signing_key:
127
101
  specification_version: 3
128
102
  summary: A simple interface for searching CMU LDAP directory
129
- test_files: []
103
+ test_files:
104
+ - spec/cmu_person_spec.rb
105
+ - spec/spec_helper.rb
106
+ has_rdoc:
@@ -1,20 +0,0 @@
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/SAMPLE DELETED
@@ -1 +0,0 @@
1
- #<Net::LDAP::Entry:0x007ff24a8a5338 @myhash={:dn=>["guid=9E64B44A-EC50-11DD-8000-0003BA2FA263,ou=person,dc=cmu,dc=edu"], :sn=>["Vargo"], :cmuprimarycampus=>["Pittsburgh"], :cmucampus=>["Pittsburgh"], :edupersonschoolcollegename=>["Student Employment", "VP For Campus Affairs", "College of Humanities & Social Sciences", "SCS - School of Computer Science", "Dietrich College of Humanities and Social Sciences"], :givenname=>["Seth"], :cmumiddlename=>["J."], :cn=>["Seth J. Vargo", "Seth Vargo"], :cmustudentlevel=>["Undergrad"], :guid=>["9E64B44A-EC50-11DD-8000-0003BA2FA263"], :objectclass=>["cmuPerson"], :cmuaccount=>["uid=svargo,ou=Account,dc=andrew,dc=cmu,dc=edu", "uid=svargo,ou=Account,dc=cmu,dc=edu"], :cmuactivedn=>["uid=svargo,ou=Account,dc=andrew,dc=cmu,dc=edu", "uid=svargo,ou=Account,dc=cmu,dc=edu"], :cmuandrewcommonnamespaceid=>["svargo"], :cmuandrewid=>["svargo"], :cmueduid=>["svargo"], :cmupersonprincipalname=>["svargo@ANDREW.CMU.EDU"], :cmupreferredtelephone=>["(814) 421-1811"], :nickname=>["Seth"], :cmupersonaffiliation=>["Undergraduate Student", "Student"], :cmustudentclass=>["Senior"], :cmupreferredmail=>["svargo@andrew.cmu.edu"], :mail=>["svargo@andrew.cmu.edu"], :labeleduri=>["http://www.sethvargo.com"], :cmutitle=>["Mr. President"], :cmudepartment=>["H&SS Interdisciplinary"], :cmuprivate=>["homePhone", "homePostalAddress", "postalAddress", "telephoneNumber"], :edupersonaffiliation=>["Student"], :edupersonprimaryaffiliation=>["Student"], :title=>["Head Grader"]}
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.2
@@ -1,85 +0,0 @@
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 phone
42
- if @data.attribute_names.include?(:cmupreferredtelephone)
43
- @data[:cmupreferredtelephone].last.gsub(/[^0-9]/,'')
44
- else
45
- nil
46
- end
47
- end
48
-
49
- def type
50
- @data[:edupersonaffiliation].last
51
- end
52
-
53
- def title
54
- if @data.attribute_names.include?(:title)
55
- @data[:title].last
56
- else
57
- if @data.attribute_names.include?(:cmutitle)
58
- @data[:cmutitle].last
59
- else
60
- nil
61
- end
62
- end
63
- end
64
-
65
- def grade
66
- if @data.attribute_names.include?(:cmustudentclass)
67
- @data[:cmustudentclass].last
68
- else
69
- nil
70
- end
71
- end
72
-
73
- def department
74
- @data[:cmudepartment].last
75
- end
76
-
77
- def school
78
- @data[:edupersonschoolcollegename].last
79
- end
80
-
81
- def to_s
82
- @data.collect{|i,j| i.to_s.ljust(30)+":\t"+(j.is_a?(Array) ? "[ "+j.join(", ")+" ]" : j.to_s)+"\n"}.join("\n")
83
- end
84
- end
85
- end
@@ -1,18 +0,0 @@
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
@@ -1,14 +0,0 @@
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