clever 2.1.0 → 3.0.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: '090aa2a5761f72e7e462c3357ddaf259dd0f6c81'
4
- data.tar.gz: b16b89f8e7b208e2dcddd4be8638cd0ea557951e
3
+ metadata.gz: ae0e8318fdecf7c7c7165bef8c0ac88051f66d18
4
+ data.tar.gz: d3d7ae47d72ca7535fa478f4ff5f29dc97b0b192
5
5
  SHA512:
6
- metadata.gz: b75c8494f7899b7f6b7027d24c77586e2cbd704240d86decba941fb3acbebf36c1420f4f377698a65d0f0746e84733be0211b29c28849140ed30acf577b70067
7
- data.tar.gz: a0179bba8d24cbeab7b13d10750a826aadd144c98281c33e2ca3091bc11888177f11091855e0e534de8bcb220966bf25bb0b0e1199019eca89f8fc3bb0dad8e2
6
+ metadata.gz: 3041336d755fecb6fc2860439c6bc2b9f94e5bbef769647a0fd767587ac3a9eabda9db14311178920aca7edcd5ef2b5e3ac0c52e93630fc8d0a621a6a8394301
7
+ data.tar.gz: d043aa91dabd5b5e0044cfdd396bbae6f846776e2e126db85ef70b4afb04e6256aad7e4630ff0541c55fd60167d30f8cd82548175dd1e7162753ede4c31db067
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clever (2.1.0)
4
+ clever (3.0.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
data/lib/clever.rb CHANGED
@@ -21,14 +21,14 @@ require 'clever/types/term'
21
21
  require 'clever/types/token'
22
22
 
23
23
  module Clever
24
- API_URL = 'https://api.clever.com/v2.0'
24
+ API_URL = 'https://api.clever.com/v3.0'
25
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'
26
+ STUDENTS_ENDPOINT = '/v3.0/users?role=student'
27
+ COURSES_ENDPOINT = '/v3.0/courses'
28
+ SECTIONS_ENDPOINT = '/v3.0/sections'
29
+ TEACHERS_ENDPOINT = '/v3.0/users'
30
30
  EVENTS_ENDPOINT = '/v1.2/events'
31
- TERMS_ENDPOINT = '/v2.0/terms'
31
+ TERMS_ENDPOINT = '/v3.0/terms'
32
32
  GRADES_ENDPOINT = 'https://grades-api.beta.clever.com/v1/grade'
33
33
 
34
34
  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
 
@@ -136,7 +136,8 @@ module Clever
136
136
  section.teachers.each do |teacher_uid|
137
137
  enrollments[:teacher] << Types::Enrollment.new(
138
138
  'classroom_uid' => section.uid,
139
- 'user_uid' => teacher_uid
139
+ 'user_uid' => teacher_uid,
140
+ 'primary' => section.primary_teacher_uid == teacher_uid
140
141
  )
141
142
  end
142
143
  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 = attributes['grade']
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,52 @@ 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
+
13
+ def initialize(attributes = {}, *, client: nil)
14
+ @district_username = attributes.dig('credentials', 'district_username')
15
+ @email = attributes['email']
16
+ @first_name = attributes['name']['first']
17
+ @last_name = attributes['name']['last']
18
+ @legacy_id = attributes.dig('roles', 'teacher', 'legacy_id')
19
+ @provider = 'clever'
20
+ @sis_id = attributes['sis_id']
21
+ @uid = attributes['id']
22
+ @username = username(client)
23
+ end
24
+
25
+ def username(client = nil)
26
+ username_source = client&.staff_username_source
27
+
28
+ @username ||= presence(username_from(username_source))
29
+ end
30
+
31
+ def to_h
32
+ {
33
+ uid: @uid,
34
+ email: @email,
35
+ first_name: @first_name,
36
+ last_name: @last_name,
37
+ username: @username,
38
+ provider: @provider
39
+ }
40
+ end
41
+
42
+ private
43
+
44
+ def username_from(username_source)
45
+ return if blank?(username_source)
46
+
47
+ presence(instance_variable_get("@#{username_source}"))
48
+ end
49
+
50
+ def presence(field)
51
+ field unless blank?(field)
52
+ end
53
+
54
+ def blank?(field)
55
+ field.nil? || field == ''
18
56
  end
19
57
  end
20
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clever
4
- VERSION = '2.1.0'
4
+ VERSION = '3.0.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.1.0
4
+ version: 3.0.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-24 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday