clever 2.3.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c35d6eada204a0058fad8c09d0bd59a63a928255
4
- data.tar.gz: 467317854d78559603c9d829899b9adc9cc20cfa
3
+ metadata.gz: 86d6af37efac719fa831d86a65862a402eb5af65
4
+ data.tar.gz: 46c1a1e4142338704353295934719e109b09e28f
5
5
  SHA512:
6
- metadata.gz: 7595b689345c6a9dc347a561f7c0674ae4a82d53b436455f6ce8e5b0bfb278ac39ccb63e625ffbd052a08c291c426f810927d89c6a3c72e8723c0a071d2b9642
7
- data.tar.gz: 6dc199bfa6d54d851a607cb04d52edb3c5393a5515e28c89ddf6aa6ab1790ecfd542d6405d80dfadb98152c6a7a658ebfb923f24aaacbb20026e40d7237d4e4f
6
+ metadata.gz: e21034624a92171120aa45364bbdc347696c5a65377907703c1297ddf94ee06638884f9d8ba02b2ff2bb133e40947135322c3391207448a114769c483b6e6615
7
+ data.tar.gz: 41d92685a37b57957ea89584ea60daa52950dfde939529d32daab129352c2e4f3a43ca6caa09debbbb8e71842b0cc6efbfb4f787a99c32cbe460ced858097197
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clever (2.3.1)
4
+ clever (3.2.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
data/lib/clever.rb CHANGED
@@ -17,19 +17,23 @@ 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/district_admin'
21
+ require 'clever/types/school_admin'
20
22
  require 'clever/types/term'
21
23
  require 'clever/types/token'
22
24
 
23
25
  module Clever
24
- API_URL = 'https://api.clever.com/v2.0'
25
- 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'
30
- EVENTS_ENDPOINT = '/v1.2/events'
31
- TERMS_ENDPOINT = '/v2.0/terms'
32
- GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
26
+ API_URL = 'https://api.clever.com/v3.0'
27
+ TOKENS_ENDPOINT = 'https://clever.com/oauth/tokens?owner_type=district'
28
+ STUDENTS_ENDPOINT = '/v3.0/users?role=student'
29
+ COURSES_ENDPOINT = '/v3.0/courses'
30
+ SECTIONS_ENDPOINT = '/v3.0/sections'
31
+ TEACHERS_ENDPOINT = '/v3.0/users?role=teacher'
32
+ DISTRICT_ADMINS_ENDPOINT = '/v3.0/users?role=district_admin'
33
+ SCHOOL_ADMINS_ENDPOINT = '/v3.0/users?role=staff'
34
+ EVENTS_ENDPOINT = '/v1.2/events'
35
+ TERMS_ENDPOINT = '/v3.0/terms'
36
+ GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
33
37
 
34
38
  class DistrictNotFound < StandardError; end
35
39
  class ConnectionError < StandardError; end
data/lib/clever/client.rb CHANGED
@@ -8,8 +8,8 @@ module Clever
8
8
  attr_reader :api_url, :tokens_endpoint
9
9
 
10
10
  def initialize
11
- @api_url = API_URL
12
- @tokens_endpoint = TOKENS_ENDPOINT
11
+ @api_url = API_URL
12
+ @tokens_endpoint = TOKENS_ENDPOINT
13
13
  end
14
14
 
15
15
  def self.configure
@@ -69,6 +69,22 @@ module Clever
69
69
  end
70
70
  end
71
71
 
72
+ def admins(record_uids = [])
73
+ authenticate
74
+
75
+ district_admins = Paginator.fetch(connection, Clever::DISTRICT_ADMINS_ENDPOINT,
76
+ :get, Types::DistrictAdmin, client: self).force
77
+
78
+ school_admins = Paginator.fetch(connection, Clever::SCHOOL_ADMINS_ENDPOINT,
79
+ :get, Types::SchoolAdmin, client: self).force
80
+
81
+ admins = (district_admins + school_admins).uniq(&:uid)
82
+
83
+ return admins if record_uids.empty?
84
+
85
+ admins.select { |record| record_uids.to_set.include?(record.uid) }
86
+ end
87
+
72
88
  # discard params to make the API behave the same as the one roster gem
73
89
  def classrooms(*)
74
90
  authenticate
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clever
4
+ module Types
5
+ class DistrictAdmin < 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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clever
4
+ module Types
5
+ class SchoolAdmin < Teacher
6
+ def initialize(attributes = {}, *, client: nil)
7
+ @district_username = attributes.dig('roles', 'staff', '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', 'staff', 'legacy_id')
12
+ @provider = 'clever'
13
+ @sis_id = attributes.dig('roles', 'staff', 'credentials', 'sis_id')
14
+ @uid = attributes['id']
15
+ @username = username(client)
16
+ @role = 'admin'
17
+ end
18
+ end
19
+ end
20
+ 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,17 +7,21 @@ module Clever
7
7
  :email,
8
8
  :first_name,
9
9
  :last_name,
10
- :provider
10
+ :provider,
11
+ :legacy_id,
12
+ :role
11
13
 
12
14
  def initialize(attributes = {}, *, client: nil)
13
- @uid = attributes['id']
14
- @email = attributes['email']
15
- @first_name = attributes['name']['first']
16
- @last_name = attributes['name']['last']
17
- @district_username = attributes.dig('credentials', 'district_username')
18
- @sis_id = attributes['sis_id']
19
- @username = username(client)
20
- @provider = 'clever'
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'
21
25
  end
22
26
 
23
27
  def username(client = nil)
@@ -26,6 +30,17 @@ module Clever
26
30
  @username ||= presence(username_from(username_source))
27
31
  end
28
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
+
29
44
  private
30
45
 
31
46
  def username_from(username_source)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clever
4
- VERSION = '2.3.1'
4
+ VERSION = '3.2.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.3.1
4
+ version: 3.2.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-09-28 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -195,8 +195,10 @@ files:
195
195
  - lib/clever/types/base.rb
196
196
  - lib/clever/types/classroom.rb
197
197
  - lib/clever/types/course.rb
198
+ - lib/clever/types/district_admin.rb
198
199
  - lib/clever/types/enrollment.rb
199
200
  - lib/clever/types/event.rb
201
+ - lib/clever/types/school_admin.rb
200
202
  - lib/clever/types/section.rb
201
203
  - lib/clever/types/student.rb
202
204
  - lib/clever/types/teacher.rb