-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for teachers resource and mapping for TeacherTimetableSlot
- Loading branch information
Showing
6 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module KOSapiClient | ||
module Entity | ||
class TeacherTimetableSlot | ||
|
||
include DataMappings | ||
|
||
map_data :id, Integer | ||
map_data :day, Integer | ||
map_data :duration, Integer | ||
map_data :first_hour, Integer | ||
map_data :parity, Enum | ||
map_data :title, String | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module KOSapiClient | ||
module Resource | ||
class TeachersBuilder < RequestBuilder | ||
|
||
# XXX: This is quite insane, we need some support to DRY subresources. | ||
%w[courses parallels exams timetable].each do |resource| | ||
define_method(resource) do |semester: 'current'| | ||
raise "Call #find({username}) before asking for #{resource}" unless id_set? | ||
url_builder.set_path(id, resource) | ||
url_builder.set_query_param(:sem, semester) | ||
self | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe KOSapiClient::Entity::TeacherTimetableSlot do | ||
|
||
describe '.parse' do | ||
|
||
it 'can be parsed from a hash' do | ||
slot = described_class.parse({ | ||
id: '42', day: '1', first_hour: '3', duration: '2', parity: 'BOTH', title: 'Sleep' | ||
}) | ||
expect(slot.id).to eq 42 | ||
expect(slot.day).to eq 1 | ||
expect(slot.first_hour).to eq 3 | ||
expect(slot.duration).to eq 2 | ||
expect(slot.parity).to eq :both | ||
expect(slot.title).to eq 'Sleep' | ||
end | ||
end | ||
end |