Skip to content

Commit

Permalink
Fixed parsing of empty response.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Jul 17, 2014
1 parent e526e9d commit 2d78a35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/kosapi_client/response_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ResponseConverter
# @return [ResultPage] ResultPage of domain objects

def convert_paginated(items)
items ||= []
converted_items = items.map{ |p| convert_type(p, detect_type(p)) }
Entity::ResultPage.new(converted_items, 0, nil)
end
Expand Down
8 changes: 5 additions & 3 deletions lib/kosapi_client/response_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def merge_contents(hash)
else
[hash[:atom_entry]]
end
entries.each do |entry|
content = entry.delete(:atom_content)
entry.merge! content if content
if entries
entries.each do |entry|
content = entry.delete(:atom_content)
entry.merge! content if content
end
end

end
Expand Down
5 changes: 5 additions & 0 deletions spec/integration/courses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
expect(page.items.first.title).not_to be_nil
end

it 'parses empty response' do
page = client.courses.offset(1000000)
expect(page.items).to eq []
end


end
6 changes: 6 additions & 0 deletions spec/kosapi_client/response_preprocessor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@
expect(result).to eq({atom_entry: {id: '1234', foo: :bar}})
end

it 'handles empty response' do
resp = {atom_feed: {} }
result = preprocessor.preprocess(resp)
expect(result).to eq({atom_feed: {}})
end

end

0 comments on commit 2d78a35

Please sign in to comment.