cmu 0.0.1

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.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +49 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +16 -0
  5. data/LICENSE +20 -0
  6. data/README.md +15 -0
  7. data/lib/cmu.rb +85 -0
  8. metadata +65 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2914f47e228006ff733e54b2a09fea14419c2e35
4
+ data.tar.gz: afd5e7a9acca157a8b3bdb0e572c027e62524d67
5
+ SHA512:
6
+ metadata.gz: 18ee46ca6c04df1dd7169d378b490606f1c824cf95f0134190556b7a26a32b7f654a6b51cbe0eed4e795f431575378f8c45480aa19e8ba6540873d9c68394926
7
+ data.tar.gz: fd5a599b0c6009b2942a779e4862eeefb3b428983b4fc86d1a0b849d9cb9dc21c2e665cdbfa538ddacc4a4495828daf4927f193698772ec573b79a911506ec27
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # Created by http://www.gitignore.io
2
+
3
+ ### Ruby ###
4
+ *.gem
5
+ *.rbc
6
+ /.config
7
+ /coverage/
8
+ /InstalledFiles
9
+ /pkg/
10
+ /spec/reports/
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ ## Documentation cache and generated files:
16
+ /.yardoc/
17
+ /_yardoc/
18
+ /doc/
19
+ /rdoc/
20
+
21
+ ## Environment normalisation:
22
+ /.bundle/
23
+ /lib/bundler/man/
24
+
25
+ # for a library or gem, you might want to ignore these files since the code is
26
+ # intended to run in multiple environments; otherwise, check them in:
27
+ # Gemfile.lock
28
+ # .ruby-version
29
+ # .ruby-gemset
30
+
31
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
32
+ .rvmrc
33
+
34
+
35
+ ### OSX ###
36
+ .DS_Store
37
+ .AppleDouble
38
+ .LSOverride
39
+
40
+ # Icon must ends with two \r.
41
+ Icon
42
+
43
+ # Thumbnails
44
+ ._*
45
+
46
+ # Files that might appear on external disk
47
+ .Spotlight-V100
48
+ .Trashes
49
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cmu (0.0.1)
5
+ net-ldap2
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ net-ldap2 (0.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ cmu!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Tom Shen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # cmurb
2
+
3
+ A Ruby library for CMU data. Currently only supports directory.
4
+
5
+ ## Usage
6
+ First, `bundle install` all the dependencies. Then, to use the library:
7
+
8
+ ```ruby
9
+ >> require './lib/cmu'
10
+ >> tom = CMU::Directory.find(:andrew_id=>'zhixians').first
11
+ >> tom.name
12
+ => "Tom Shen"
13
+ ```
14
+
15
+ You can also search by `:name`, `:first_name` and `:last_name`.
data/lib/cmu.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'net-ldap'
2
+
3
+ module CMU
4
+ def valid_andrewid?(andrewid)
5
+ not /^[a-zA-Z][a-zA-Z0-9]{1,7}$/.match(andrewid).nil?
6
+ end
7
+
8
+ module Directory
9
+ @ldap = Net::LDAP.new(:host => 'ldap.andrew.cmu.edu')
10
+
11
+ class Person
12
+ def initialize(data)
13
+ @andrew_id = data[:cmuAndrewId].last
14
+ if data.attribute_names.include?(:nickname)
15
+ @name = data[:nickname].last
16
+ else
17
+ @name = data[:cn].last
18
+ end
19
+ @last_name = data[:sn].last
20
+ @first_name = @name.split()[0]
21
+ if data.attribute_names.include?(:cmupreferredmail)
22
+ @email = data[:cmupreferredmail].last
23
+ else
24
+ @email = data[:mail].last
25
+ end
26
+ if data.attribute_names.include?(:cmupreferredtelephone)
27
+ @phone = data[:cmupreferredtelephone].last.gsub(/[^0-9]/,'')
28
+ else
29
+ @phone = nil
30
+ end
31
+ @role = data[:edupersonaffiliation].last
32
+ if data.attribute_names.include?(:title)
33
+ @title = data[:title].last
34
+ else
35
+ if data.attribute_names.include?(:cmutitle)
36
+ @title = data[:cmutitle].last
37
+ else
38
+ @title = nil
39
+ end
40
+ end
41
+ if data.attribute_names.include?(:cmustudentclass)
42
+ @student_class = data[:cmustudentclass].last
43
+ else
44
+ @student_class = nil
45
+ end
46
+ if data.attribute_names.include?(:cmustudentlevel)
47
+ @student_level = data[:cmustudentlevel].last
48
+ else
49
+ @student_level = nil
50
+ end
51
+ @department = data[:cmudepartment].last
52
+ @affiliated_schools = data[:edupersonschoolcollegename]
53
+ end
54
+ attr_reader :andrew_id, :name, :last_name, :first_name, :email,
55
+ :phone, :role, :title, :student_class, :student_level, :department,
56
+ :affiliated_schools
57
+ end
58
+
59
+ def Directory.search(query)
60
+ data = @ldap.search(:base => 'ou=Person,dc=cmu,dc=edu', :filter => query)
61
+ data.nil? ? [] : data
62
+ end
63
+
64
+ def Directory.search_by_name(name)
65
+ nickname_filter = Net::LDAP::Filter.contains('nickname', name)
66
+ givenname_filter = Net::LDAP::Filter.contains('cn', name)
67
+ Directory.search(nickname_filter).concat(Directory.search(givenname_filter))
68
+ end
69
+
70
+ def Directory.find(args)
71
+ if args.key?(:andrew_id)
72
+ data = Directory.search('cmuAndrewId=' + args[:andrew_id])
73
+ elsif args.key?(:first_name)
74
+ data = Directory.search_by_name(args[:first_name])
75
+ elsif args.key?(:last_name)
76
+ data = Directory.search_by_name(args[:last_name])
77
+ elsif args.key?(:name)
78
+ data = Directory.search_by_name(args[:name])
79
+ else
80
+ data = nil
81
+ end
82
+ data.map { |person_hash| Directory::Person.new(person_hash) }
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Shen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ldap2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: cmurb provides a clean, simple interface for accessing CMU data. It currently
28
+ only supports directory data.
29
+ email: tom@shen.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - lib/cmu.rb
40
+ homepage: https://github.com/ScottyLabs/cmurb
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.0
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A library for CMU data
64
+ test_files: []
65
+ has_rdoc: