diff --git a/README.md b/README.md index 55e7fd0..9e72ede 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ This gem support requesting: - Sections - Classrooms - Enrollments + - Contacts + - Schools #### Students - Request all students: diff --git a/lib/clever.rb b/lib/clever.rb index afceb97..2909210 100644 --- a/lib/clever.rb +++ b/lib/clever.rb @@ -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' @@ -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 diff --git a/lib/clever/client.rb b/lib/clever/client.rb index e0bbb81..b5a7251 100644 --- a/lib/clever/client.rb +++ b/lib/clever/client.rb @@ -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 diff --git a/lib/clever/connection.rb b/lib/clever/connection.rb index 72f413e..ae92a98 100644 --- a/lib/clever/connection.rb +++ b/lib/clever/connection.rb @@ -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 diff --git a/lib/clever/paginator.rb b/lib/clever/paginator.rb index ee7a4a7..d66b490 100644 --- a/lib/clever/paginator.rb +++ b/lib/clever/paginator.rb @@ -31,8 +31,8 @@ def fetch end.lazy end - def self.fetch(*params) - new(*params).fetch + def self.fetch(...) + new(...).fetch end private diff --git a/lib/clever/types/contact.rb b/lib/clever/types/contact.rb new file mode 100644 index 0000000..0b6dd01 --- /dev/null +++ b/lib/clever/types/contact.rb @@ -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 diff --git a/lib/clever/types/school.rb b/lib/clever/types/school.rb new file mode 100644 index 0000000..aaa18ef --- /dev/null +++ b/lib/clever/types/school.rb @@ -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 diff --git a/lib/clever/types/section.rb b/lib/clever/types/section.rb index 52d3bc8..fa762c6 100644 --- a/lib/clever/types/section.rb +++ b/lib/clever/types/section.rb @@ -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 diff --git a/lib/clever/types/student.rb b/lib/clever/types/student.rb index b134a93..a1dd565 100644 --- a/lib/clever/types/student.rb +++ b/lib/clever/types/student.rb @@ -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) diff --git a/lib/clever/types/term.rb b/lib/clever/types/term.rb index f09c8fd..df16177 100644 --- a/lib/clever/types/term.rb +++ b/lib/clever/types/term.rb @@ -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 diff --git a/lib/clever/version.rb b/lib/clever/version.rb index f9c62a7..98a41f9 100644 --- a/lib/clever/version.rb +++ b/lib/clever/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Clever - VERSION = '3.2.5' + VERSION = '3.3.0' end