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
17 way = Way.from_xml(request.raw_post, true)
19 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
20 way.create_with_history current_user
21 render :plain => way.id.to_s
25 @way = Way.find(params[:id])
27 response.last_modified = @way.timestamp
31 respond_to do |format|
40 way = Way.find(params[:id])
41 new_way = Way.from_xml(request.raw_post)
43 unless new_way && new_way.id == way.id
44 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
47 way.update_from(new_way, current_user)
48 render :plain => way.version.to_s
51 # This is the API call to delete a way
53 way = Way.find(params[:id])
54 new_way = Way.from_xml(request.raw_post)
56 if new_way && new_way.id == way.id
57 way.delete_with_history!(new_way, current_user)
58 render :plain => way.version.to_s
65 @way = Way.includes(:nodes => :node_tags).find(params[:id])
72 @way.nodes.uniq.each do |node|
75 visible_nodes[node.id] = node
80 respond_to do |format|
90 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
93 ids = params["ways"].split(",").collect(&:to_i)
95 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
100 respond_to do |format|
106 # returns all the ways which are currently using the node given in the
107 # :id parameter. note that this used to return deleted ways as well, but
108 # this seemed not to be the expected behaviour, so it was removed.
110 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
112 @ways = Way.where(:id => wayids, :visible => true)
115 respond_to do |format|