danwoolley-numbertwopencil 0.1.2

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.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ NumberTwoPencil
2
+ Created by Dan Woolley, September 2008.
3
+
4
+
5
+ Education.com API requirements:
6
+ * Docs at http://www.education.com/webservice/documentation/
7
+ * Sign up for an API key at http://www.education.com/webservice/request/
8
+ * Terms of service at http://www.education.com/webservice/terms/
9
+ * This provider is pretty strict about tying your api key to an IP address. Contact them if you need
10
+ multiple IP's.
11
+
12
+
13
+ Library requirements:
14
+ * gem install json
15
+
16
+
17
+ Sample library usage:
18
+ require 'numbertwopencil'
19
+ foo = NumberTwoPencil.new(your_api_key)
20
+ params = { "zip" => "33432" }
21
+ data = foo.education_com_getSchools params
22
+ p data
23
+ data.each {|item| puts "#{item["schoolname"]}\t#{item["gradelevel"]}\t#{item["city"]}"}
24
+
25
+
26
+
27
+ Sample schoolSearch request using curl:
28
+ curl "http://www.education.com/service/service.php?f=schoolSearch&sn=sf&resf=json&key=your_education_com_api_key&zip=33432"
29
+
data/demo/demo.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'lib/numbertwopencil'
2
+
3
+ foo = NumberTwoPencil.new('your_education_com_api_key')
4
+
5
+ # education_com_getSchools
6
+ begin
7
+ params = { "zip" => "33486" }
8
+ data = foo.education_com_getSchools params
9
+ #p data
10
+ data.each {|item| puts "#{item["schoolname"]}\t#{item["gradelevel"]}\t#{item["schoolid"]}"}
11
+ rescue Exception => e
12
+ p e.message
13
+ end
14
+
15
+ # education_com_getStudentDiversity
16
+ begin
17
+ data = foo.education_com_getStudentDiversity '41160'
18
+ p data
19
+ rescue Exception => e
20
+ p e.message
21
+ end
22
+
23
+ # education_com_getTestScores
24
+ begin
25
+ data = foo.education_com_getTestScores '41160'
26
+ p data
27
+ rescue Exception => e
28
+ p e.message
29
+ end
30
+
31
+ # education_com_getTeacherStats
32
+ begin
33
+ data = foo.education_com_getTeacherStats '41160'
34
+ p data
35
+ rescue Exception => e
36
+ p e.message
37
+ end
38
+
39
+ # education_com_getSchoolReviews
40
+ begin
41
+ data = foo.education_com_getSchoolReviews '41160'
42
+ p data
43
+ rescue Exception => e
44
+ p e.message
45
+ end
46
+
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json' # gem install json
5
+
6
+ class NumberTwoPencil
7
+
8
+ @@education_com_webservice_url = 'http://www.education.com/service/service.php'
9
+
10
+ # foo = NumberTwoPencil.new('your-education_com-api-key)
11
+ def initialize(apikey)
12
+ @apikey = apikey
13
+ end
14
+
15
+ # Example:
16
+ # params = { "zip" => "33486" }
17
+ # data = foo.education_com_getSchools params
18
+ # p data
19
+ def education_com_getSchools(params)
20
+ # Allowed params: zip, city, state, address, distance, latitude, longitude
21
+ # Returns an array of school data in hashes, or nil, or raises an error
22
+
23
+ url = "#{@@education_com_webservice_url}?sn=sf&f=schoolSearch&resf=json&key=#{@apikey}"
24
+ params.each { |key, value| url << "&#{key}=#{value}" }
25
+
26
+ # The entire JSON data structure
27
+ data = fetch_result url
28
+ if data == nil or data.empty?
29
+ return nil
30
+ elsif Hash === data and data.has_key?("faultCode")
31
+ raise "#{data["faultType"].capitalize} #{data["faultCode"]}: #{data["faultString"].capitalize}"
32
+ else
33
+ # Just the school data as an array of hashes
34
+ return data.map {|item| item["school"]} rescue nil
35
+ end
36
+ end
37
+
38
+ # Example:
39
+ # data = foo.education_com_getStudentDiversity '41160'
40
+ # p data
41
+ def education_com_getStudentDiversity(schoolid)
42
+ # Returns a hash of diversity data, or nil, or raises an error
43
+
44
+ url = "#{@@education_com_webservice_url}?sn=sf&f=getStudentDiversity&resf=json&key=#{@apikey}&schoolid=#{schoolid}"
45
+
46
+ # The entire JSON data structure
47
+ data = fetch_result url
48
+ if data == nil or data.empty?
49
+ return nil
50
+ elsif Hash === data and data.has_key?("faultCode")
51
+ raise "#{data["faultType"].capitalize} #{data["faultCode"]}: #{data["faultString"].capitalize}"
52
+ else
53
+ return data
54
+ end
55
+ end
56
+
57
+ # Example:
58
+ # data = foo.education_com_getTestScores '41160'
59
+ # p data
60
+ def education_com_getTestScores(schoolid)
61
+ # Returns a hash of test score data, or nil, or raises an error
62
+
63
+ url = "#{@@education_com_webservice_url}?sn=sf&f=getTestScores&resf=json&key=#{@apikey}&schoolid=#{schoolid}"
64
+
65
+ # The entire JSON data structure
66
+ data = fetch_result url
67
+ if data == nil or data.empty?
68
+ return nil
69
+ elsif Hash === data and data.has_key?("faultCode")
70
+ raise "#{data["faultType"].capitalize} #{data["faultCode"]}: #{data["faultString"].capitalize}"
71
+ else
72
+ return data
73
+ end
74
+ end
75
+
76
+ # Example:
77
+ # data = foo.education_com_getTeacherStats '41160'
78
+ # p data
79
+ def education_com_getTeacherStats(schoolid)
80
+ # Returns an array teacher stat hash data, or nil, or raises an error
81
+
82
+ url = "#{@@education_com_webservice_url}?sn=sf&f=getTeacherStats&resf=json&key=#{@apikey}&schoolid=#{schoolid}"
83
+
84
+ # The entire JSON data structure
85
+ data = fetch_result url
86
+ if data == nil or data.empty?
87
+ return nil
88
+ elsif Hash === data and data.has_key?("faultCode")
89
+ raise "#{data["faultType"].capitalize} #{data["faultCode"]}: #{data["faultString"].capitalize}"
90
+ else
91
+ return data
92
+ end
93
+ end
94
+
95
+ # Example:
96
+ # data = foo.education_com_getSchoolReviews '41160'
97
+ # p data
98
+ def education_com_getSchoolReviews(schoolid)
99
+ # Returns a hash of review data, or nil, or raises an error
100
+
101
+ url = "#{@@education_com_webservice_url}?sn=sf&f=getReviews&resf=json&key=#{@apikey}&schoolid=#{schoolid}"
102
+
103
+ # The entire JSON data structure
104
+ data = fetch_result url
105
+ if data == nil or data.empty?
106
+ return nil
107
+ elsif Hash === data and data.has_key?("faultCode")
108
+ raise "#{data["faultType"].capitalize} #{data["faultCode"]}: #{data["faultString"].capitalize}"
109
+ else
110
+ return data
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def fetch_result(url)
117
+ puts url
118
+ #data = File.read("sample_data/schoolSearch.json")
119
+ data = Net::HTTP.get_response(URI.parse(URI.escape(url))).body
120
+ return JSON.parse(data) rescue nil
121
+ end
122
+
123
+ end
@@ -0,0 +1,55 @@
1
+ =begin
2
+ require 'rake/gempackagetask'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "NumberTwoPencil"
6
+ s.version = "0.1.1"
7
+ s.date = "2008-09-18"
8
+ s.author = "Dan Woolley"
9
+ s.email = "danwoolley@gmail.com"
10
+ s.summary = "Ruby library for accessing school data using the education.com web services."
11
+ s.files = FileList['lib/*.rb', 'test/*', 'sample_data/*', 'demo/demo.rb'].to_a
12
+ s.test_files = Dir.glob('test/*.rb')
13
+ s.require_path = "lib"
14
+ s.has_rdoc = false
15
+ s.extra_rdoc_files = ["README"]
16
+ end
17
+ =end
18
+
19
+ Gem::Specification.new do |s|
20
+ s.name = "numbertwopencil"
21
+ s.version = "0.1.2"
22
+ s.date = "2008-09-18"
23
+ s.summary = "Ruby library for accessing school data using the education.com web services."
24
+ s.email = "danwoolley@gmail.com"
25
+ s.homepage = "http://github.com/danwoolley/numbertwopencil"
26
+ s.description = "Ruby library for accessing school data using the education.com web services."
27
+ s.has_rdoc = false
28
+ s.authors = ["Dan Woolley"]
29
+ s.files = ["README",
30
+ "numbertwopencil.gemspec",
31
+ "lib/numbertwopencil.rb",
32
+ "demo/demo.rb",
33
+ "sample_data/schoolSearch.json",
34
+ "sample_data/schoolSearch.xml"]
35
+ =begin
36
+ s.test_files = ["test/test_actor.rb",
37
+ "test/test_blob.rb", "test/test_commit.rb",
38
+ "test/test_config.rb",
39
+ "test/test_diff.rb",
40
+ "test/test_git.rb",
41
+ "test/test_grit.rb",
42
+ "test/test_head.rb",
43
+ "test/test_real.rb",
44
+ "test/test_reality.rb",
45
+ "test/test_remote.rb",
46
+ "test/test_repo.rb",
47
+ "test/test_tag.rb",
48
+ "test/test_tree.rb"]
49
+ s.rdoc_options = ["--main", "README.txt"]
50
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
51
+ s.add_dependency("diff-lcs", ["> 0.0.0"])
52
+ s.add_dependency("mime-types", ["> 0.0.0"])
53
+ s.add_dependency("open4", ["> 0.0.0"])
54
+ =end
55
+ end
@@ -0,0 +1 @@
1
+ [{"school":{"schoolid":"41182","schoolname":"Boca Raton Elementary School","zip":"33432","address":"103 SW 1st Ave","city":"Boca Raton","AYPresult":"0","APIScore":"","distance":0,"enrollment":369,"gradelevel":"Elementary","gradesserved":"K-5 ","latitude":26.348398,"longitude":-80.089104,"phonenumber":"5613381454","schooldistrictname":"Palm Beach","schooltype":"Public","state":"FL","studentteacherratio":"13.3","website":"http:\/\/www.palmbeach.k12.fl.us\/BocaRatonES","nces_id":"120150001534"}},{"school":{"schoolid":"41240","schoolname":"Gulf Stream Goodwill Career Academy","zip":"33432","address":"269 NE 14TH St","city":"Boca Raton","AYPresult":"0","APIScore":"","distance":0,"enrollment":57,"gradelevel":"High","gradesserved":"9-12 ","latitude":26.364012,"longitude":-80.083206,"phonenumber":"5613671067","schooldistrictname":"Palm Beach","schooltype":"Charter","state":"FL","studentteacherratio":null,"website":null,"nces_id":"120150004023"}},{"school":{"schoolid":"97750","schoolname":"St Joan of Arc School","zip":"33432","address":"501 SW 3rd Ave","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":707,"gradelevel":"Elementary","gradesserved":"PK-8","latitude":26.344946,"longitude":-80.091782,"phonenumber":"(561)3927974","schooldistrictname":"FL Private Schools","schooltype":"Private","state":"FL","studentteacherratio":"20.94","website":null,"nces_id":"00257657"}},{"school":{"schoolid":"97941","schoolname":"Boca Raton Christian School","zip":"33432","address":"315 NW Fourth St","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":604,"gradelevel":"Elementary","gradesserved":"PK-12","latitude":26.353622,"longitude":-80.092239,"phonenumber":"(561)3912727","schooldistrictname":"FL Private Schools","schooltype":"Private","state":"FL","studentteacherratio":"12.36","website":null,"nces_id":"00261459"}},{"school":{"schoolid":"112235","schoolname":"Solomon Schechter Day School","zip":"33432","address":"333 SW 4th Ave","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":21,"gradelevel":"Elementary","gradesserved":"K-2","latitude":26.345854,"longitude":-80.095436,"phonenumber":"(561)7504240","schooldistrictname":"FL Private Schools","schooltype":"Private, Special Program Emphasis","state":"FL","studentteacherratio":"3.96","website":null,"nces_id":"A0301108"}},{"school":{"schoolid":"114596","schoolname":"St Andrew's School","zip":"33432","address":"3900 Jog Road","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":1069,"gradelevel":"Elementary","gradesserved":"K-12","latitude":26.385609,"longitude":-80.143723,"phonenumber":"(561)2102401","schooldistrictname":"FL Private Schools","schooltype":"Private","state":"FL","studentteacherratio":"8.76","website":null,"nces_id":"A9102006"}},{"school":{"schoolid":"118965","schoolname":"Temple Beth Elementary of Boca Raton N","zip":"33432","address":"333 SW 4th Ave","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":74,"gradelevel":"Elementary","gradesserved":"PK-K","latitude":26.345854,"longitude":-80.095436,"phonenumber":"(561)3919092","schooldistrictname":"FL Private Schools","schooltype":"Private, Early Childhood Program\/Day Care Center","state":"FL","studentteacherratio":"7.37","website":null,"nces_id":"A9701199"}},{"school":{"schoolid":"124165","schoolname":"Children's House of Boca Raton","zip":"33432","address":"100 Pine Circle","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":54,"gradelevel":"Elementary","gradesserved":"PK-K","latitude":26.351372,"longitude":-80.094116,"phonenumber":"(561)3910074","schooldistrictname":"FL Private Schools","schooltype":"Private, Montessori","state":"FL","studentteacherratio":"4.8","website":null,"nces_id":"K9301663"}},{"school":{"schoolid":"124166","schoolname":"Mece Inc","zip":"33432","address":"625 NE Mizner Blvd","city":"Boca Raton","AYPresult":"","APIScore":"","distance":0,"enrollment":112,"gradelevel":"Elementary","gradesserved":"PK-K","latitude":26.356331,"longitude":-80.083946,"phonenumber":"(561)3681215","schooldistrictname":"FL Private Schools","schooltype":"Private, Early Childhood Program\/Day Care Center","state":"FL","studentteacherratio":"12","website":null,"nces_id":"K9301665"}}]