getclever-ruby 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 (44) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +13 -0
  5. data/LICENSE +22 -0
  6. data/README.md +71 -0
  7. data/Rakefile +2 -0
  8. data/getclever-ruby.gemspec +24 -0
  9. data/lib/clever.rb +16 -0
  10. data/lib/clever/api.rb +162 -0
  11. data/lib/clever/configuration.rb +10 -0
  12. data/lib/clever/error.rb +12 -0
  13. data/lib/clever/fake_response.rb +8 -0
  14. data/lib/clever/fake_server.rb +2785 -0
  15. data/lib/clever/models/contact.rb +7 -0
  16. data/lib/clever/models/district.rb +7 -0
  17. data/lib/clever/models/photo.rb +7 -0
  18. data/lib/clever/models/school.rb +7 -0
  19. data/lib/clever/models/section.rb +7 -0
  20. data/lib/clever/models/student.rb +7 -0
  21. data/lib/clever/models/teacher.rb +7 -0
  22. data/lib/clever/version.rb +3 -0
  23. data/lib/generators/clever/install_generator.rb +24 -0
  24. data/lib/generators/clever/templates/clever.yml +8 -0
  25. data/lib/generators/clever/templates/initializer.rb +3 -0
  26. data/lib/generators/crocodoc.rb +11 -0
  27. data/spec/api_spec.rb +0 -0
  28. data/spec/configuration_spec.rb +11 -0
  29. data/spec/endpoints/districts_spec.rb +86 -0
  30. data/spec/endpoints/schools_spec.rb +88 -0
  31. data/spec/endpoints/sections_spec.rb +74 -0
  32. data/spec/endpoints/students_spec.rb +100 -0
  33. data/spec/endpoints/teachers_spec.rb +85 -0
  34. data/spec/error_spec.rb +0 -0
  35. data/spec/fake_server_spec.rb +0 -0
  36. data/spec/models/contact_spec.rb +38 -0
  37. data/spec/models/district_spec.rb +24 -0
  38. data/spec/models/photo_spec.rb +23 -0
  39. data/spec/models/school_spec.rb +53 -0
  40. data/spec/models/section_spec.rb +48 -0
  41. data/spec/models/student_spec.rb +73 -0
  42. data/spec/models/teacher_spec.rb +46 -0
  43. data/spec/spec_helper.rb +16 -0
  44. metadata +201 -0
