Class: Clever::Types::Student

Inherits:
Base
  • Object
show all
Defined in:
lib/clever/types/student.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#blank?, #presence

Constructor Details

#initialize(attributes = {}, client: nil) ⇒ Student

Returns a new instance of Student.



11
12
13
14
15
16
17
18
19
20
# File 'lib/clever/types/student.rb', line 11

def initialize(attributes = {}, client: nil)
  @district_username = attributes.dig('roles', 'student', 'credentials', 'district_username')
  @email             = attributes['email']
  @first_name        = attributes['name']['first']
  @last_name         = attributes['name']['last']
  @provider          = 'clever'
  @sis_id            = attributes.dig('roles', 'student', 'sis_id')
  @uid               = attributes['id']
  @username          = username(client)
end

Instance Attribute Details

#first_nameObject (readonly)

Returns the value of attribute first_name.



6
7
8
# File 'lib/clever/types/student.rb', line 6

def first_name
  @first_name
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



6
7
8
# File 'lib/clever/types/student.rb', line 6

def last_name
  @last_name
end

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/clever/types/student.rb', line 6

def provider
  @provider
end

#uidObject (readonly)

Returns the value of attribute uid.



6
7
8
# File 'lib/clever/types/student.rb', line 6

def uid
  @uid
end

Instance Method Details

#to_hObject



28
29
30
31
32
33
34
35
36
# File 'lib/clever/types/student.rb', line 28

def to_h
  {
    uid: @uid,
    first_name: @first_name,
    last_name: @last_name,
    username: @username,
    provider: @provider
  }
end

#username(client = nil) ⇒ Object



22
23
24
25
26
# File 'lib/clever/types/student.rb', line 22

def username(client = nil)
  username_source = client&.username_source

  @username ||= presence(username_from(username_source)) || default_username
end