2 class ChangesController < ApiController
3 before_action :api_deny_access_handler
5 authorize_resource :class => false
7 before_action :check_api_readable
8 around_action :api_call_handle_error, :api_call_timeout
10 # Get a list of the tiles that have changed within a specified time
13 zoom = (params[:zoom] || "12").to_i
15 if params.include?(:start) && params.include?(:end)
16 starttime = Time.parse(params[:start])
17 endtime = Time.parse(params[:end])
19 hours = (params[:hours] || "1").to_i.hours
20 endtime = Time.now.getutc
21 starttime = endtime - hours
24 if zoom >= 1 && zoom <= 16 &&
25 endtime > starttime && endtime - starttime <= 24.hours
26 mask = (1 << zoom) - 1
28 tiles = Node.where(:timestamp => starttime..endtime).group("maptile_for_point(latitude, longitude, #{zoom})").count
30 doc = OSM::API.new.get_xml_doc
31 changes = XML::Node.new "changes"
32 changes["starttime"] = starttime.xmlschema
33 changes["endtime"] = endtime.xmlschema
35 tiles.each do |tile, count|
36 x = (tile.to_i >> zoom) & mask
39 t = XML::Node.new "tile"
43 t["changes"] = count.to_s
50 render :xml => doc.to_s
52 render :plain => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request