2 class WaysController < ApiController
5 before_action :authorize, :only => [:create, :update, :delete]
9 before_action :require_public_data, :only => [:create, :update, :delete]
10 before_action :check_api_writable, :only => [:create, :update, :delete]
11 before_action :check_api_readable, :except => [:create, :update, :delete]
12 around_action :api_call_handle_error, :api_call_timeout
14 before_action :default_format_xml
16 # Set format to xml unless client requires a specific format
17 def default_format_xml
18 request.format = "xml" unless params[:format]
24 way = Way.from_xml(request.raw_post, true)
26 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
27 way.create_with_history current_user
28 render :plain => way.id.to_s
32 @way = Way.find(params[:id])
34 response.last_modified = @way.timestamp
38 respond_to do |format|
48 way = Way.find(params[:id])
49 new_way = Way.from_xml(request.raw_post)
51 unless new_way && new_way.id == way.id
52 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
55 way.update_from(new_way, current_user)
56 render :plain => way.version.to_s
59 # This is the API call to delete a way
61 way = Way.find(params[:id])
62 new_way = Way.from_xml(request.raw_post)
64 if new_way && new_way.id == way.id
65 way.delete_with_history!(new_way, current_user)
66 render :plain => way.version.to_s
73 @way = Way.includes(:nodes => :node_tags).find(params[:id])
80 @way.nodes.uniq.each do |node|
83 visible_nodes[node.id] = node
88 respond_to do |format|
99 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
102 ids = params["ways"].split(",").collect(&:to_i)
104 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
106 @ways = Way.find(ids)
109 respond_to do |format|
116 # returns all the ways which are currently using the node given in the
117 # :id parameter. note that this used to return deleted ways as well, but
118 # this seemed not to be the expected behaviour, so it was removed.
120 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
122 @ways = Way.where(:id => wayids, :visible => true)
125 respond_to do |format|