@@ -0,0 +1,7 @@
1
+ class Clever::Models::Contact
2
+ attr_accessor :id, :email, :name, :phone, :phone_type, :type, :student_id
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::District
2
+ attr_accessor :id, :name
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::Photo
2
+ attr_accessor :id, :data
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::School
2
+ attr_accessor :id, :high_grade, :low_grade, :name, :nces_id, :phone, :school_number, :sis_id, :location, :principal, :last_modified
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::Section
2
+ attr_accessor :id, :grade, :name, :school_id, :sis_id, :section_number, :subject, :students, :teacher_id, :school_id, :district_id, :last_modified
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::Student
2
+ attr_accessor :id, :name, :dob, :frl_status, :gender, :grade, :hispanic_ethnicity, :race, :school_id, :sis_id, :state_id, :student_number, :location, :name, :district_id, :last_modified
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Clever::Models::Teacher
2
+ attr_accessor :id, :email, :name, :title, :sis_id, :last_modified, :school_id, :district_id
3
+
4
+ def initialize params
5
+ params.each { |k,v| instance_variable_set("@#{k}", v) unless v.nil? }
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Clever
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ module Clever
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ class_option :api_key, :type => :string, :banner => 'Your Clever API key', :required => true
5
+
6
+ def create_config_file
7
+ template 'clever.yml', File.join('config', 'clever.yml')
8
+ end
9
+
10
+ def create_initializer
11
+ template 'initializer.rb', File.join('config', 'initializers', 'clever.rb')
12
+ end
13
+
14
+ desc <<DESC
15
+ Description:
16
+ Copies Clever configuration file to your application's initializer directory.
17
+ DESC
18
+
19
+ def self.source_root
20
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ development:
2
+ token: '<%= options[:api_key] %>'
3
+
4
+ test:
5
+ token: '<%= options[:api_key] %>'
6
+
7
+ production:
8
+ token: '<%= options[:api_key] %>'
@@ -0,0 +1,3 @@
1
+ Clever.configure do |config|
2
+ config.api_key = YAML.load_file(Rails.root.join("config/clever.yml"))[Rails.env]['token']
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Clever
4
+ module Generators
5
+ class Base < ::Rails::Generators::NamedBase
6
+ def self.source_root
7
+ @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'clever', generator_name, 'templates'))
8
+ end
9
+ end
10
+ end
11
+ end
data/spec/api_spec.rb ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'configuration' do
4
+ it 'should accept an api_key and save it' do
5
+ Clever.configure do |config|
6
+ config.api_key = 'test1234'
7
+ end
8
+
9
+ Clever.config.api_key.should eq('test1234')
10
+ end
11
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'clever/api'
3
+
4
+ describe 'API' do
5
+ before do
6
+ Clever.configure do |config|
7
+ config.api_key = 'DEMO_KEY'
8
+ end
9
+
10
+ @api = Clever::API.new
11
+ @api.http = Clever::FakeServer.new({:api_key => Clever.config.api_key})
12
+ end
13
+
14
+ it "can get a list of districts" do
15
+ districts = @api.districts
16
+
17
+ districts.should.respond_to? :data
18
+
19
+ # exclude paging tests if no paging data found (accommodate live server tests rather than stubbed tests)
20
+ unless districts[:paging].nil?
21
+ districts[:paging][:current].should eq(1)
22
+ districts[:paging][:total].should eq(1)
23
+ districts[:paging][:count].should eq(1)
24
+ end
25
+
26
+ districts[:data][0].id.should eq('4fd43cc56d11340000000005')
27
+ districts[:data][0].name.should eq('Demo District')
28
+ end
29
+
30
+ it "can get a specific district" do
31
+ district = @api.district('4fd43cc56d11340000000005')
32
+
33
+ district.name.should eq('Demo District')
34
+ end
35
+
36
+ it "can get a list of schools for a given district" do
37
+ schools = @api.district_schools('4fd43cc56d11340000000005')
38
+
39
+ schools[:data].length.should eq(4)
40
+ schools[:data][0].name.should eq('Clever Academy')
41
+ end
42
+
43
+ it "can get a list of teachers for a given district" do
44
+ teachers = @api.district_teachers('4fd43cc56d11340000000005', {:limit => 10})
45
+
46
+ # exclude paging tests if no paging data found (accommodate live server tests rather than stubbed tests)
47
+ unless teachers[:paging].nil?
48
+ teachers[:paging][:current].should eq(1)
49
+ teachers[:paging][:total].should eq(5)
50
+ teachers[:paging][:count].should eq(50)
51
+ end
52
+
53
+ teachers[:data].length.should eq(10)
54
+
55
+ teachers[:data][0].id.should eq('4fee004dca2e43cf270007d5')
56
+ teachers[:data][0].email.should eq('ashlee@mailinator.com')
57
+ end
58
+
59
+ it "can get a list of students for a given district" do
60
+ students = @api.district_students('4fd43cc56d11340000000005', {:limit => 5})
61
+
62
+ unless students[:paging].nil?
63
+ students[:paging][:current].should eq(1)
64
+ students[:paging][:total].should eq(200)
65
+ students[:paging][:count].should eq(1000)
66
+ end
67
+
68
+ students[:data].length.should eq(5)
69
+ students[:data][0].id.should eq('4fee004cca2e43cf27000005')
70
+ students[:data][0].name['first'].should eq('Constance')
71
+ end
72
+
73
+ it "can get a list of sections for a given district" do
74
+ sections = @api.district_sections('4fd43cc56d11340000000005', {:limit => 2})
75
+
76
+ unless sections[:paging].nil?
77
+ sections[:paging][:current].should eq(1)
78
+ sections[:paging][:total].should eq(37)
79
+ sections[:paging][:count].should eq(73)
80
+ end
81
+
82
+ sections[:data].length.should eq(2)
83
+ sections[:data][0].id.should eq('4fee004dca2e43cf27000807')
84
+ sections[:data][0].name.should eq('Advanced Arithmetic 8(A)')
85
+ end
86
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'clever/api'
3
+
4
+ describe 'API' do
5
+ before do
6
+ Clever.configure do |config|
7
+ config.api_key = 'DEMO_KEY'
8
+ end
9
+
10
+ @api = Clever::API.new
11
+ @api.http = Clever::FakeServer.new({:api_key => Clever.config.api_key})
12
+ end
13
+
14
+ it "can get a list of schools" do
15
+ schools = @api.schools({:limit => 2})
16
+
17
+ schools.should.respond_to?(:data)
18
+
19
+ # exclude paging tests if no paging data found (accommodate live server tests rather than stubbed tests)
20
+ unless schools[:paging].nil?
21
+ schools[:paging][:current].should eq(1)
22
+ schools[:paging][:total].should eq(2)
23
+ schools[:paging][:count].should eq(4)
24
+ end
25
+
26
+ schools[:data].length.should eq(2)
27
+
28
+ schools[:data][0].id.should eq('4fee004cca2e43cf27000001')
29
+ schools[:data][0].name.should eq('Clever Academy')
30
+ end
31
+
32
+ it "can get a specific school" do
33
+ school = @api.school('4fee004cca2e43cf27000001')
34
+
35
+ school.name.should eq('Clever Academy')
36
+ end
37
+
38
+ it "can get a list of teachers for a given school" do
39
+ teachers = @api.school_teachers('4fee004cca2e43cf27000001', {:limit => 10})
40
+
41
+ # exclude paging tests if no paging data found (accommodate live server tests rather than stubbed tests)
42
+ unless teachers[:paging].nil?
43
+ teachers[:paging][:current].should eq(1)
44
+ teachers[:paging][:total].should eq(2)
45
+ teachers[:paging][:count].should eq(12)
46
+ end
47
+
48
+ teachers[:data].length.should eq(10)
49
+
50
+ teachers[:data][0].id.should eq('4fee004dca2e43cf270007d8')
51
+ teachers[:data][0].email.should eq('adaline_kunze@mailinator.com')
52
+ end
53
+
54
+ it "can get a list of students for a given school" do
55
+ students = @api.school_students('4fee004cca2e43cf27000001', {:limit => 4})
56
+
57
+ unless students[:paging].nil?
58
+ students[:paging][:current].should eq(1)
59
+ students[:paging][:total].should eq(60)
60
+ students[:paging][:count].should eq(239)
61
+ end
62
+
63
+ students[:data].length.should eq(4)
64
+ students[:data][0].id.should eq('4fee004cca2e43cf27000013')
65
+ students[:data][0].name['first'].should eq('Jacinthe')
66
+ end
67
+
68
+ it "can get a list of sections for a given school" do
69
+ sections = @api.school_sections('4fee004cca2e43cf27000001', {:limit => 2})
70
+
71
+ unless sections[:paging].nil?
72
+ sections[:paging][:current].should eq(1)
73
+ sections[:paging][:total].should eq(9)
74
+ sections[:paging][:count].should eq(17)
75
+ end
76
+
77
+ sections[:data].length.should eq(2)
78
+ sections[:data][0].id.should eq('4fee004dca2e43cf27000808')
79
+ sections[:data][0].name.should eq('Planetary Chemistry 5(B)')
80
+ end
81
+
82
+ it "can get the school's district" do
83
+ district = @api.school_district('4fee004cca2e43cf27000001')
84
+
85
+ district.name.should eq('Demo District')
86
+ district.id.should eq('4fd43cc56d11340000000005')
87
+ end
88
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'clever/api'
3
+
4
+ describe 'API' do
5
+ before do
6
+ Clever.configure do |config|
7
+ config.api_key = 'DEMO_KEY'
8
+ end
9
+
10
+ @api = Clever::API.new
11
+ @api.http = Clever::FakeServer.new({:api_key => Clever.config.api_key})
12
+ end
13
+
14
+ it "can get a list of sections" do
15
+ sections = @api.sections
16
+
17
+ sections.should.respond_to? :data
18
+
19
+ # exclude paging tests if no paging data found (accommodate live server tests rather than stubbed tests)
20
+ unless sections[:paging].nil?
21
+ sections[:paging][:current].should eq(1)
22
+ sections[:paging][:total].should eq(15)
23
+ sections[:paging][:count].should eq(73)
24
+ end
25
+
26
+ sections[:data][0].id.should eq('4fee004dca2e43cf27000807')
27
+ sections[:data][0].name.should eq('Advanced Arithmetic 8(A)')
28
+ end
29
+
30
+ it "can get a specific section" do
31
+ section = @api.section('4fee004dca2e43cf27000807')
32
+
33
+ section.id.should eq('4fee004dca2e43cf27000807')
34
+ section.name.should eq('Advanced Arithmetic 8(A)')
35
+ end
36
+
37
+ it "can get a school for a given section" do
38
+ school = @api.section_school('4fee004dca2e43cf27000807')
39
+
40
+ school.name.should eq('Clever Memorial High')
41
+ end
42
+
43
+ it "can get a district for a given section" do
44
+ district = @api.section_district('4fee004dca2e43cf27000807')
45
+
46
+ district.name.should eq('Demo District')
47
+ district.id.should eq('4fd43cc56d11340000000005')
48
+ end
49
+
50
+ it "can get a list of students for a given section" do
51
+ students = @api.section_students('4fee004dca2e43cf27000807', {:limit => 4})
52
+
53
+ unless students[:paging].nil?
54
+ students[:paging][:current].should eq(1)
55
+ students[:paging][:total].should eq(6)
56
+ students[:paging][:count].should eq(22)
57
+ end
58
+
59
+ students[:data].length.should eq(4)
60
+ students[:data][0].id.should eq('4fee004cca2e43cf27000043')
61
+ students[:data][0].name['first'].should eq('Mertie')
62
+ students[:data][0].name['m'].should eq(nil)
63
+ students[:data][0].name['last'].should eq('Volkman')
64
+ end
65
+
66
+ it "can get a teacher for a given section" do
67
+ teacher = @api.section_teacher('4fee004dca2e43cf27000807')
68
+
69
+ teacher.id.should eq('4fee004dca2e43cf270007f4')
70
+ teacher.name['first'].should eq('Estevan')
71
+ teacher.name['middle'].should eq('N')
72
+ teacher.name['last'].should eq('Braun')
73
+ end
74
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'clever/api'
3
+
4
+ describe 'API' do
5
+ before do
6
+ Clever.configure do |config|
7
+ config.api_key = 'DEMO_KEY'
8
+ end
9
+
10
+ @api = Clever::API.new
11
+ @api.http = Clever::FakeServer.new({:api_key => Clever.config.api_key})
12
+ end
13
+
14
+ it "can get a list of students" do
15
+ students = @api.students({:limit => 5})
16
+
17
+ unless students[:paging].nil?
18
+ students[:paging][:current].should eq(1)
19
+ students[:paging][:total].should eq(200)
20
+ students[:paging][:count].should eq(1000)
21
+ end
22
+
23
+ students[:data].length.should be(5)
24
+
25
+ students[:data][0].id.should eq('4fee004cca2e43cf27000005')
26
+ students[:data][0].name['first'].should eq('Constance')
27
+ students[:data][0].name['middle'].should eq('')
28
+ students[:data][0].name['last'].should eq('Roob')
29
+ end
30
+
31
+ it "can get a specific student" do
32
+ student = @api.student('4fee004cca2e43cf27000005')
33
+
34
+ student.id.should eq('4fee004cca2e43cf27000005')
35
+ student.name['first'].should eq('Constance')
36
+ student.name['middle'].should eq('')
37
+ student.name['last'].should eq('Roob')
38
+ end
39
+
40
+ it "can get a list of sections for a given student" do
41
+ sections = @api.student_sections('4fee004cca2e43cf27000005', {:limit => 2})
42
+
43
+ unless sections[:paging].nil?
44
+ sections[:paging][:current].should eq(1)
45
+ sections[:paging][:total].should eq(2)
46
+ sections[:paging][:count].should eq(4)
47
+ end
48
+
49
+ sections[:data].length.should eq(2)
50
+
51
+ sections[:data][0].id.should eq('4fee004dca2e43cf27000818')
52
+ sections[:data][0].name.should eq('Planetary Chemistry 1(B)')
53
+ end
54
+
55
+ it "can get a school for a given student" do
56
+ school = @api.student_school('4fee004cca2e43cf27000005')
57
+
58
+ school.id.should eq('4fee004cca2e43cf27000003')
59
+ school.name.should eq('Clever High School')
60
+ end
61
+
62
+ it "can get a district for a given student" do
63
+ district = @api.student_district('4fee004cca2e43cf27000005')
64
+
65
+ district.id.should eq('4fd43cc56d11340000000005')
66
+ district.name.should eq('Demo District')
67
+ end
68
+
69
+ it "can get a list of teachers for a given student" do
70
+ teachers = @api.student_teachers('4fee004cca2e43cf27000005', {:limit => 2})
71
+
72
+ unless teachers[:paging].nil?
73
+ teachers[:paging][:current].should eq(1)
74
+ teachers[:paging][:total].should eq(2)
75
+ teachers[:paging][:count].should eq(4)
76
+ end
77
+
78
+ teachers[:data].length.should eq(2)
79
+
80
+ teachers[:data][0].id.should eq('4fee004dca2e43cf270007d9')
81
+ teachers[:data][0].name['first'].should eq('Bridget')
82
+ teachers[:data][0].name['middle'].should eq('B')
83
+ teachers[:data][0].name['last'].should eq('Kulas')
84
+ end
85
+
86
+ it "can get a list of contacts for a given student" do
87
+ contacts = @api.student_contacts('4fee004cca2e43cf27000005', {:limit => 2})
88
+
89
+ contacts[:data].length.should eq(6)
90
+ contacts[:data][0].email.should eq('Samanta.Schaefer@mailinator.com')
91
+ contacts[:data][0].type.should eq('guardian')
92
+
93
+ end
94
+
95
+ it "can get a photo for a given student" do
96
+ photo = @api.student_photo('4fee004cca2e43cf27000005')
97
+
98
+ photo.id.should eq('4fee004cca2e43cf27000006')
99
+ end
100
+ end