swot 0.2.13 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a49ff2011c0bce368851e99dd4b455d8b1cfcca5
4
+ data.tar.gz: 1d7fc4c436b7c369f182c5666fab45fe5c17cf2b
5
+ SHA512:
6
+ metadata.gz: 32318f590856ba9d84770e72becbcf372c4bc308a859048d9beac32fc40dd99e523c531ca55db991b37b95eebc88fd42b9a9f2592e2f97f9cf3077798a365619
7
+ data.tar.gz: ca9f2c2aa0c681316f617b0d1d5d09f2c281f2517d9bee6b4bf3875e5f512e05f6da5d04f887e4aa2d9298b78468917fc4fc1fd8f24605b51ddd7c3a8b3aac68
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ group :development do
6
6
  gem "rake", "~> 10.0.4"
7
7
  gem "shoulda", ">= 0"
8
8
  gem "rdoc", "~> 3.12"
9
- gem "bundler", "~> 1.2.1"
9
+ gem "bundler", "~> 1.5.0"
10
10
  gem "jeweler", "~> 1.8.3"
11
11
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Swot :apple:
2
2
 
3
+ [![Build Status](https://api.travis-ci.org/leereilly/swot.png)](https://travis-ci.org/leereilly/swot) ![](https://badge.fury.io/rb/swot.png)
4
+
3
5
  If you have a product or service and offer **academic discounts**, there's a good chance there's some manual component to the approval process. Perhaps `.edu` email addresses are automatically approved because, for the most part at least, they're associated with American post-secondary educational institutions. Perhaps `.ac.uk` email addresses are automatically approved because they're guaranteed to belong to British universities and colleges. Unfortunately, not every country has an education-specific TLD (Top Level Domain) and plenty of schools use `.com` or `.net`.
4
6
 
5
7
  Swot is a community-driven or crowdsourced library for verifying that domain names and email addresses are tied to a legitimate university of college - more specifically, an academic institution providing higher education in tertiary, quaternary or any other kind of post-secondary education in any country in the world.
@@ -51,10 +53,10 @@ Swot::school_name 'http://www.stanford.edu'
51
53
 
52
54
  ### Contributing to Swot
53
55
 
54
- Contributions welcome! Please see the [contribution guidelines](CONTRIBUTING.md) for details on how to add, update, or delete schools. Code contributions welcome too. Ports to different languages welcome too.
56
+ Contributions welcome! Please see the [contribution guidelines](CONTRIBUTING.md) for details on how to add, update, or delete schools. Code contributions and ports to different languages welcome too.
55
57
 
56
58
  **Thanks** to the following people for their contributions:
57
- @blutack, @captn3m0, @johndbritton, @johnotander, @pborreli, @rcurtis, @vikhyat,.
59
+ @blutack, @captn3m0, @chrishunt, @johndbritton, @johnotander, @pborreli, @rcurtis, @vikhyat,.
58
60
 
59
61
  **Special thanks** to @weppos for the [public_suffix](https://github.com/weppos/publicsuffix-ruby) gem :metal:
60
62
 
@@ -100,3 +102,8 @@ Hopefully, you'll be surprised by some of this:
100
102
  |`lsmu.com`|:heavy_check_mark:| Lugansk State Medical University in the Ukraine |
101
103
 
102
104
  If you verified this by visiting all of the websites, how long did it take you? Did you have fun? Imagine you had to do this 10 - 100 times every day. Now you know a little something about the inspiration for Swot. Swot can verify them all in a fraction of a second and remove a :poop: part of someone's job.
105
+
106
+ ### See Also
107
+
108
+ * [gman](https://github.com/benbalter/gman) - like swot, but for government emails
109
+
@@ -0,0 +1 @@
1
+ Bengal Engineering and Science University
@@ -0,0 +1 @@
1
+ University of South Wales
@@ -0,0 +1 @@
1
+ BRG Fadingerstraße Linz, Austria
@@ -0,0 +1,2 @@
1
+ Sault College of Applied Arts & Technology
2
+
@@ -0,0 +1 @@
1
+ Institut EURECOM
data/lib/swot.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'public_suffix'
2
2
 
3
3
  module Swot
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
 
6
6
  # These top-level domains are guaranteed to be academic institutions.
7
7
  ACADEMIC_TLDS = {
@@ -123,6 +123,13 @@ module Swot
123
123
  'vic.edu.au' => 1,
124
124
  }
125
125
 
126
+ # These are domains that snuck into the edu registry,
127
+ # but don't pass the education sniff test
128
+ # Note: domain must be a direct match
129
+ BLACKLIST = [
130
+ 'si.edu',
131
+ ]
132
+
126
133
  class << self
127
134
 
128
135
  # Figure out if an email or domain belongs to academic institution.
@@ -131,12 +138,13 @@ module Swot
131
138
  # false otherwise.
132
139
  def is_academic?(text)
133
140
  return false if text.nil?
134
- text.strip!
135
141
  begin
136
142
  domain = get_domain(text)
137
143
  return false if domain.nil?
138
144
 
139
- if ACADEMIC_TLDS[domain.tld]
145
+ if BLACKLIST.include? domain.name
146
+ false
147
+ elsif ACADEMIC_TLDS[domain.tld]
140
148
  true
141
149
  elsif match_academic_domain?(domain)
142
150
  true
@@ -157,11 +165,7 @@ module Swot
157
165
  #
158
166
  # Returns a string with the institution name; nil if nothing is found.
159
167
  def get_institution_name(text)
160
- text.strip!
161
- text.downcase!
162
- text = text.split("@")[1] if text.include? "@"
163
- domain = PublicSuffix.parse(text)
164
- name_from_academic_domain(domain)
168
+ name_from_academic_domain(get_domain(text))
165
169
  end
166
170
  alias_method :school_name, :get_institution_name
167
171
 
@@ -170,7 +174,7 @@ module Swot
170
174
  # Returns true if the domain name belongs to a known academic institution;
171
175
  # false otherwise.
172
176
  def match_academic_domain?(domain)
173
- File.exists?("#{File.expand_path(__FILE__+'/..')}/domains/#{domain.tld}/#{domain.sld}")
177
+ File.exists?(get_path(domain))
174
178
  end
175
179
 
176
180
  # Figure out the institutions' name based on the domain name.
@@ -178,10 +182,7 @@ module Swot
178
182
  # Return the institution name, or nil if not found.
179
183
  def name_from_academic_domain(domain)
180
184
  begin
181
- file = File.open("#{File.expand_path(__FILE__+'/..')}/domains/#{domain.tld}/#{domain.sld}", "rb")
182
- contents = file.read
183
- contents.strip!
184
- return contents
185
+ File.read(get_path(domain), :mode => "rb", :external_encoding => "UTF-8").strip
185
186
  rescue
186
187
  return nil
187
188
  end
@@ -191,17 +192,20 @@ module Swot
191
192
  #
192
193
  # Returns a string with the FQDN; nil if there's an error.
193
194
  def get_domain(text)
194
- text.strip!
195
- return false if text.nil?
196
- text.downcase!
197
- text = text.split("@")[1] if text.include? "@"
195
+ PublicSuffix.parse text.strip.downcase.match(domain_regex).captures.first
196
+ rescue
197
+ return nil
198
+ end
198
199
 
199
- begin
200
- domain = PublicSuffix.parse(text)
201
- return domain
202
- rescue
203
- return nil
204
- end
200
+ def get_path(domain)
201
+ File.join(File.dirname(__FILE__), "domains", domain.tld, domain.sld)
202
+ end
203
+
204
+ private
205
+
206
+ # http://rubular.com/r/uW2GqSxvqD
207
+ def domain_regex
208
+ /([^@\/:]+)[:\d]*$/
205
209
  end
206
210
  end
207
- end
211
+ end
data/swot.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "swot"
8
- s.version = "0.2.13"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lee Reilly"]
12
- s.date = "2013-05-28"
12
+ s.date = "2014-04-01"
13
13
  s.description = "email helpers"
14
14
  s.email = "lee@leereilly.net"
15
15
  s.extra_rdoc_files = [
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".rbenv-version",
21
+ ".ruby-version",
22
+ ".travis.yml",
22
23
  "CONTRIBUTING.md",
23
24
  "Gemfile",
24
25
  "LICENSE.txt",
@@ -331,6 +332,7 @@ Gem::Specification.new do |s|
331
332
  "lib/domains/ac.il/weizmann",
332
333
  "lib/domains/ac.il/wgalil",
333
334
  "lib/domains/ac.il/yvc",
335
+ "lib/domains/ac.in/becs",
334
336
  "lib/domains/ac.in/bitmesra",
335
337
  "lib/domains/ac.in/bits-pilani",
336
338
  "lib/domains/ac.in/daiict",
@@ -1257,6 +1259,7 @@ Gem::Specification.new do |s|
1257
1259
  "lib/domains/ac.uk/soas",
1258
1260
  "lib/domains/ac.uk/solent",
1259
1261
  "lib/domains/ac.uk/soton",
1262
+ "lib/domains/ac.uk/southwales",
1260
1263
  "lib/domains/ac.uk/ssees",
1261
1264
  "lib/domains/ac.uk/st-and",
1262
1265
  "lib/domains/ac.uk/st-patricks",
@@ -1355,6 +1358,7 @@ Gem::Specification.new do |s|
1355
1358
  "lib/domains/asso.fr/essca",
1356
1359
  "lib/domains/asso.fr/fupl",
1357
1360
  "lib/domains/asso.fr/ict-toulouse",
1361
+ "lib/domains/at/fadi",
1358
1362
  "lib/domains/at/fh-burgenland",
1359
1363
  "lib/domains/at/fh-hagenberg",
1360
1364
  "lib/domains/at/fh-joanneum",
@@ -1672,6 +1676,7 @@ Gem::Specification.new do |s|
1672
1676
  "lib/domains/ca/rrc",
1673
1677
  "lib/domains/ca/ryerson",
1674
1678
  "lib/domains/ca/sait",
1679
+ "lib/domains/ca/saultcollege",
1675
1680
  "lib/domains/ca/sfu",
1676
1681
  "lib/domains/ca/stfx",
1677
1682
  "lib/domains/ca/stmarys",
@@ -6331,6 +6336,7 @@ Gem::Specification.new do |s|
6331
6336
  "lib/domains/fr/essec",
6332
6337
  "lib/domains/fr/estp",
6333
6338
  "lib/domains/fr/eudil",
6339
+ "lib/domains/fr/eurecom",
6334
6340
  "lib/domains/fr/hec",
6335
6341
  "lib/domains/fr/hei",
6336
6342
  "lib/domains/fr/icam",
@@ -7695,25 +7701,25 @@ Gem::Specification.new do |s|
7695
7701
  s.homepage = "http://github.com/leereilly/swot"
7696
7702
  s.licenses = ["MIT"]
7697
7703
  s.require_paths = ["lib"]
7698
- s.rubygems_version = "1.8.23"
7704
+ s.rubygems_version = "2.0.14"
7699
7705
  s.summary = "email helpers"
7700
7706
 
7701
7707
  if s.respond_to? :specification_version then
7702
- s.specification_version = 3
7708
+ s.specification_version = 4
7703
7709
 
7704
7710
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
7705
7711
  s.add_runtime_dependency(%q<public_suffix>, [">= 0"])
7706
7712
  s.add_development_dependency(%q<rake>, ["~> 10.0.4"])
7707
7713
  s.add_development_dependency(%q<shoulda>, [">= 0"])
7708
7714
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
7709
- s.add_development_dependency(%q<bundler>, ["~> 1.2.1"])
7715
+ s.add_development_dependency(%q<bundler>, ["~> 1.5.0"])
7710
7716
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
7711
7717
  else
7712
7718
  s.add_dependency(%q<public_suffix>, [">= 0"])
7713
7719
  s.add_dependency(%q<rake>, ["~> 10.0.4"])
7714
7720
  s.add_dependency(%q<shoulda>, [">= 0"])
7715
7721
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
7716
- s.add_dependency(%q<bundler>, ["~> 1.2.1"])
7722
+ s.add_dependency(%q<bundler>, ["~> 1.5.0"])
7717
7723
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
7718
7724
  end
7719
7725
  else
@@ -7721,7 +7727,7 @@ Gem::Specification.new do |s|
7721
7727
  s.add_dependency(%q<rake>, ["~> 10.0.4"])
7722
7728
  s.add_dependency(%q<shoulda>, [">= 0"])
7723
7729
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
7724
- s.add_dependency(%q<bundler>, ["~> 1.2.1"])
7730
+ s.add_dependency(%q<bundler>, ["~> 1.5.0"])
7725
7731
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
7726
7732
  end
7727
7733
  end
data/test/test_swot.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'helper'
2
3
 
3
4
  class TestEmail < Test::Unit::TestCase
@@ -21,8 +22,8 @@ class TestEmail < Test::Unit::TestCase
21
22
  assert_equal Swot::is_academic?('stanford.edu'), true
22
23
  assert_equal Swot::is_academic?('slac.stanford.edu'), true
23
24
  assert_equal Swot::is_academic?('www.stanford.edu'), true
24
- #assert_equal Swot::is_academic?('http://www.stanford.edu'), true
25
- #assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true
25
+ assert_equal Swot::is_academic?('http://www.stanford.edu'), true
26
+ assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true
26
27
  assert_equal Swot::is_academic?('strath.ac.uk'), true
27
28
  assert_equal Swot::is_academic?('soft-eng.strath.ac.uk'), true
28
29
  assert_equal Swot::is_academic?('ugr.es'), true
@@ -46,10 +47,21 @@ class TestEmail < Test::Unit::TestCase
46
47
 
47
48
  should "returns name of valid institution" do
48
49
  assert_equal Swot::get_institution_name('lreilly@cs.strath.ac.uk'), "University of Strathclyde"
50
+ assert_equal Swot::get_institution_name('lreilly@fadi.at'), "BRG Fadingerstraße Linz, Austria"
51
+ end
52
+
53
+ should "returns nil when institution invalid" do
54
+ assert_equal Swot::get_institution_name('foo@shop.com'), nil
49
55
  end
50
56
 
51
57
  should "test aliased methods" do
52
58
  assert_equal Swot::academic?('stanford.edu'), true
53
59
  assert_equal Swot::school_name('lreilly@cs.strath.ac.uk'), "University of Strathclyde"
54
60
  end
61
+
62
+ should "fail blacklisted domains" do
63
+ ["si.edu", " si.edu ", "imposter@si.edu"].each do |domain|
64
+ assert_equal false, Swot::is_academic?(domain), "#{domain} should be denied"
65
+ end
66
+ end
55
67
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lee Reilly
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-28 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: public_suffix
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: shoulda
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rdoc
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,23 +69,20 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
85
- version: 1.2.1
75
+ version: 1.5.0
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
93
- version: 1.2.1
82
+ version: 1.5.0
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: jeweler
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -116,7 +103,8 @@ extra_rdoc_files:
116
103
  - README.md
117
104
  files:
118
105
  - .document
119
- - .rbenv-version
106
+ - .ruby-version
107
+ - .travis.yml
120
108
  - CONTRIBUTING.md
121
109
  - Gemfile
122
110
  - LICENSE.txt
@@ -429,6 +417,7 @@ files:
429
417
  - lib/domains/ac.il/weizmann
430
418
  - lib/domains/ac.il/wgalil
431
419
  - lib/domains/ac.il/yvc
420
+ - lib/domains/ac.in/becs
432
421
  - lib/domains/ac.in/bitmesra
433
422
  - lib/domains/ac.in/bits-pilani
434
423
  - lib/domains/ac.in/daiict
@@ -1355,6 +1344,7 @@ files:
1355
1344
  - lib/domains/ac.uk/soas
1356
1345
  - lib/domains/ac.uk/solent
1357
1346
  - lib/domains/ac.uk/soton
1347
+ - lib/domains/ac.uk/southwales
1358
1348
  - lib/domains/ac.uk/ssees
1359
1349
  - lib/domains/ac.uk/st-and
1360
1350
  - lib/domains/ac.uk/st-patricks
@@ -1453,6 +1443,7 @@ files:
1453
1443
  - lib/domains/asso.fr/essca
1454
1444
  - lib/domains/asso.fr/fupl
1455
1445
  - lib/domains/asso.fr/ict-toulouse
1446
+ - lib/domains/at/fadi
1456
1447
  - lib/domains/at/fh-burgenland
1457
1448
  - lib/domains/at/fh-hagenberg
1458
1449
  - lib/domains/at/fh-joanneum
@@ -1770,6 +1761,7 @@ files:
1770
1761
  - lib/domains/ca/rrc
1771
1762
  - lib/domains/ca/ryerson
1772
1763
  - lib/domains/ca/sait
1764
+ - lib/domains/ca/saultcollege
1773
1765
  - lib/domains/ca/sfu
1774
1766
  - lib/domains/ca/stfx
1775
1767
  - lib/domains/ca/stmarys
@@ -6429,6 +6421,7 @@ files:
6429
6421
  - lib/domains/fr/essec
6430
6422
  - lib/domains/fr/estp
6431
6423
  - lib/domains/fr/eudil
6424
+ - lib/domains/fr/eurecom
6432
6425
  - lib/domains/fr/hec
6433
6426
  - lib/domains/fr/hei
6434
6427
  - lib/domains/fr/icam
@@ -7792,29 +7785,25 @@ files:
7792
7785
  homepage: http://github.com/leereilly/swot
7793
7786
  licenses:
7794
7787
  - MIT
7788
+ metadata: {}
7795
7789
  post_install_message:
7796
7790
  rdoc_options: []
7797
7791
  require_paths:
7798
7792
  - lib
7799
7793
  required_ruby_version: !ruby/object:Gem::Requirement
7800
- none: false
7801
7794
  requirements:
7802
- - - ! '>='
7795
+ - - '>='
7803
7796
  - !ruby/object:Gem::Version
7804
7797
  version: '0'
7805
- segments:
7806
- - 0
7807
- hash: 4255369170415974051
7808
7798
  required_rubygems_version: !ruby/object:Gem::Requirement
7809
- none: false
7810
7799
  requirements:
7811
- - - ! '>='
7800
+ - - '>='
7812
7801
  - !ruby/object:Gem::Version
7813
7802
  version: '0'
7814
7803
  requirements: []
7815
7804
  rubyforge_project:
7816
- rubygems_version: 1.8.23
7805
+ rubygems_version: 2.0.14
7817
7806
  signing_key:
7818
- specification_version: 3
7807
+ specification_version: 4
7819
7808
  summary: email helpers
7820
7809
  test_files: []
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p194