1 class WayController < ApplicationController
4 skip_before_filter :verify_authenticity_token
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :require_allow_write_api, :only => [:create, :update, :delete]
7 before_filter :require_public_data, :only => [:create, :update, :delete]
8 before_filter :check_api_writable, :only => [:create, :update, :delete]
9 before_filter :check_api_readable, :except => [:create, :update, :delete]
10 after_filter :compress_output
11 around_filter :api_call_handle_error, :api_call_timeout
16 way = Way.from_xml(request.raw_post, true)
19 way.create_with_history @user
20 render :text => way.id.to_s, :content_type => "text/plain"
22 render :text => "", :status => :bad_request
27 way = Way.find(params[:id])
29 response.last_modified = way.timestamp
32 render :text => way.to_xml.to_s, :content_type => "text/xml"
34 render :text => "", :status => :gone
39 way = Way.find(params[:id])
40 new_way = Way.from_xml(request.raw_post)
42 if new_way && new_way.id == way.id
43 way.update_from(new_way, @user)
44 render :text => way.version.to_s, :content_type => "text/plain"
46 render :text => "", :status => :bad_request
50 # This is the API call to delete a way
52 way = Way.find(params[:id])
53 new_way = Way.from_xml(request.raw_post)
55 if new_way && new_way.id == way.id
56 way.delete_with_history!(new_way, @user)
57 render :text => way.version.to_s, :content_type => "text/plain"
59 render :text => "", :status => :bad_request
64 way = Way.includes(:nodes => :node_tags).find(params[:id])
69 user_display_name_cache = {}
71 doc = OSM::API.new.get_xml_doc
72 way.nodes.uniq.each do |node|
74 doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
75 visible_nodes[node.id] = node
78 doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
80 render :text => doc.to_s, :content_type => "text/xml"
82 render :text => "", :status => :gone
88 fail OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
91 ids = params["ways"].split(",").collect(&:to_i)
94 fail OSM::APIBadUserInput.new("No ways were given to search for")
97 doc = OSM::API.new.get_xml_doc
99 Way.find(ids).each do |way|
100 doc.root << way.to_xml_node
103 render :text => doc.to_s, :content_type => "text/xml"
107 # returns all the ways which are currently using the node given in the
108 # :id parameter. note that this used to return deleted ways as well, but
109 # this seemed not to be the expected behaviour, so it was removed.
111 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
113 doc = OSM::API.new.get_xml_doc
115 Way.find(wayids).each do |way|
116 doc.root << way.to_xml_node if way.visible
119 render :text => doc.to_s, :content_type => "text/xml"