Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ This gem support requesting:
- Sections
- Classrooms
- Enrollments
- Contacts
- Schools

#### Students
- Request all students:
Expand Down
4 changes: 4 additions & 0 deletions lib/clever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
require 'clever/types/student'
require 'clever/types/section'
require 'clever/types/teacher'
require 'clever/types/contact'
require 'clever/types/school'
require 'clever/types/district_admin'
require 'clever/types/school_admin'
require 'clever/types/term'
Expand All @@ -35,6 +37,8 @@ module Clever
SCHOOL_ADMINS_ENDPOINT = '/v3.0/users?role=staff'
EVENTS_ENDPOINT = '/v1.2/events'
TERMS_ENDPOINT = '/v3.0/terms'
CONTACTS_ENDPOINT = '/v3.0/users?role=contact'
SCHOOLS_ENDPOINT = '/v3.0/schools'
GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'

class DistrictNotFound < StandardError; end
Expand Down
2 changes: 1 addition & 1 deletion lib/clever/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def events(starting_after)
Paginator.fetch(connection, endpoint, :get, Types::Event, client: self).force
end

%i(students courses teachers sections terms).each do |record_type|
%i(students courses teachers sections terms contacts schools).each do |record_type|
define_method(record_type) do |record_uids = []|
authenticate

Expand Down
1 change: 0 additions & 1 deletion lib/clever/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def log(message = '')
private

def raw_request(path, method, params, body)
p "request #{path} #{params}"
connection.public_send(method) do |request|
request.options.open_timeout = OPEN_TIMEOUT
request.options.timeout = TIMEOUT
Expand Down
4 changes: 2 additions & 2 deletions lib/clever/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def fetch
end.lazy
end

def self.fetch(*params)
new(*params).fetch
def self.fetch(...)
new(...).fetch
end

private
Expand Down
28 changes: 28 additions & 0 deletions lib/clever/types/contact.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Clever
module Types
class Contact < Base
attr_reader :uid, :sis_id, :name, :students, :school, :district,
:phone_type, :phone, :email

def initialize(attributes = {}, *)
@uid = attributes['id']
@sis_id = dig_contact_role(attributes, "sis_id")
@name = attributes.dig('name', 'last')
@students = dig_contact_role(attributes, "student_relationships")
@school = attributes['school']
@district = attributes['district']
@phone_type = dig_contact_role(attributes, "phone_type")
@phone = dig_contact_role(attributes, "phone")
@email = attributes['email']
end

private

def dig_contact_role(attributes, key)
attributes.dig('roles', 'contact', key)
end
end
end
end
28 changes: 28 additions & 0 deletions lib/clever/types/school.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Clever
module Types
class School < Base
attr_reader :uid, :district, :name, :high_grade, :low_grade, :state_id, :sis_id,
:provider, :school_number, :phone, :location, :charter_school, :principal

def initialize(attributes = {}, *, client: nil)
@uid = attributes['id']
@district = attributes['district']
@high_grade = attributes['high_grade']
@name = attributes['name']
@low_grade = attributes['low_grade']
@state_id = attributes['state_id']
@school_number = attributes['school_number']
@phone = attributes['phone']
@location = attributes['location']
@charter_school = attributes.fetch('ext', 'charter_school')
@principal = attributes['principal']
@sis_id = attributes['sis_id']
@provider = 'clever'
@created = attributes['created']
@last_modified = attributes['last_modified']
end
end
end
end
46 changes: 24 additions & 22 deletions lib/clever/types/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
module Clever
module Types
class Section < Base
attr_reader :uid,
:name,
:period,
:course,
:grades,
:subjects,
:students,
:teachers,
:term_id,
:provider,
:primary_teacher_uid

attr_reader :uid, :name, :period, :course, :grades, :subjects, :students,
:teachers, :term_id, :provider, :primary_teacher_uid, :district, :school,
:section_number, :sis_id, :grade, :subject
def initialize(attributes = {}, *)
@uid = attributes['id']
@name = attributes['name']
@period = attributes['period']
@course = attributes['course']
@grades = [presence(attributes['grade'])].compact
@subjects = [presence(attributes['subject'])].compact
@students = attributes['students']
@teachers = attributes['teachers']
@term_id = attributes['term_id']
@provider = 'clever'
@uid = attributes['id']
@name = attributes['name']
@period = attributes['period']
@course = attributes['course']
@district = attributes['district']
@classroom = attributes.dig('ext', 'classroom')
@grade = attributes['grade']
@subject = attributes['subject']
@school = attributes['school']
@section_number = attributes['section_number']
@sis_id = attributes['sis_id']
@grade = attributes['grade']
@subject = attributes['subject']
@grades = [presence(attributes['grade'])].compact
@subjects = [presence(attributes['subject'])].compact
@students = attributes['students']
@teachers = attributes['teachers']
@term_id = attributes['term_id']
@provider = 'clever'
@primary_teacher_uid = attributes['teacher']
@created = attributes['created']
@last_modified = attributes['last_modified']
end
end
end
Expand Down
43 changes: 31 additions & 12 deletions lib/clever/types/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@
module Clever
module Types
class Student < Base
attr_reader :uid,
:first_name,
:last_name,
:provider
attr_reader :district_username, :email, :uid, :first_name, :last_name,
:middle_name, :provider, :sis_id, :dob, :grade, :enrollments,
:gifted_status, :gender, :graduation_year, :hispanic_ethnicity, :hispanic_ethnicity,
:location, :race, :school, :schools, :state_id, :student_number, :username


def initialize(attributes = {}, client: nil)
@district_username = attributes.dig('credentials', 'district_username')
@email = attributes['email']
@first_name = attributes['name']['first']
@last_name = attributes['name']['last']
@provider = 'clever'
@sis_id = attributes.dig('roles', 'student', 'sis_id')
@uid = attributes['id']
@username = username(client)
student = attributes.dig('roles', 'student')

@uid = attributes['id']
@district_username = student.dig('credentials', 'district_username')
@email = attributes['email']
@first_name = attributes['name']['first']
@last_name = attributes['name']['last']
@middle_name = attributes['name']['middle']
@provider = 'clever'
@sis_id = student['sis_id']
@dob = student['dob']
@grade = student['grade']
@enrollments = student['enrollments']
@gifted_status = student.dig('ext', 'gifted_status')
@gender = student['gender']
@graduation_year = student['graduation_year']
@hispanic_ethnicity = student['hispanic_ethnicity']
@location = student['location']
@race = student['race']
@school = student['school']
@schools = student['schools']
@state_id = student['state_id']
@student_number = student['student_number']
@username = username(client)
@created = attributes['created']
@last_modified = attributes['last_modified']
end

def username(client = nil)
Expand Down
6 changes: 2 additions & 4 deletions lib/clever/types/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
module Clever
module Types
class Term < Base
attr_reader :uid,
:name,
:start_date,
:end_date
attr_reader :uid, :name, :start_date, :end_date, :district

def initialize(attributes = {}, *)
@uid = attributes['id']
@name = attributes['name']
@start_date = attributes['start_date']
@end_date = attributes['end_date']
@district = attributes['district']
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/clever/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Clever
VERSION = '3.2.5'
VERSION = '3.3.0'
end