yaleldap 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12d18261da5f2af81134acde14dda46077a89652
4
- data.tar.gz: 5da0fffd53d2ec47c5486cec9f26a8a644da0ba9
3
+ metadata.gz: 22865d39103fa944e24f2889695cb00bcb35e1ae
4
+ data.tar.gz: 9f15790fe82aa385ff9ba4816549b32a568084b3
5
5
  SHA512:
6
- metadata.gz: 5c3df73a33cf141c6383d1b6175ed7eb7413a62c22301e362719d276ffb1a36de89cc4221a228964e8aa2151ded3ab470657bbf662a30dbe648086c5e343b8d0
7
- data.tar.gz: beac04df0d2afabfb7025b56f4bb7975746f77906b91a8169649b9df1ae65fd0b477fa0138e6e81945712a19744d981af498a6ffe20e472bd5b0ac4c7c67518d
6
+ metadata.gz: 7370b4871fe629f53934c40dbd8587884d5a45332d0ad56ea1de10f179f4e0803b7fcdfa5388891ab1582d0693251b5fbe3db250d58b6ea8b55bf80a3b3a11ba
7
+ data.tar.gz: a310204d85fbd47026089a50b69be846258d0e396bb24b9998882635d762ad0622d165629b2b0fba3719761f00eb473298d3906a20a262ebd346b66f3c7d8a74
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ script: bundle exec rspec spec
5
+ addons:
6
+ code_climate:
7
+ repo_token: 26473d8ac983f8c195675b3369530ea84d26ee1d1101dd0300caa29f7642eb41 bundle exec rake
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
3
4
  # Specify your gem's dependencies in yaleldap.gemspec
4
5
  gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', cmd: 'bundle exec rake' do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/yaleldap.svg)](http://badge.fury.io/rb/yaleldap)
