Method: Osm::Event.get_list
- Defined in:
- lib/osm/event.rb
.get_list(api, section, options = {}) ⇒ Array<Hash>
Get event list for a section (not all details for each event)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/osm/event.rb', line 142 def self.get_list(api, section, ={}) require_ability_to(api, :read, :events, section, ) section_id = section.to_i cache_key = ['events_list', section_id] events_cache_key = ['events', section_id] events = nil unless [:no_cache] # Try getting from cache if cache_exist?(api, cache_key) return cache_read(api, cache_key) end # Try generating from cached events if cache_exist?(api, events_cache_key) ids = cache_read(api, events_cache_key) events = get_from_ids(api, ids, 'event', section, , :get_for_section).map do |e| e.attributes.symbolize_keys.select do |k,v| LIST_ATTRIBUTES.include?(k) end end end end # Fetch from OSM if events.nil? data = api.perform_query("events.php?action=getEvents§ionid=#{section_id}&showArchived=true") events = Array.new unless data['items'].nil? data['items'].map do |event_data| events.push(attributes_from_data(event_data)) end end end cache_write(api, cache_key, events) return events end |