class Manabu::Student
Attributes
birth_date[RW]
enrollment_status[RW]
gender[RW]
id[RW]
middle_name[RW]
middle_name_reading[RW]
name[RW]
name_reading[RW]
surname[RW]
surname_reading[RW]
Public Class Methods
new(client, **info)
click to toggle source
Calls superclass method
Manabu::Resource::new
# File lib/manabu/student.rb, line 15 def initialize(client, **info) super @contacts = [] @picture = nil end
Public Instance Methods
add_contact(contact_type_id, data)
click to toggle source
# File lib/manabu/student.rb, line 62 def add_contact(contact_type_id, data) response = @client.post("students/#{id}/contacts", contact_type_id: contact_type_id, data: data ) @contacts.push Contact.new(@client, response) self # rescue StandardError # raise ContactNotAdded, 'Contact is not added to student' end
add_guardian(guardian)
click to toggle source
# File lib/manabu/student.rb, line 54 def add_guardian(guardian) # NOTE: detect when guardian is already added to student response = @client.post("students/#{id}/student_guardians", guardian_id: guardian.id) self rescue StandardError raise GuardianNotAdded, 'Guardian is not added to student' end
add_picture(path)
click to toggle source
# File lib/manabu/student.rb, line 46 def add_picture(path) file = Faraday::UploadIO.new(path, FileMagic.new(FileMagic::MAGIC_MIME).file(path)) response = @client.patch("students/#{@id}", picture: file) @picture = nil fill(response) end
courses()
click to toggle source
# File lib/manabu/student.rb, line 80 def courses response = @client.get("students/#{id}/courses") response[:courses].map do |course| Manabu::Course.new(@client, course) end end
fill(**info)
click to toggle source
# File lib/manabu/student.rb, line 21 def fill(**info) @id = info.fetch(:id, @id) @surname = info.fetch(:surname, @surname) @name = info.fetch(:name, @name) @name_reading = info.fetch(:name_reading, @name_reading) @surname_reading = info.fetch(:surname_reading, @surname_reading) @birth_date = info.fetch(:birth_date, @birth_date) @gender = info.fetch(:gender, @gender) @enrollment_status = Manabu::EnrollmentStatus.new(@client, info[:enrollment_status] || {}) self end
guardians()
click to toggle source
# File lib/manabu/student.rb, line 73 def guardians response = @client.get("students/#{id}/guardians") response[:guardians].map do |guardian| Manabu::Guardian.new(@client, guardian) end end
picture()
click to toggle source
# File lib/manabu/student.rb, line 33 def picture return unless @id return @picture if @picture response = @client.simple_get("students/#{id}/picture") @picture = response.body end
set(**info)
click to toggle source
# File lib/manabu/student.rb, line 41 def set(**info) response = @client.patch("students/#{@id}", info) fill(response) end