lib/osm/grouping.rb in osm-0.1.15 vs lib/osm/grouping.rb in osm-0.1.16
- old
+ new
@@ -42,19 +42,21 @@
end
data = api.perform_query("users.php?action=getPatrols§ionid=#{section_id}")
result = Array.new
- data['patrols'].each do |item|
- result.push Osm::Grouping.new({
- :id => Osm::to_i_or_nil(item['patrolid']),
- :section_id => section_id,
- :name => item['name'],
- :active => (item['active'] == 1),
- :points => Osm::to_i_or_nil(item['points']),
- })
+ if data.is_a?(Hash) && data['patrols'].is_a?(Array)
+ data['patrols'].each do |item|
+ result.push Osm::Grouping.new({
+ :id => Osm::to_i_or_nil(item['patrolid']),
+ :section_id => section_id,
+ :name => item['name'],
+ :active => (item['active'] == 1),
+ :points => Osm::to_i_or_nil(item['points']),
+ })
+ end
+ cache_write(api, cache_key, result)
end
- cache_write(api, cache_key, result)
return result
end