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
104 105 106 107 108 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 |
# File 'lib/osm/event.rb', line 104 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}") event = self.new_event_from_data(event_data) 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 |