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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77dbd6fdbbf2b13bdf7d7011c19f03d90db8ab4e
4
- data.tar.gz: c98d3ea989e3c3cdfd0bd8114a412965c232c586
3
+ metadata.gz: 63979f4986db64df6612124fd9ab0974cb198bab
4
+ data.tar.gz: 9304f5516f09faeaaaa7c107f6c531f42164ee4b
5
5
  SHA512:
6
- metadata.gz: 36c9a1621dedd554ff8959ec6f4477baa48a5832dde56fd4d64201fdb5bca3d8b02d502f443beff52978908164e9286b4897cc5aa546cf5b4f153764a381cf5e
7
- data.tar.gz: 8de9b79585e796b400544747294ddbd4fd23e1688df9875497270004b80c988d6745147556ca23eb70c0b729c5c85f5a7d143b131ed173779220cd8c9c03810d
6
+ metadata.gz: 866dd8a3c35e4a950cce8f2d5de0e854ae1890b60ae8a05d4f2b6189c37aaa0eaf8b5d5b5e217f9ae2c47b9358cd429ae1460c6b1ceef34ecd421d97c646fb77
7
+ data.tar.gz: 66156debf6f11613064e09645aca230d61611f98f140abf15b6b0aa324b7756b94a6d0f329a96e4d4c25b671018eac25e0910ac28bbef1ac4010a013d0216e4b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clever (3.1.0)
4
+ clever (3.2.2)
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 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 teachers(record_uids = [])
88
+ def admins(record_uids = [])
73
89
  authenticate
74
90
 
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
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
- records = (admins + teachers).uniq(&:uid)
97
+ admins = (district_admins + school_admins).uniq(&:uid)
79
98
 
80
- return records if record_uids.empty?
99
+ return admins if record_uids.empty?
81
100
 
82
- records.select { |record| record_uids.to_set.include?(record.uid) }
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 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']
@@ -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
@@ -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.0'
4
+ VERSION = '3.2.2'
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.0
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-06-01 00:00:00.000000000 Z
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