clever 3.1.0 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/clever.rb +15 -11
- data/lib/clever/client.rb +29 -10
- data/lib/clever/types/{admin.rb → district_admin.rb} +1 -1
- data/lib/clever/types/school_admin.rb +20 -0
- data/lib/clever/types/teacher.rb +2 -1
- data/lib/clever/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63979f4986db64df6612124fd9ab0974cb198bab
|
4
|
+
data.tar.gz: 9304f5516f09faeaaaa7c107f6c531f42164ee4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 866dd8a3c35e4a950cce8f2d5de0e854ae1890b60ae8a05d4f2b6189c37aaa0eaf8b5d5b5e217f9ae2c47b9358cd429ae1460c6b1ceef34ecd421d97c646fb77
|
7
|
+
data.tar.gz: 66156debf6f11613064e09645aca230d61611f98f140abf15b6b0aa324b7756b94a6d0f329a96e4d4c25b671018eac25e0910ac28bbef1ac4010a013d0216e4b
|
data/Gemfile.lock
CHANGED
data/lib/clever.rb
CHANGED
@@ -17,21 +17,25 @@ 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/
|
20
|
+
require 'clever/types/district_admin'
|
21
|
+
require 'clever/types/school_admin'
|
21
22
|
require 'clever/types/term'
|
22
23
|
require 'clever/types/token'
|
23
24
|
|
24
25
|
module Clever
|
25
|
-
API_URL
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
API_URL = 'https://api.clever.com/v3.0'
|
27
|
+
ME_ENDPOINT = '/v3.0/me'
|
28
|
+
USER_TOKEN_ENDPOINT = 'https://clever.com/oauth/tokens'
|
29
|
+
TOKENS_ENDPOINT = 'https://clever.com/oauth/tokens?owner_type=district'
|
30
|
+
STUDENTS_ENDPOINT = '/v3.0/users?role=student'
|
31
|
+
COURSES_ENDPOINT = '/v3.0/courses'
|
32
|
+
SECTIONS_ENDPOINT = '/v3.0/sections'
|
33
|
+
TEACHERS_ENDPOINT = '/v3.0/users?role=teacher'
|
34
|
+
DISTRICT_ADMINS_ENDPOINT = '/v3.0/users?role=district_admin'
|
35
|
+
SCHOOL_ADMINS_ENDPOINT = '/v3.0/users?role=staff'
|
36
|
+
EVENTS_ENDPOINT = '/v1.2/events'
|
37
|
+
TERMS_ENDPOINT = '/v3.0/terms'
|
38
|
+
GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
|
35
39
|
|
36
40
|
class DistrictNotFound < StandardError; end
|
37
41
|
class ConnectionError < StandardError; end
|
data/lib/clever/client.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
module Clever
|
4
4
|
class Client
|
5
|
-
attr_accessor :app_id, :app_token, :sync_id, :logger,
|
5
|
+
attr_accessor :app_id, :app_token, :sync_id, :logger, :redirect_uri,
|
6
6
|
:vendor_key, :vendor_secret, :username_source, :staff_username_source
|
7
7
|
|
8
8
|
attr_reader :api_url, :tokens_endpoint
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@api_url
|
12
|
-
@tokens_endpoint
|
11
|
+
@api_url = API_URL
|
12
|
+
@tokens_endpoint = TOKENS_ENDPOINT
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.configure
|
@@ -38,6 +38,22 @@ module Clever
|
|
38
38
|
response
|
39
39
|
end
|
40
40
|
|
41
|
+
def user_uid_for_code(code)
|
42
|
+
response = connection.execute(USER_TOKEN_ENDPOINT,
|
43
|
+
:post,
|
44
|
+
nil,
|
45
|
+
{ code: code,
|
46
|
+
grant_type: 'authorization_code',
|
47
|
+
redirect_uri: redirect_uri })
|
48
|
+
|
49
|
+
fail ConnectionError, response.raw_body unless response.success?
|
50
|
+
|
51
|
+
connection.set_token(response.raw_body['access_token'])
|
52
|
+
|
53
|
+
response = connection.execute(ME_ENDPOINT, :get)
|
54
|
+
response&.body&.dig('id')
|
55
|
+
end
|
56
|
+
|
41
57
|
def most_recent_event
|
42
58
|
authenticate
|
43
59
|
|
@@ -54,7 +70,7 @@ module Clever
|
|
54
70
|
Paginator.fetch(connection, endpoint, :get, Types::Event, client: self).force
|
55
71
|
end
|
56
72
|
|
57
|
-
%i(students courses sections terms).each do |record_type|
|
73
|
+
%i(students courses teachers sections terms).each do |record_type|
|
58
74
|
define_method(record_type) do |record_uids = []|
|
59
75
|
authenticate
|
60
76
|
|
@@ -69,17 +85,20 @@ module Clever
|
|
69
85
|
end
|
70
86
|
end
|
71
87
|
|
72
|
-
def
|
88
|
+
def admins(record_uids = [])
|
73
89
|
authenticate
|
74
90
|
|
75
|
-
|
76
|
-
|
91
|
+
district_admins = Paginator.fetch(connection, Clever::DISTRICT_ADMINS_ENDPOINT,
|
92
|
+
:get, Types::DistrictAdmin, client: self).force
|
93
|
+
|
94
|
+
school_admins = Paginator.fetch(connection, Clever::SCHOOL_ADMINS_ENDPOINT,
|
95
|
+
:get, Types::SchoolAdmin, client: self).force
|
77
96
|
|
78
|
-
|
97
|
+
admins = (district_admins + school_admins).uniq(&:uid)
|
79
98
|
|
80
|
-
return
|
99
|
+
return admins if record_uids.empty?
|
81
100
|
|
82
|
-
|
101
|
+
admins.select { |record| record_uids.to_set.include?(record.uid) }
|
83
102
|
end
|
84
103
|
|
85
104
|
# discard params to make the API behave the same as the one roster gem
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Clever
|
4
4
|
module Types
|
5
|
-
class
|
5
|
+
class DistrictAdmin < Teacher
|
6
6
|
def initialize(attributes = {}, *, client: nil)
|
7
7
|
@district_username = attributes.dig('roles', 'district_admin', 'credentials', 'district_username')
|
8
8
|
@email = attributes['email']
|
@@ -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
|
data/lib/clever/types/teacher.rb
CHANGED
data/lib/clever/version.rb
CHANGED
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: 3.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Julius
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -192,12 +192,13 @@ 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
|
196
195
|
- lib/clever/types/base.rb
|
197
196
|
- lib/clever/types/classroom.rb
|
198
197
|
- lib/clever/types/course.rb
|
198
|
+
- lib/clever/types/district_admin.rb
|
199
199
|
- lib/clever/types/enrollment.rb
|
200
200
|
- lib/clever/types/event.rb
|
201
|
+
- lib/clever/types/school_admin.rb
|
201
202
|
- lib/clever/types/section.rb
|
202
203
|
- lib/clever/types/student.rb
|
203
204
|
- lib/clever/types/teacher.rb
|