From 6564a7d88619618a8cce21eeb630c1af120b15b0 Mon Sep 17 00:00:00 2001 From: hakim Date: Fri, 24 Jun 2022 14:55:55 +0100 Subject: [PATCH 1/5] Add missing endpoints - also added extra student attributes --- README.md | 2 ++ lib/clever.rb | 4 ++++ lib/clever/client.rb | 3 ++- lib/clever/types/contact.rb | 24 +++++++++++++++++++ lib/clever/types/school.rb | 28 ++++++++++++++++++++++ lib/clever/types/section.rb | 46 +++++++++++++++++++------------------ lib/clever/types/student.rb | 43 ++++++++++++++++++++++++---------- lib/clever/types/term.rb | 6 ++--- 8 files changed, 117 insertions(+), 39 deletions(-) create mode 100644 lib/clever/types/contact.rb create mode 100644 lib/clever/types/school.rb 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..87f2e81 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 = '/v2.0/contacts' + 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..2ffdc4d 100644 --- a/lib/clever/client.rb +++ b/lib/clever/client.rb @@ -70,11 +70,12 @@ 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 endpoint = Clever.const_get("#{record_type.upcase}_ENDPOINT") + p endpoint type = Types.const_get(record_type.to_s.capitalize[0..-2]) records = Paginator.fetch(connection, endpoint, :get, type, client: self).force diff --git a/lib/clever/types/contact.rb b/lib/clever/types/contact.rb new file mode 100644 index 0000000..8d3721d --- /dev/null +++ b/lib/clever/types/contact.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Clever + module Types + class Contact < Base + attr_reader :uid, :sis_id, :name, :students, :school, :district, + :phone_type, :phone, :email, :type, :relationship + + def initialize(attributes = {}, *) + @uid = attributes['id'] + @sis_id = attributes['sis_id'] + @name = attributes['name'] + @students = attributes['students'] + @school = attributes['school'] + @district = attributes['district'] + @phone_type = attributes['phone_type'] + @phone = attributes['phone'] + @email = attributes['email'] + @type = attributes['type'] + @relationship = attributes['relationship'] + 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 From a38fe08a9ddc9ab255d83edea3216a411d2894dd Mon Sep 17 00:00:00 2001 From: hakim Date: Fri, 24 Jun 2022 16:42:20 +0100 Subject: [PATCH 2/5] Remove debugging outputs --- lib/clever/client.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/clever/client.rb b/lib/clever/client.rb index 2ffdc4d..b5a7251 100644 --- a/lib/clever/client.rb +++ b/lib/clever/client.rb @@ -75,7 +75,6 @@ def events(starting_after) authenticate endpoint = Clever.const_get("#{record_type.upcase}_ENDPOINT") - p endpoint type = Types.const_get(record_type.to_s.capitalize[0..-2]) records = Paginator.fetch(connection, endpoint, :get, type, client: self).force From a9a8c835c3ca9c1843a4ff6c9e7d8574d807a494 Mon Sep 17 00:00:00 2001 From: hakim Date: Tue, 28 Jun 2022 10:13:29 +0100 Subject: [PATCH 3/5] Remove more debugging outputs --- lib/clever/connection.rb | 1 - 1 file changed, 1 deletion(-) 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 From 9063e241e7702a4e35fdc3d48c82cab5878b8068 Mon Sep 17 00:00:00 2001 From: hakim Date: Fri, 1 Mar 2024 17:04:59 +0000 Subject: [PATCH 4/5] Funnel kwargs into paginator initializer --- lib/clever/paginator.rb | 4 ++-- lib/clever/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/version.rb b/lib/clever/version.rb index f9c62a7..d7047a9 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.2.6' end From 5fe29f8145c1b0066028ee8527d455e6d36fd48d Mon Sep 17 00:00:00 2001 From: Hakim Aryan Date: Wed, 9 Jul 2025 13:00:08 +0100 Subject: [PATCH 5/5] Migrate contacts API endpoint to use v3 instead of v2 --- lib/clever.rb | 2 +- lib/clever/types/contact.rb | 20 ++++++++++++-------- lib/clever/version.rb | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/clever.rb b/lib/clever.rb index 87f2e81..2909210 100644 --- a/lib/clever.rb +++ b/lib/clever.rb @@ -37,7 +37,7 @@ module Clever SCHOOL_ADMINS_ENDPOINT = '/v3.0/users?role=staff' EVENTS_ENDPOINT = '/v1.2/events' TERMS_ENDPOINT = '/v3.0/terms' - CONTACTS_ENDPOINT = '/v2.0/contacts' + CONTACTS_ENDPOINT = '/v3.0/users?role=contact' SCHOOLS_ENDPOINT = '/v3.0/schools' GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade' diff --git a/lib/clever/types/contact.rb b/lib/clever/types/contact.rb index 8d3721d..0b6dd01 100644 --- a/lib/clever/types/contact.rb +++ b/lib/clever/types/contact.rb @@ -4,20 +4,24 @@ module Clever module Types class Contact < Base attr_reader :uid, :sis_id, :name, :students, :school, :district, - :phone_type, :phone, :email, :type, :relationship + :phone_type, :phone, :email def initialize(attributes = {}, *) @uid = attributes['id'] - @sis_id = attributes['sis_id'] - @name = attributes['name'] - @students = attributes['students'] + @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 = attributes['phone_type'] - @phone = attributes['phone'] + @phone_type = dig_contact_role(attributes, "phone_type") + @phone = dig_contact_role(attributes, "phone") @email = attributes['email'] - @type = attributes['type'] - @relationship = attributes['relationship'] + end + + private + + def dig_contact_role(attributes, key) + attributes.dig('roles', 'contact', key) end end end diff --git a/lib/clever/version.rb b/lib/clever/version.rb index d7047a9..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.6' + VERSION = '3.3.0' end