clever 3.1.1 → 3.2.3

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: ba04605f8dd24c5294e0ad902c29df9296ce14e1
4
- data.tar.gz: 275fecc1abefb5af4a08d146b38eca3acc24602a
3
+ metadata.gz: 6694d0cb1936ab84956d227272a9539ecc6a5791
4
+ data.tar.gz: a23ad0110f1459719445ac685af838c42b438ebc
5
5
  SHA512:
6
- metadata.gz: a336127ba0c65de367f9ed9a027ab71baa411baf0ee2302e105a475665035d1a6ec9da5cbe1680adc6280acfacf2ae7ac9c8ec28b52837610a39cadacfbd5810
7
- data.tar.gz: 1eea6ee645d14b4410dcab268a4508a23200faf724f77467c61822ba8a904e994f11871a39fefe3cc25bd1c633f0c45635aeb9c5676ec55fb6cb13c4fbec7134
6
+ metadata.gz: ab3e3447b9c05aaf6758e14ae0ce6e533a559fdac407c29cc548fc5acfca6ad05c719810a857b265514e5a4052a4a96abc7d0ac2b6f51b9159c615a1c50a816a
7
+ data.tar.gz: 74e9b01f178087d04f568bc79b667441439ae809e19697c7f78ba9518cc606f66b003f7f4574785cb458f24deac94b0765f81193229e6087143b3d2c559c2b7f
data/.circleci/config.yml CHANGED
@@ -22,7 +22,7 @@ install_dependencies: &install_dependencies
22
22
  command: |
23
23
  echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
24
24
  source $BASH_ENV
25
- gem install bundler
25
+ gem install bundler -v '2.1.4'
26
26
  bundle install --jobs=4 --retry=3 --path vendor/bundle
27
27
 
28
28
  save_ruby_cache: &save_ruby_cache
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clever (3.1.1)
4
+ clever (3.2.3)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
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/admin'
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 = 'https://api.clever.com/v3.0'
26
- TOKENS_ENDPOINT = 'https://clever.com/oauth/tokens?owner_type=district'
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'
32
- EVENTS_ENDPOINT = '/v1.2/events'
33
- TERMS_ENDPOINT = '/v3.0/terms'
34
- GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
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 = 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
@@ -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 teachers admins 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,6 +85,22 @@ module Clever
69
85
  end
70
86
  end
71
87
 
88
+ def admins(record_uids = [])
89
+ authenticate
90
+
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
96
+
97
+ admins = (district_admins + school_admins).uniq(&:uid)
98
+
99
+ return admins if record_uids.empty?
100
+
101
+ admins.select { |record| record_uids.to_set.include?(record.uid) }
102
+ end
103
+
72
104
  # discard params to make the API behave the same as the one roster gem
73
105
  def classrooms(*)
74
106
  authenticate
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Clever
4
4
  module Types
5
- class Admin < Teacher
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']
@@ -10,7 +10,7 @@ module Clever
10
10
  @last_name = attributes['name']['last']
11
11
  @legacy_id = attributes.dig('roles', 'district_admin', 'legacy_id')
12
12
  @provider = 'clever'
13
- @sis_id = attributes.dig('roles', 'district_admin', 'credentials', 'sis_id')
13
+ @sis_id = attributes.dig('roles', 'district_admin', 'sis_id')
14
14
  @uid = attributes['id']
15
15
  @username = username(client)
16
16
  @role = 'admin'
@@ -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', 'sis_id')
14
+ @uid = attributes['id']
15
+ @username = username(client)
16
+ @role = 'admin'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -16,7 +16,7 @@ module Clever
16
16
  @last_name = attributes['name']['last']
17
17
  @legacy_id = attributes.dig('roles', 'student', 'legacy_id')
18
18
  @provider = 'clever'
19
- @sis_id = attributes['sis_id']
19
+ @sis_id = attributes.dig('roles', 'student', 'sis_id')
20
20
  @uid = attributes['id']
21
21
  @username = username(client)
22
22
  end
@@ -18,7 +18,7 @@ module Clever
18
18
  @last_name = attributes['name']['last']
19
19
  @legacy_id = attributes.dig('roles', 'teacher', 'legacy_id')
20
20
  @provider = 'clever'
21
- @sis_id = attributes.dig('roles', 'teacher', 'credentials', 'sis_id')
21
+ @sis_id = attributes.dig('roles', 'teacher', 'sis_id')
22
22
  @uid = attributes['id']
23
23
  @username = username(client)
24
24
  @role = 'teacher'
@@ -37,7 +37,8 @@ module Clever
37
37
  first_name: @first_name,
38
38
  last_name: @last_name,
39
39
  username: @username,
40
- provider: @provider
40
+ provider: @provider,
41
+ legacy_id: @legacy_id
41
42
  }
42
43
  end
43
44
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clever
4
- VERSION = '3.1.1'
4
+ VERSION = '3.2.3'
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: 3.1.1
4
+ version: 3.2.3
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-06-02 00:00:00.000000000 Z
11
+ date: 2021-08-11 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