Method: Osm::Event.get_for_section
- Defined in:
- lib/osm/event.rb
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Event>
Get events for a section
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/osm/event.rb', line 109 def self.get_for_section(api, section, ={}) require_ability_to(api, :read, :events, section, ) section_id = section.to_i cache_key = ['events', section_id] events = nil if ![:no_cache] && cache_exist?(api, cache_key) ids = cache_read(api, cache_key) events = get_from_ids(api, ids, 'event', section, , :get_for_section) end if events.nil? data = api.perform_query("events.php?action=getEvents§ionid=#{section_id}&showArchived=true") events = Array.new ids = Array.new unless data['items'].nil? data['items'].map { |i| i['eventid'].to_i }.each do |event_id| event_data = api.perform_query("events.php?action=getEvent§ionid=#{section_id}&eventid=#{event_id}") files_data = api.perform_query("ext/uploads/events/?action=listAttachments§ionid=#{section_id}&eventid=#{event_id}") files = files_data.is_a?(Hash) ? files_data['files'] : files_data files = [] unless files.is_a?(Array) event = self.new_event_from_data(event_data) event.files = files events.push event ids.push event.id cache_write(api, ['event', event.id], event) end end cache_write(api, cache_key, ids) end return events if [:include_archived] return events.reject do |event| event.archived? end end |