schoolfinder 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/README.rdoc +11 -0
- data/Rakefile +6 -37
- data/lib/schoolfinder.rb +1 -0
- data/lib/schoolfinder/client.rb +29 -17
- data/lib/schoolfinder/error.rb +4 -4
- data/lib/schoolfinder/response.rb +5 -5
- data/lib/schoolfinder/version.rb +3 -0
- data/schoolfinder.gemspec +20 -71
- data/spec/schoolfinder/client_spec.rb +63 -31
- data/spec/schoolfinder/error_spec.rb +1 -3
- data/spec/spec_helper.rb +5 -6
- metadata +79 -52
- data/VERSION +0 -1
- data/spec/spec.opts +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
Gemfile.lock
|
23
|
+
*.gem
|
24
|
+
spec/schoolfinder_api_key.yml
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -24,6 +24,17 @@ Create a new instance of the Schoolfinder Client
|
|
24
24
|
|
25
25
|
@schoolfinder = Schoolfinder::Client.new('your_api_key')
|
26
26
|
|
27
|
+
You can also pass an optional http timeout setting that httparty will pass to net/http
|
28
|
+
|
29
|
+
@schoolfinder = Schoolfinder::Client.new('your_api_key', 5)
|
30
|
+
|
31
|
+
This would make the response trigger a Timeout::Error on the request.
|
32
|
+
The client then rescues that request and passes a fake response that will trigger a Schoolfinder::Error with the code 0 and message "a timeout occured".
|
33
|
+
This is because Schoolfinder currently does not have a error code 0 (only 1-7, see here: http://www.education.com/webservice/documentation/?section=schoolsearch)
|
34
|
+
So this would raise a:
|
35
|
+
|
36
|
+
#<Schoolfinder::Error: Schoolfinder Error: a timeout occured (code: 0)>
|
37
|
+
|
27
38
|
The following methods are available to the Schoolfinder::Client class, each method corresponds to an api call
|
28
39
|
Each method returns a Schoolfinder::Response which responds to a call to :body
|
29
40
|
|
data/Rakefile
CHANGED
@@ -1,41 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "schoolfinder"
|
8
|
-
gem.summary = %Q{api wrapper for the education.com schoolfinder}
|
9
|
-
gem.description = %Q{api wrapper for the education.com schoolfinder}
|
10
|
-
gem.email = "tom.cocca@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/tcocca/schoolfinder"
|
12
|
-
gem.authors = ["tcocca"]
|
13
|
-
gem.add_dependency "httparty", ">= 0.6.1"
|
14
|
-
gem.add_dependency "hashie", ">= 0.3.1"
|
15
|
-
gem.add_dependency "rash", ">= 0.3.1"
|
16
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
|
-
gem.add_development_dependency "webmock", ">= 1.3.4"
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << 'lib' << 'spec'
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
30
|
-
|
31
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
-
spec.libs << 'lib' << 'spec'
|
33
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
-
spec.rcov = true
|
35
|
-
end
|
36
|
-
|
37
|
-
task :spec => :check_dependencies
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
38
6
|
|
7
|
+
task :test => :spec
|
39
8
|
task :default => :spec
|
40
9
|
|
41
10
|
require 'rake/rdoctask'
|
@@ -43,7 +12,7 @@ Rake::RDocTask.new do |rdoc|
|
|
43
12
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
13
|
|
45
14
|
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "
|
15
|
+
rdoc.title = "you_got_listed #{version}"
|
47
16
|
rdoc.rdoc_files.include('README*')
|
48
17
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
18
|
end
|
data/lib/schoolfinder.rb
CHANGED
data/lib/schoolfinder/client.rb
CHANGED
@@ -1,73 +1,85 @@
|
|
1
1
|
module Schoolfinder
|
2
2
|
class Client
|
3
|
-
|
3
|
+
|
4
4
|
include HTTParty
|
5
5
|
base_uri 'api.education.com'
|
6
6
|
format :json
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
attr_accessor :http_timeout
|
9
|
+
|
10
|
+
def initialize(api_key, http_timeout = nil)
|
9
11
|
self.class.default_params :key => api_key
|
10
12
|
self.class.default_params :sn => 'sf'
|
11
13
|
self.class.default_params :resf => 'json'
|
12
14
|
self.class.default_params :v => '3'
|
15
|
+
self.http_timeout = http_timeout
|
13
16
|
end
|
14
|
-
|
17
|
+
|
15
18
|
def school_search(optional_params = {})
|
16
19
|
params = {:f => 'schoolSearch'}
|
17
20
|
make_request(params, optional_params)
|
18
21
|
end
|
19
|
-
|
22
|
+
|
20
23
|
def test_rating(options)
|
21
24
|
params = {:f => 'getTestRating'}
|
22
25
|
make_request(params, options)
|
23
26
|
end
|
24
|
-
|
27
|
+
|
25
28
|
def student_diversity(options)
|
26
29
|
params = {:f => 'getStudentDiversity'}
|
27
30
|
make_request(params, options)
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
def test_scores(options)
|
31
34
|
params = {:f => 'getTestScores'}
|
32
35
|
make_request(params, options)
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
def teacher_stats(options)
|
36
39
|
params = {:f => 'getTeacherStats'}
|
37
40
|
make_request(params, options)
|
38
41
|
end
|
39
|
-
|
42
|
+
|
40
43
|
def student_stats(options)
|
41
44
|
params = {:f => 'getStudentStats'}
|
42
45
|
make_request(params, options)
|
43
46
|
end
|
44
|
-
|
47
|
+
|
45
48
|
def reviews(options)
|
46
49
|
params = {:f => 'getReviews'}
|
47
50
|
make_request(params, options)
|
48
51
|
end
|
49
|
-
|
52
|
+
|
50
53
|
def number_of(city, state)
|
51
54
|
params = {:f => 'numberOf', :city => city, :state => state}
|
52
55
|
make_request(params)
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
def district_search(options)
|
56
59
|
params = {:f => 'districtSearch'}
|
57
60
|
make_request(params, options)
|
58
61
|
end
|
59
|
-
|
62
|
+
|
60
63
|
def branding_data(optional_params = {})
|
61
64
|
params = {:f => 'gbd'}
|
62
65
|
make_request(params, optional_params)
|
63
66
|
end
|
64
|
-
|
67
|
+
|
65
68
|
private
|
66
|
-
|
69
|
+
|
67
70
|
def make_request(params, options = {})
|
68
71
|
params.merge!(options) unless options.blank?
|
69
|
-
|
72
|
+
http_params = {}
|
73
|
+
unless params.empty?
|
74
|
+
http_params[:query] = params
|
75
|
+
end
|
76
|
+
unless self.http_timeout.nil?
|
77
|
+
http_params[:timeout] = self.http_timeout
|
78
|
+
end
|
79
|
+
Schoolfinder::Response.new(self.class.get('/service/service.php', http_params))
|
80
|
+
rescue Timeout::Error
|
81
|
+
Schoolfinder::Response.new({"faultCode" => 0, "faultString" => "a timeout occured", "faultType" => "error"})
|
70
82
|
end
|
71
|
-
|
83
|
+
|
72
84
|
end
|
73
85
|
end
|
data/lib/schoolfinder/error.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Schoolfinder
|
2
2
|
class Error < Exception
|
3
|
-
|
3
|
+
|
4
4
|
attr_reader :code, :error
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(code, error)
|
7
7
|
@code = code
|
8
8
|
@error = error
|
9
9
|
super(message)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def message
|
13
13
|
"Schoolfinder Error: #{@error} (code: #{@code})"
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
17
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Schoolfinder
|
2
2
|
class Response
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :body
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(response)
|
7
7
|
rash_response(response)
|
8
8
|
if self.body.respond_to?('fault_string')
|
9
9
|
raise Schoolfinder::Error.new(self.body.fault_code, self.body.fault_string)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
private
|
14
|
-
|
14
|
+
|
15
15
|
def rash_response(response)
|
16
16
|
if response.is_a?(Array)
|
17
17
|
self.body = []
|
@@ -28,6 +28,6 @@ module Schoolfinder
|
|
28
28
|
self.body = response
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
33
|
end
|
data/schoolfinder.gemspec
CHANGED
@@ -1,81 +1,30 @@
|
|
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__)
|
3
|
+
require "schoolfinder/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = %q{schoolfinder}
|
8
|
-
s.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["tcocca"]
|
7
|
+
s.authors = ["Tom Cocca"]
|
12
8
|
s.date = %q{2011-10-16}
|
13
|
-
s.description = %q{
|
9
|
+
s.description = %q{Ruby API wrapper for education.com schoolfinder built with httparty}
|
14
10
|
s.email = %q{tom.cocca@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/schoolfinder.rb",
|
26
|
-
"lib/schoolfinder/client.rb",
|
27
|
-
"lib/schoolfinder/error.rb",
|
28
|
-
"lib/schoolfinder/response.rb",
|
29
|
-
"schoolfinder.gemspec",
|
30
|
-
"spec/responses/branding_data.json",
|
31
|
-
"spec/responses/district_search.json",
|
32
|
-
"spec/responses/failure.json",
|
33
|
-
"spec/responses/number_of.json",
|
34
|
-
"spec/responses/reviews.json",
|
35
|
-
"spec/responses/school_search.json",
|
36
|
-
"spec/responses/student_diversity.json",
|
37
|
-
"spec/responses/student_stats.json",
|
38
|
-
"spec/responses/teacher_stats.json",
|
39
|
-
"spec/responses/test_rating.json",
|
40
|
-
"spec/responses/test_scores.json",
|
41
|
-
"spec/schoolfinder/client_spec.rb",
|
42
|
-
"spec/schoolfinder/error_spec.rb",
|
43
|
-
"spec/schoolfinder_api_key.example.yml",
|
44
|
-
"spec/spec.opts",
|
45
|
-
"spec/spec_helper.rb"
|
46
|
-
]
|
47
11
|
s.homepage = %q{http://github.com/tcocca/schoolfinder}
|
48
|
-
s.
|
49
|
-
s.rubygems_version = %q{1.
|
50
|
-
s.summary = %q{api wrapper for
|
51
|
-
s.test_files = [
|
52
|
-
"spec/schoolfinder/client_spec.rb",
|
53
|
-
"spec/schoolfinder/error_spec.rb",
|
54
|
-
"spec/spec_helper.rb"
|
55
|
-
]
|
12
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
13
|
+
s.rubygems_version = %q{1.3.5}
|
14
|
+
s.summary = %q{ruby api wrapper for education.com schoolfinder}
|
56
15
|
|
57
|
-
|
58
|
-
|
16
|
+
s.version = Schoolfinder::VERSION
|
17
|
+
s.platform = Gem::Platform::RUBY
|
59
18
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
68
|
-
s.add_dependency(%q<hashie>, [">= 0.3.1"])
|
69
|
-
s.add_dependency(%q<rash>, [">= 0.3.1"])
|
70
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
71
|
-
s.add_dependency(%q<webmock>, [">= 1.3.4"])
|
72
|
-
end
|
73
|
-
else
|
74
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
75
|
-
s.add_dependency(%q<hashie>, [">= 0.3.1"])
|
76
|
-
s.add_dependency(%q<rash>, [">= 0.3.1"])
|
77
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
78
|
-
s.add_dependency(%q<webmock>, [">= 1.3.4"])
|
79
|
-
end
|
80
|
-
end
|
19
|
+
s.add_dependency "activesupport", "~> 3"
|
20
|
+
s.add_dependency "httparty", "~> 0.8.3"
|
21
|
+
s.add_dependency "rash", ">= 0.3.2"
|
22
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
23
|
+
s.add_development_dependency "rspec", ">= 2.5.0"
|
24
|
+
s.add_development_dependency "webmock", ">= 1.6.2"
|
81
25
|
|
26
|
+
s.require_paths = ['lib']
|
27
|
+
s.files = `git ls-files`.split("\n")
|
28
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
30
|
+
end
|
@@ -4,14 +4,37 @@ describe "Schoolfinder::Client" do
|
|
4
4
|
before(:each) do
|
5
5
|
@schoolfinder = new_schoolfinder
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
|
+
context "new client" do
|
9
|
+
it "should set the default params" do
|
10
|
+
@schoolfinder.class.default_params.should_not be_empty
|
11
|
+
@schoolfinder.class.default_params[:key].should == SCHOOLFINDER_API_KEY
|
12
|
+
@schoolfinder.class.default_params[:sn].should == 'sf'
|
13
|
+
@schoolfinder.class.default_params[:resf].should == 'json'
|
14
|
+
@schoolfinder.class.default_params[:v].should == '3'
|
15
|
+
@schoolfinder.http_timeout.should be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "new timeout client" do
|
20
|
+
it "should set the default params" do
|
21
|
+
@schoolfinder = new_timeout_schoolfinder
|
22
|
+
@schoolfinder.class.default_params.should_not be_empty
|
23
|
+
@schoolfinder.class.default_params[:key].should == SCHOOLFINDER_API_KEY
|
24
|
+
@schoolfinder.class.default_params[:sn].should == 'sf'
|
25
|
+
@schoolfinder.class.default_params[:resf].should == 'json'
|
26
|
+
@schoolfinder.class.default_params[:v].should == '3'
|
27
|
+
@schoolfinder.http_timeout.should == 5
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
8
31
|
context "school_search" do
|
9
32
|
before do
|
10
33
|
mock_get({"f" => "schoolSearch", "zip" => "29601"}, 'school_search.json')
|
11
34
|
end
|
12
|
-
|
35
|
+
|
13
36
|
it { lambda {@schoolfinder.school_search(:zip => "29601")}.should_not raise_exception }
|
14
|
-
|
37
|
+
|
15
38
|
it "should return a response" do
|
16
39
|
@response = @schoolfinder.school_search(:zip => "29601")
|
17
40
|
@response.should_not be_nil
|
@@ -19,14 +42,14 @@ describe "Schoolfinder::Client" do
|
|
19
42
|
@response.body.first.should be_kind_of(Hashie::Rash)
|
20
43
|
end
|
21
44
|
end
|
22
|
-
|
45
|
+
|
23
46
|
context "test_rating" do
|
24
47
|
before do
|
25
48
|
mock_get({"f" => "getTestRating", "nces_id" => "061029001146"}, 'test_rating.json')
|
26
49
|
end
|
27
|
-
|
50
|
+
|
28
51
|
it { lambda {@schoolfinder.test_rating(:nces_id => "061029001146")}.should_not raise_exception }
|
29
|
-
|
52
|
+
|
30
53
|
it "should return a response" do
|
31
54
|
@response = @schoolfinder.test_rating(:nces_id => "061029001146")
|
32
55
|
@response.should_not be_nil
|
@@ -34,84 +57,84 @@ describe "Schoolfinder::Client" do
|
|
34
57
|
@response.body.first.should be_kind_of(Hashie::Rash)
|
35
58
|
end
|
36
59
|
end
|
37
|
-
|
60
|
+
|
38
61
|
context "student_diversity" do
|
39
62
|
before do
|
40
63
|
mock_get({"f" => "getStudentDiversity", "nces_id" => "450231000564"}, 'student_diversity.json')
|
41
64
|
end
|
42
|
-
|
65
|
+
|
43
66
|
it { lambda {@schoolfinder.student_diversity(:nces_id => "450231000564")}.should_not raise_exception }
|
44
|
-
|
67
|
+
|
45
68
|
it "should return a response" do
|
46
69
|
@response = @schoolfinder.student_diversity(:nces_id => "450231000564")
|
47
70
|
@response.should_not be_nil
|
48
71
|
@response.body.should be_kind_of(Hashie::Rash)
|
49
72
|
end
|
50
73
|
end
|
51
|
-
|
74
|
+
|
52
75
|
context "test_scores" do
|
53
76
|
before do
|
54
77
|
mock_get({"f" => "getTestScores", "nces_id" => "450231000564"}, 'test_scores.json')
|
55
78
|
end
|
56
|
-
|
79
|
+
|
57
80
|
it { lambda {@schoolfinder.test_scores(:nces_id => "450231000564")}.should_not raise_exception }
|
58
|
-
|
81
|
+
|
59
82
|
it "should return a response" do
|
60
83
|
@response = @schoolfinder.test_scores(:nces_id => "450231000564")
|
61
84
|
@response.should_not be_nil
|
62
85
|
@response.body.should be_kind_of(Hashie::Rash)
|
63
86
|
end
|
64
87
|
end
|
65
|
-
|
88
|
+
|
66
89
|
context "teacher_stats" do
|
67
90
|
before do
|
68
91
|
mock_get({"f" => "getTeacherStats", "nces_id" => "450231000564", "districtleaid" => "4502310"}, 'teacher_stats.json')
|
69
92
|
end
|
70
|
-
|
93
|
+
|
71
94
|
it { lambda {@schoolfinder.teacher_stats(:nces_id => "450231000564", :districtleaid => "4502310")}.should_not raise_exception }
|
72
|
-
|
95
|
+
|
73
96
|
it "should return a response" do
|
74
97
|
@response = @schoolfinder.teacher_stats(:nces_id => "450231000564", :districtleaid => "4502310")
|
75
98
|
@response.should_not be_nil
|
76
99
|
@response.body.should be_kind_of(Hashie::Rash)
|
77
100
|
end
|
78
101
|
end
|
79
|
-
|
102
|
+
|
80
103
|
context "student_stats" do
|
81
104
|
before do
|
82
105
|
mock_get({"f" => "getStudentStats", "nces_id" => "450231000564", "districtleaid" => "4502310", "city" => "Greenville", "state" => "SC"}, 'student_stats.json')
|
83
106
|
end
|
84
|
-
|
107
|
+
|
85
108
|
it { lambda {@response = @schoolfinder.student_stats(:nces_id => "450231000564", :districtleaid => "4502310", :city => "Greenville", :state => "SC")}.should_not raise_exception }
|
86
|
-
|
109
|
+
|
87
110
|
it "should return a response" do
|
88
111
|
@response = @schoolfinder.student_stats(:nces_id => "450231000564", :districtleaid => "4502310", :city => "Greenville", :state => "SC")
|
89
112
|
@response.should_not be_nil
|
90
113
|
@response.body.should be_kind_of(Hashie::Rash)
|
91
114
|
end
|
92
115
|
end
|
93
|
-
|
116
|
+
|
94
117
|
context "reviews" do
|
95
118
|
before do
|
96
119
|
mock_get({"f" => "getReviews", "schoolid" => "25381"}, 'reviews.json')
|
97
120
|
end
|
98
|
-
|
121
|
+
|
99
122
|
it { lambda {@schoolfinder.reviews(:schoolid => "25381")}.should_not raise_exception }
|
100
|
-
|
123
|
+
|
101
124
|
it "should return a response" do
|
102
125
|
@response = @schoolfinder.reviews(:schoolid => "25381")
|
103
126
|
@response.should_not be_nil
|
104
127
|
@response.body.should be_kind_of(Hashie::Rash)
|
105
128
|
end
|
106
129
|
end
|
107
|
-
|
130
|
+
|
108
131
|
context "number_of" do
|
109
132
|
before do
|
110
133
|
mock_get({"f" => "numberOf", "city" => "Greenville", "state" => "SC"}, 'number_of.json')
|
111
134
|
end
|
112
|
-
|
135
|
+
|
113
136
|
it { lambda {@schoolfinder.number_of("Greenville", "SC")}.should_not raise_exception }
|
114
|
-
|
137
|
+
|
115
138
|
it "should return a response" do
|
116
139
|
@response = @schoolfinder.number_of("Greenville", "SC")
|
117
140
|
@response.should_not be_nil
|
@@ -119,14 +142,14 @@ describe "Schoolfinder::Client" do
|
|
119
142
|
@response.body.first.should be_kind_of(Hashie::Rash)
|
120
143
|
end
|
121
144
|
end
|
122
|
-
|
145
|
+
|
123
146
|
context "district_search" do
|
124
147
|
before do
|
125
148
|
mock_get({"f" => "districtSearch", "city" => "Greenville", "state" => "SC"}, 'district_search.json')
|
126
149
|
end
|
127
|
-
|
150
|
+
|
128
151
|
it { lambda {@schoolfinder.district_search(:city => "Greenville", :state => "SC")}.should_not raise_exception }
|
129
|
-
|
152
|
+
|
130
153
|
it "should return a response" do
|
131
154
|
@response = @schoolfinder.district_search(:city => "Greenville", :state => "SC")
|
132
155
|
@response.should_not be_nil
|
@@ -134,19 +157,28 @@ describe "Schoolfinder::Client" do
|
|
134
157
|
@response.body.first.should be_kind_of(Hashie::Rash)
|
135
158
|
end
|
136
159
|
end
|
137
|
-
|
160
|
+
|
138
161
|
context "branding_data" do
|
139
162
|
before do
|
140
163
|
mock_get({"f" => "gbd", "nces_id" => "450231000564"}, 'branding_data.json')
|
141
164
|
end
|
142
|
-
|
165
|
+
|
143
166
|
it { lambda {@schoolfinder.branding_data(:nces_id => "450231000564")}.should_not raise_exception }
|
144
|
-
|
167
|
+
|
145
168
|
it "should return a response" do
|
146
169
|
@response = @schoolfinder.branding_data(:nces_id => "450231000564")
|
147
170
|
@response.should_not be_nil
|
148
171
|
@response.body.should be_kind_of(Hashie::Rash)
|
149
172
|
end
|
150
173
|
end
|
151
|
-
|
174
|
+
|
175
|
+
context "timeout" do
|
176
|
+
it "should rescue a timeout error and raise a Schoolfinder::Error" do
|
177
|
+
stub_request(:get, "http://api.education.com/service/service.php?f=gbd&key=#{SCHOOLFINDER_API_KEY}&nces_id=450231000564&resf=json&sn=sf&v=3").to_timeout
|
178
|
+
lambda {
|
179
|
+
response = @schoolfinder.branding_data(:nces_id => "450231000564").should raise_exception(Schoolfinder::Error, "Schoolfinder Error: a timeout occured (code: 0)")
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
152
184
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Schoolfinder::Error" do
|
4
|
-
|
5
4
|
before do
|
6
5
|
mock_get({"f" => "getTestScores", "nces_id" => "450231000564"}, 'failure.json')
|
7
6
|
@schoolfinder = new_schoolfinder
|
8
7
|
end
|
9
|
-
|
8
|
+
|
10
9
|
it "should return an error" do
|
11
10
|
lambda {
|
12
11
|
@response = @schoolfinder.test_scores(:nces_id => "450231000564")
|
13
12
|
}.should raise_exception(Schoolfinder::Error, "Schoolfinder Error: invalid api key (code: 3)")
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'schoolfinder'
|
4
|
-
require '
|
5
|
-
require 'spec/autorun'
|
4
|
+
require 'rspec'
|
6
5
|
require 'webmock/rspec'
|
7
6
|
|
8
7
|
SCHOOLFINDER_API_KEY = YAML.load_file(File.join(File.dirname(__FILE__), 'schoolfinder_api_key.yml'))["api_key"]
|
9
8
|
|
10
|
-
Spec::Runner.configure do |config|
|
11
|
-
config.include WebMock
|
12
|
-
end
|
13
|
-
|
14
9
|
def new_schoolfinder
|
15
10
|
Schoolfinder::Client.new(SCHOOLFINDER_API_KEY)
|
16
11
|
end
|
17
12
|
|
13
|
+
def new_timeout_schoolfinder
|
14
|
+
Schoolfinder::Client.new(SCHOOLFINDER_API_KEY, 5)
|
15
|
+
end
|
16
|
+
|
18
17
|
def default_params
|
19
18
|
{"v" => "3", "key" => SCHOOLFINDER_API_KEY, "resf" => "json", "sn" => "sf"}
|
20
19
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schoolfinder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 1
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- Tom Cocca
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
@@ -19,104 +19,120 @@ date: 2011-10-16 00:00:00 -04:00
|
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
27
|
-
- -
|
25
|
+
- - ~>
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
hash: 5
|
30
28
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
|
34
|
-
version: 0.6.1
|
29
|
+
- 3
|
30
|
+
version: "3"
|
31
|
+
requirement: *id001
|
35
32
|
type: :runtime
|
36
|
-
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: hashie
|
33
|
+
name: activesupport
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
37
|
none: false
|
42
38
|
requirements:
|
43
|
-
- -
|
39
|
+
- - ~>
|
44
40
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
41
|
+
hash: 57
|
46
42
|
segments:
|
47
43
|
- 0
|
44
|
+
- 8
|
48
45
|
- 3
|
49
|
-
|
50
|
-
|
46
|
+
version: 0.8.3
|
47
|
+
requirement: *id002
|
51
48
|
type: :runtime
|
52
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rash
|
49
|
+
name: httparty
|
55
50
|
prerelease: false
|
56
|
-
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
53
|
none: false
|
58
54
|
requirements:
|
59
55
|
- - ">="
|
60
56
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
57
|
+
hash: 23
|
62
58
|
segments:
|
63
59
|
- 0
|
64
60
|
- 3
|
65
|
-
-
|
66
|
-
version: 0.3.
|
61
|
+
- 2
|
62
|
+
version: 0.3.2
|
63
|
+
requirement: *id003
|
67
64
|
type: :runtime
|
68
|
-
|
65
|
+
name: rash
|
66
|
+
prerelease: false
|
69
67
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 63
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
- 9
|
77
|
+
- 2
|
78
|
+
version: 0.9.2
|
79
|
+
requirement: *id004
|
80
|
+
type: :development
|
81
|
+
name: rake
|
71
82
|
prerelease: false
|
72
|
-
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
73
85
|
none: false
|
74
86
|
requirements:
|
75
87
|
- - ">="
|
76
88
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
89
|
+
hash: 27
|
78
90
|
segments:
|
79
|
-
- 1
|
80
91
|
- 2
|
81
|
-
-
|
82
|
-
|
92
|
+
- 5
|
93
|
+
- 0
|
94
|
+
version: 2.5.0
|
95
|
+
requirement: *id005
|
83
96
|
type: :development
|
84
|
-
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: webmock
|
97
|
+
name: rspec
|
87
98
|
prerelease: false
|
88
|
-
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
89
101
|
none: false
|
90
102
|
requirements:
|
91
103
|
- - ">="
|
92
104
|
- !ruby/object:Gem::Version
|
93
|
-
hash:
|
105
|
+
hash: 11
|
94
106
|
segments:
|
95
107
|
- 1
|
96
|
-
-
|
97
|
-
-
|
98
|
-
version: 1.
|
108
|
+
- 6
|
109
|
+
- 2
|
110
|
+
version: 1.6.2
|
111
|
+
requirement: *id006
|
99
112
|
type: :development
|
100
|
-
|
101
|
-
|
113
|
+
name: webmock
|
114
|
+
prerelease: false
|
115
|
+
description: Ruby API wrapper for education.com schoolfinder built with httparty
|
102
116
|
email: tom.cocca@gmail.com
|
103
117
|
executables: []
|
104
118
|
|
105
119
|
extensions: []
|
106
120
|
|
107
|
-
extra_rdoc_files:
|
108
|
-
|
109
|
-
- README.rdoc
|
121
|
+
extra_rdoc_files: []
|
122
|
+
|
110
123
|
files:
|
111
124
|
- .document
|
125
|
+
- .gitignore
|
126
|
+
- .rspec
|
127
|
+
- Gemfile
|
112
128
|
- LICENSE
|
113
129
|
- README.rdoc
|
114
130
|
- Rakefile
|
115
|
-
- VERSION
|
116
131
|
- lib/schoolfinder.rb
|
117
132
|
- lib/schoolfinder/client.rb
|
118
133
|
- lib/schoolfinder/error.rb
|
119
134
|
- lib/schoolfinder/response.rb
|
135
|
+
- lib/schoolfinder/version.rb
|
120
136
|
- schoolfinder.gemspec
|
121
137
|
- spec/responses/branding_data.json
|
122
138
|
- spec/responses/district_search.json
|
@@ -132,15 +148,14 @@ files:
|
|
132
148
|
- spec/schoolfinder/client_spec.rb
|
133
149
|
- spec/schoolfinder/error_spec.rb
|
134
150
|
- spec/schoolfinder_api_key.example.yml
|
135
|
-
- spec/spec.opts
|
136
151
|
- spec/spec_helper.rb
|
137
152
|
has_rdoc: true
|
138
153
|
homepage: http://github.com/tcocca/schoolfinder
|
139
154
|
licenses: []
|
140
155
|
|
141
156
|
post_install_message:
|
142
|
-
rdoc_options:
|
143
|
-
|
157
|
+
rdoc_options:
|
158
|
+
- --charset=UTF-8
|
144
159
|
require_paths:
|
145
160
|
- lib
|
146
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -167,8 +182,20 @@ rubyforge_project:
|
|
167
182
|
rubygems_version: 1.4.2
|
168
183
|
signing_key:
|
169
184
|
specification_version: 3
|
170
|
-
summary: api wrapper for
|
185
|
+
summary: ruby api wrapper for education.com schoolfinder
|
171
186
|
test_files:
|
187
|
+
- spec/responses/branding_data.json
|
188
|
+
- spec/responses/district_search.json
|
189
|
+
- spec/responses/failure.json
|
190
|
+
- spec/responses/number_of.json
|
191
|
+
- spec/responses/reviews.json
|
192
|
+
- spec/responses/school_search.json
|
193
|
+
- spec/responses/student_diversity.json
|
194
|
+
- spec/responses/student_stats.json
|
195
|
+
- spec/responses/teacher_stats.json
|
196
|
+
- spec/responses/test_rating.json
|
197
|
+
- spec/responses/test_scores.json
|
172
198
|
- spec/schoolfinder/client_spec.rb
|
173
199
|
- spec/schoolfinder/error_spec.rb
|
200
|
+
- spec/schoolfinder_api_key.example.yml
|
174
201
|
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.1
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|