Skip to content

Commit

Permalink
Add attribute 'examiners' to exam entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed May 17, 2015
1 parent 619dde7 commit 2fc49c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/kosapi_client/entity/data_mappings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def set_mapped_attribute(instance, name, source_hash, mapping_options)
else
key = src_element
end
value = source_hash[key]
value = retrieve_value(source_hash, key, mapping_options)
if value.nil?
raise "Missing value for attribute #{name}" if mapping_options[:required]
if mapping_options[:type].is_a?(Array)
Expand Down Expand Up @@ -106,6 +106,16 @@ def convert_array(values, type)
end
end

def retrieve_value(source_hash, key, mapping_options)
path = mapping_options[:path]
if path
parent_element = source_hash[path]
else
parent_element = source_hash
end
parent_element[key] if parent_element
end

end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/kosapi_client/entity/exam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Exam < BaseEntity
map_data :department, Link
map_data :end_date, Time
map_data :examiner, Link
map_data :examiners, [Link], element: :teacher, path: :examiners
map_data :note
map_data :occupied, Integer
map_data :resit, Boolean
Expand Down
2 changes: 1 addition & 1 deletion lib/kosapi_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module KOSapiClient
VERSION = '0.3.1'
VERSION = '0.3.2'
end
7 changes: 6 additions & 1 deletion spec/integration/exams_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
expect(client.exams.find(193156727405).attendees.count).to be > 0
end

end
it 'allows multiple examiners' do
exam = client.exams.find(613664749005)
expect(exam.examiners.count).to be 2
expect(exam.examiners.first.link_id).to eq 'zhoufjar'
end
end

0 comments on commit 2fc49c8

Please sign in to comment.