clever 2.2.0 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31937aa6d83d7456eac854bd077475ddf5d39299
4
- data.tar.gz: 77406af9971e86d2044dee2fb97f39d26b5fc77e
3
+ metadata.gz: 77dbd6fdbbf2b13bdf7d7011c19f03d90db8ab4e
4
+ data.tar.gz: c98d3ea989e3c3cdfd0bd8114a412965c232c586
5
5
  SHA512:
6
- metadata.gz: fd292670c55b4206b3ba68dc009e79084e9eb6d601e2179d9a0b6f499542892a4ea470ec789dfb4f0aa244c85e0d5e06f49b1001a6ef92a8ee072c9fd7e67bda
7
- data.tar.gz: feea3b0b8dbd0e131bdfd1243425e924850a683c8f86e873b46d06b2f26f50e41abfda429c336440d587ea2a55f76487d40aa3c117b2d24653dd2c8823c71509
6
+ metadata.gz: 36c9a1621dedd554ff8959ec6f4477baa48a5832dde56fd4d64201fdb5bca3d8b02d502f443beff52978908164e9286b4897cc5aa546cf5b4f153764a381cf5e
7
+ data.tar.gz: 8de9b79585e796b400544747294ddbd4fd23e1688df9875497270004b80c988d6745147556ca23eb70c0b729c5c85f5a7d143b131ed173779220cd8c9c03810d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clever (2.2.0)
4
+ clever (3.1.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
data/lib/clever.rb CHANGED
@@ -17,18 +17,20 @@ require 'clever/types/event'
17
17
  require 'clever/types/student'
18
18
  require 'clever/types/section'
19
19
  require 'clever/types/teacher'
20
+ require 'clever/types/admin'
20
21
  require 'clever/types/term'
21
22
  require 'clever/types/token'
22
23
 
23
24
  module Clever
24
- API_URL = 'https://api.clever.com/v2.0'
25
+ API_URL = 'https://api.clever.com/v3.0'
25
26
  TOKENS_ENDPOINT = 'https://clever.com/oauth/tokens?owner_type=district'
26
- STUDENTS_ENDPOINT = '/v2.0/students'
27
- COURSES_ENDPOINT = '/v2.0/courses'
28
- SECTIONS_ENDPOINT = '/v2.0/sections'
29
- TEACHERS_ENDPOINT = '/v2.0/teachers'
27
+ STUDENTS_ENDPOINT = '/v3.0/users?role=student'
28
+ COURSES_ENDPOINT = '/v3.0/courses'
29
+ SECTIONS_ENDPOINT = '/v3.0/sections'
30
+ TEACHERS_ENDPOINT = '/v3.0/users?role=teacher'
31
+ ADMINS_ENDPOINT = '/v3.0/users?role=district_admin'
30
32
  EVENTS_ENDPOINT = '/v1.2/events'
31
- TERMS_ENDPOINT = '/v2.0/terms'
33
+ TERMS_ENDPOINT = '/v3.0/terms'
32
34
  GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
33
35
 
34
36
  class DistrictNotFound < StandardError; end
data/lib/clever/client.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Clever
4
4
  class Client
5
5
  attr_accessor :app_id, :app_token, :sync_id, :logger,
6
- :vendor_key, :vendor_secret, :username_source
6
+ :vendor_key, :vendor_secret, :username_source, :staff_username_source
7
7
 
8
8
  attr_reader :api_url, :tokens_endpoint
9
9
 
@@ -54,7 +54,7 @@ module Clever
54
54
  Paginator.fetch(connection, endpoint, :get, Types::Event, client: self).force
55
55
  end
56
56
 
57
- %i(students courses teachers sections terms).each do |record_type|
57
+ %i(students courses sections terms).each do |record_type|
58
58
  define_method(record_type) do |record_uids = []|
59
59
  authenticate
60
60
 
@@ -69,6 +69,19 @@ module Clever
69
69
  end
70
70
  end
71
71
 
72
+ def teachers(record_uids = [])
73
+ authenticate
74
+
75
+ teachers = Paginator.fetch(connection, Clever::TEACHERS_ENDPOINT, :get, Types::Teacher, client: self).force
76
+ admins = Paginator.fetch(connection, Clever::ADMINS_ENDPOINT, :get, Types::Admin, client: self).force
77
+
78
+ records = (admins + teachers).uniq(&:uid)
79
+
80
+ return records if record_uids.empty?
81
+
82
+ records.select { |record| record_uids.to_set.include?(record.uid) }
83
+ end
84
+
72
85
  # discard params to make the API behave the same as the one roster gem
73
86
  def classrooms(*)
74
87
  authenticate
@@ -136,7 +149,8 @@ module Clever
136
149
  section.teachers.each do |teacher_uid|
137
150
  enrollments[:teacher] << Types::Enrollment.new(
138
151
  'classroom_uid' => section.uid,
139
- 'user_uid' => teacher_uid
152
+ 'user_uid' => teacher_uid,
153
+ 'primary' => section.primary_teacher_uid == teacher_uid
140
154
  )
141
155
  end
142
156
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clever
4
+ module Types
5
+ class Admin < Teacher
6
+ def initialize(attributes = {}, *, client: nil)
7
+ @district_username = attributes.dig('roles', 'district_admin', 'credentials', 'district_username')
8
+ @email = attributes['email']
9
+ @first_name = attributes['name']['first']
10
+ @last_name = attributes['name']['last']
11
+ @legacy_id = attributes.dig('roles', 'district_admin', 'legacy_id')
12
+ @provider = 'clever'
13
+ @sis_id = attributes.dig('roles', 'district_admin', 'credentials', 'sis_id')
14
+ @uid = attributes['id']
15
+ @username = username(client)
16
+ @role = 'admin'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,12 +5,14 @@ module Clever
5
5
  class Enrollment < Base
6
6
  attr_reader :classroom_uid,
7
7
  :user_uid,
8
- :provider
8
+ :provider,
9
+ :primary
9
10
 
10
11
  def initialize(attributes = {})
11
- @classroom_uid = attributes['classroom_uid']
12
- @user_uid = attributes['user_uid']
13
- @provider = 'clever'
12
+ @classroom_uid = attributes['classroom_uid']
13
+ @user_uid = attributes['user_uid']
14
+ @provider = 'clever'
15
+ @primary = attributes.dig('primary') || false
14
16
  end
15
17
  end
16
18
  end
@@ -12,19 +12,21 @@ module Clever
12
12
  :students,
13
13
  :teachers,
14
14
  :term_id,
15
- :provider
15
+ :provider,
16
+ :primary_teacher_uid
16
17
 
17
18
  def initialize(attributes = {}, *)
18
- @uid = attributes['id']
19
- @name = attributes['name']
20
- @period = attributes['period']
21
- @course = attributes['course']
22
- @grades = [presence(attributes['grade'])].compact
23
- @subjects = [presence(attributes['subject'])].compact
24
- @students = attributes['students']
25
- @teachers = attributes['teachers']
26
- @term_id = attributes['term_id']
27
- @provider = 'clever'
19
+ @uid = attributes['id']
20
+ @name = attributes['name']
21
+ @period = attributes['period']
22
+ @course = attributes['course']
23
+ @grades = [presence(attributes['grade'])].compact
24
+ @subjects = [presence(attributes['subject'])].compact
25
+ @students = attributes['students']
26
+ @teachers = attributes['teachers']
27
+ @term_id = attributes['term_id']
28
+ @provider = 'clever'
29
+ @primary_teacher_uid = attributes['teacher']
28
30
  end
29
31
  end
30
32
  end
@@ -6,17 +6,19 @@ module Clever
6
6
  attr_reader :uid,
7
7
  :first_name,
8
8
  :last_name,
9
- :provider
9
+ :provider,
10
+ :legacy_id
10
11
 
11
12
  def initialize(attributes = {}, client: nil)
12
- @uid = attributes['id']
13
+ @district_username = attributes.dig('credentials', 'district_username')
14
+ @email = attributes['email']
13
15
  @first_name = attributes['name']['first']
14
16
  @last_name = attributes['name']['last']
15
- @district_username = attributes.dig('credentials', 'district_username')
17
+ @legacy_id = attributes.dig('roles', 'student', 'legacy_id')
18
+ @provider = 'clever'
16
19
  @sis_id = attributes['sis_id']
17
- @email = attributes['email']
20
+ @uid = attributes['id']
18
21
  @username = username(client)
19
- @provider = 'clever'
20
22
  end
21
23
 
22
24
  def username(client = nil)
@@ -7,14 +7,54 @@ module Clever
7
7
  :email,
8
8
  :first_name,
9
9
  :last_name,
10
- :provider
11
-
12
- def initialize(attributes = {}, *)
13
- @uid = attributes['id']
14
- @email = attributes['email']
15
- @first_name = attributes['name']['first']
16
- @last_name = attributes['name']['last']
17
- @provider = 'clever'
10
+ :provider,
11
+ :legacy_id,
12
+ :role
13
+
14
+ def initialize(attributes = {}, *, client: nil)
15
+ @district_username = attributes.dig('roles', 'teacher', 'credentials', 'district_username')
16
+ @email = attributes['email']
17
+ @first_name = attributes['name']['first']
18
+ @last_name = attributes['name']['last']
19
+ @legacy_id = attributes.dig('roles', 'teacher', 'legacy_id')
20
+ @provider = 'clever'
21
+ @sis_id = attributes.dig('roles', 'teacher', 'credentials', 'sis_id')
22
+ @uid = attributes['id']
23
+ @username = username(client)
24
+ @role = 'teacher'
25
+ end
26
+
27
+ def username(client = nil)
28
+ username_source = client&.staff_username_source
29
+
30
+ @username ||= presence(username_from(username_source))
31
+ end
32
+
33
+ def to_h
34
+ {
35
+ uid: @uid,
36
+ email: @email,
37
+ first_name: @first_name,
38
+ last_name: @last_name,
39
+ username: @username,
40
+ provider: @provider
41
+ }
42
+ end
43
+
44
+ private
45
+
46
+ def username_from(username_source)
47
+ return if blank?(username_source)
48
+
49
+ presence(instance_variable_get("@#{username_source}"))
50
+ end
51
+
52
+ def presence(field)
53
+ field unless blank?(field)
54
+ end
55
+
56
+ def blank?(field)
57
+ field.nil? || field == ''
18
58
  end
19
59
  end
20
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clever
4
- VERSION = '2.2.0'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clever
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Julius
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -192,6 +192,7 @@ files:
192
192
  - lib/clever/connection.rb
193
193
  - lib/clever/paginator.rb
194
194
  - lib/clever/response.rb
195
+ - lib/clever/types/admin.rb
195
196
  - lib/clever/types/base.rb
196
197
  - lib/clever/types/classroom.rb
197
198
  - lib/clever/types/course.rb