2
2
  [![Dependency Status](https://gemnasium.com/YaleSTC/yaleldap.svg)](https://gemnasium.com/YaleSTC/yaleldap)
3
+ [![Build Status](https://travis-ci.org/YaleSTC/yaleldap.svg?branch=testinghound)](https://travis-ci.org/YaleSTC/yaleldap)
4
+ [![Code Climate](https://codeclimate.com/github/YaleSTC/yaleldap/badges/gpa.svg)](https://codeclimate.com/github/YaleSTC/yaleldap)
5
+ [![Test Coverage](https://codeclimate.com/github/YaleSTC/yaleldap/badges/coverage.svg)](https://codeclimate.com/github/YaleSTC/yaleldap)
3
6
  [![Inline docs](http://inch-ci.org/github/YaleSTC/yaleldap.png?branch=master)](http://inch-ci.org/github/YaleSTC/yaleldap)
4
7
 
5
- # Yaleldap
8
+ # YaleLDAP
6
9
 
7
- Automatically connects to the LDAP server if you are on campus/VPN. Can be queried by UPI, and it will return a simple ruby hash with the relevant information.
10
+ Offers the most common Yale LDAP search queries, returning a convenient ruby hash with names you can understand. Makes it easy to conserve your Yale users' time and energy, saving them from typing again and again that basic information they *know* mother Yale already has on record.
11
+
12
+ The LDAP server can only be connected to from Yale's campus or on Yale's VPN.
8
13
 
9
14
  ## Installation
10
15
 
@@ -24,29 +29,27 @@ Or install it yourself as:
24
29
 
25
30
  ###UPI
26
31
  ```
27
- YaleLDAP.lookup_by_upi("12714662")
28
- => {:first_name=>"Casey", :last_name=>"Watts", :yale_upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :collegename=>"", :college=>"", :class_year=>""}
32
+ YaleLDAP.lookup(upi: "12714662")
33
+ => {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
29
34
  ```
30
35
 
31
36
  ###NetID
32
37
  ```
33
- YaleLDAP.lookup_by_netid("csw3")
34
- => {:first_name=>"Casey", :last_name=>"Watts", :yale_upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :collegename=>"", :college=>"", :class_year=>""}
38
+ YaleLDAP.lookup(netid: "csw3")
39
+ => {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
35
40
  ```
36
41
 
37
42
  ###Email
38
43
  ```
39
- YaleLDAP.lookup_by_email("casey.watts@yale.edu")
40
- => {:first_name=>"Casey", :last_name=>"Watts", :yale_upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :collegename=>"", :college=>"", :class_year=>""}
44
+ YaleLDAP.lookup(email: "casey.watts@yale.edu")
45
+ => {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
41
46
  ```
42
47
 
43
48
 
44
49
  ## Documentation
45
- The source code is documented on rdoc.info
46
-
47
- <http://rdoc.info/github/YaleSTC/yaleldap/master/frames>
50
+ The source code is documented thoroughly, view it on [rdoc.info](http://rdoc.info/github/YaleSTC/yaleldap/master/frames)
48
51
 
49
- For more background on how the `net-ldap` gem works, check out this [Yale-specific gist](https://gist.github.com/caseywatts/ddea3996853050d1e5ad)
52
+ For more background on how the `net-ldap` gem works with specific Yale examples, check out this [Yale net-ldap gist](https://gist.github.com/caseywatts/ddea3996853050d1e5ad).
50
53
 
51
54
  ## Contributing
52
55
 
data/Rakefile CHANGED
@@ -1 +1,15 @@
1
- require "bundler/gem_tasks"
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ # RSpec::Core::RakeTask.new(:spec) do |task|
7
+ # task.rspec_opts = ['--color', '--format', 'documentation']
8
+ # end
9
+
10
+ # task spec do
11
+ # 'bundle exec rspec spec --color --format documentation'
12
+ # end
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+ task :default => :spec
@@ -1,5 +1,5 @@
1
1
  #Version Goes Here
2
2
  module YaleLDAP
3
3
  #Version Number
4
- VERSION = "0.0.2"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/yaleldap.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "yaleldap/version"
2
2
  require "net-ldap"
3
3
 
4
- #YaleLDAP Module is xyz
4
+ #YaleLDAP Module contains the logic for YaleLDAP
5
5
  module YaleLDAP
6
6
  # Yale's LDAP Host
7
7
  LDAP_HOST = 'directory.yale.edu'
@@ -12,101 +12,109 @@ module YaleLDAP
12
12
  # Specify to LDAP that we are searching for people
13
13
  LDAP_BASE = 'ou=People,o=yale.edu'
14
14
 
15
- # The most common Yale LDAP atttributes that we care about extracting
16
- LDAP_ATTRS = %w(uid givenname sn mail collegename college class UPI)
17
-
18
15
  ##
19
- # Lookup LDAP information by upi
20
- #
21
- # @param
22
- # upi as a string, ex "12714662"
16
+ # lookup by an arbitrary query (netid, email, upi, etc)
17
+ #
18
+ # @param [Hash] input_hash the query we're looking up with just one key-value pair. It expects the keys 'email', 'netid', 'upi'.
19
+ #
20
+ # @return [hash]
21
+ # our standard return hash (see README.md for a description of what it returns)
23
22
  #
24
- # @return
25
- # Standard hash (see extract_attributes)
26
- #
27
23
  # @example
28
- # YaleLDAP.lookup_by_upi("12714662")
24
+ # YaleLDAP.lookup(email: "casey.watts@yale.edu")
25
+ # YaleLDAP.lookup(netid: "csw3")
26
+ # YaleLDAP.lookup(upi: "12714662")
27
+ #
28
+ def self.lookup(input_hash)
29
+ lookup_filter = construct_filter(input_hash)
30
+ ldap_response = execute_query(lookup_filter)
31
+ attributes = extract_attributes(ldap_response)
32
+ return attributes
33
+ end
29
34
 
30
- def self.lookup_by_upi(upi)
31
- ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
32
- upifilter = Net::LDAP::Filter.eq('UPI', upi)
33
- ldap_response = ldap.search(base: LDAP_BASE,
34
- filter: upifilter,
35
- attributes: LDAP_ATTRS)
36
- extract_attributes(ldap_response)
35
+ private
36
+
37
+ ###
38
+ # Nickname Logic
39
+ ###
40
+
41
+ def self.convert_from_nickname(attribute)
42
+ attribute = attribute.to_s
43
+ nicknames[attribute]
37
44
  end
38
45
 
39
- ##
40
- # Lookup LDAP information by netid
41
- #
42
- # @param
43
- # netid as a string, ex "csw3"
44
- #
45
- # @return
46
- # Standard hash (see extract_attributes)
47
- #
48
- # @example
49
- # YaleLDAP.lookup_by_netid("csw3")
50
- #
51
- def self.lookup_by_netid(netid)
52
- ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
53
- upifilter = Net::LDAP::Filter.eq('uid', netid)
54
- ldap_response = ldap.search(base: LDAP_BASE,
55
- filter: upifilter,
56
- attributes: LDAP_ATTRS)
57
- extract_attributes(ldap_response)
46
+ def self.convert_to_nickname(attribute)
47
+ attribute = attribute.to_s
48
+ nicknames.invert[attribute]
58
49
  end
59
50
 
60
- ##
61
- # Lookup LDAP information by Yale email address
62
- #
63
- # @param
64
- # email as a string, ex "casey.watts@yale.edu"
65
- #
66
- # @return
67
- # Standard hash (see extract_attributes)
68
- #
69
- # @example
70
- # YaleLDAP.lookup_by_email("casey.watts@yale.edu")
71
- #
72
- def self.lookup_by_email(email)
51
+ def self.search_attributes
52
+ nicknames.values
53
+ end
54
+
55
+ def self.nicknames
56
+ # a list of attributes we care about
57
+ # "nickname" => "ldapname"
58
+ # "somethingthatmakessense" => "somethingjargony"
59
+ return {
60
+ "first_name" => "givenname",
61
+ "nickname" => "eduPersonNickname",
62
+ "last_name" => "sn",
63
+ "upi" => "UPI",
64
+ "netid" => "uid",
65
+ "email" => "mail",
66
+ "college_name" => "collegename",
67
+ "college_abbreviation" => "college",
68
+ "class_year" => "class",
69
+ "school" => "organizationUnitName",
70
+ "telephone" => "officePhone",
71
+ "address" => "postalAddress"
72
+ }
73
+ end
74
+
75
+
76
+
77
+ ###
78
+ #LDAP Search Logic
79
+ ###
80
+
81
+
82
+ # Constructs a Net::LDAP::Filter object out of our user input
83
+ # @param the input hash we want users to input, such as {:email => "casey.watts@yale.edu"}
84
+ # @return a net-ldap Net::LDAP::Filter object with our desired query
85
+ def self.construct_filter(input_hash)
86
+ query_type_nickname = input_hash.keys.first
87
+ query_value = input_hash.values.first
88
+ query_type_ldapname = convert_from_nickname(query_type_nickname)
89
+ lookup_filter = Net::LDAP::Filter.eq(query_type_ldapname, query_value)
90
+ return lookup_filter
91
+ end
92
+
93
+ # Executes the query on the LDAP server.
94
+ # @param a net-ldap Net::LDAP::Filter object with our desired query
95
+ # @return the raw net-ldap LDAP response object
96
+ def self.execute_query(lookup_filter)
73
97
  ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
74
- upifilter = Net::LDAP::Filter.eq('mail', email)
75
98
  ldap_response = ldap.search(base: LDAP_BASE,
76
- filter: upifilter,
77
- attributes: LDAP_ATTRS)
78
- extract_attributes(ldap_response)
99
+ filter: lookup_filter,
100
+ attributes: search_attributes)
101
+ return ldap_response
79
102
  end
80
103
 
81
- private
82
- #
83
- # Input a raw LDAP response
84
- #
85
- # Output is a hash with keys: first_name, last_name, upi, netid, email, collegename, college, class_year
86
- #
104
+
87
105
  def self.extract_attributes(ldap_response)
88
- # everyone has these
89
- first_name = ldap_response[0][:givenname][0]
90
- last_name = ldap_response[0][:sn][0]
91
- upi = ldap_response[0][:UPI][0]
92
-
93
- # not everyone has these
94
- netid = ldap_response[0][:uid][0] || ""
95
- email = ldap_response[0][:mail][0] || ""
96
- collegename = ldap_response[0][:collegename][0] || ""
97
- college = ldap_response[0][:college][0] || ""
98
- class_year = ldap_response[0][:class][0] || ""
106
+ attributes = {}
107
+ nicknames.each do |nickname, ldapname|
108
+ attribute = extract_attribute(ldap_response, ldapname)
109
+ attribute = attribute.gsub(/\$/,"\n") #for address
110
+ attributes[nickname.to_sym] = attribute
111
+ end
112
+ return attributes
113
+ end
99
114
 
100
- return {
101
- first_name: first_name,
102
- last_name: last_name,
103
- yale_upi: upi,
104
- netid: netid,
105
- email: email,
106
- collegename: collegename,
107
- college: college,
108
- class_year: class_year
109
- }
115
+ def self.extract_attribute(ldap_response, attribute_name)
116
+ attribute = ldap_response[0][attribute_name][0]
117
+ attribute ||= ""
110
118
  end
111
119
 
112
120
  end
@@ -0,0 +1,4 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'yaleldap'
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe YaleLDAP do
4
+ it 'does stuff' do
5
+ true.should be_truthy
6
+ end
7
+ xit 'does stuffz' do
8
+ raise "trouble"
9
+ end
10
+ end
data/yaleldap.gemspec CHANGED
@@ -20,5 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec", "~> 3.1.0"
26
+
23
27
  spec.add_runtime_dependency "net-ldap"
24
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaleldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - caseywatts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: net-ldap
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -61,12 +103,17 @@ extensions: []
61
103
  extra_rdoc_files: []
62
104
  files:
63
105
  - .gitignore
106
+ - .hound.yml
107
+ - .travis.yml
64
108
  - Gemfile
109
+ - Guardfile
65
110
  - LICENSE.txt
66
111
  - README.md
67
112
  - Rakefile
68
113
  - lib/yaleldap.rb
69
114
  - lib/yaleldap/version.rb
115
+ - spec/spec_helper.rb
116
+ - spec/yaleldap_spec.rb
70
117
  - yaleldap.gemspec
71
118
  homepage: http://github.com/YaleSTC/yaleldap
72
119
  licenses:
@@ -92,5 +139,7 @@ rubygems_version: 2.0.3
92
139
  signing_key:
93
140
  specification_version: 4
94
141
  summary: Easy connection to Yale's LDAP
95
- test_files: []
142
+ test_files:
143
+ - spec/spec_helper.rb
144
+ - spec/yaleldap_spec.rb
96
145
  has_rdoc: