2 class WaysController < ApiController
3 before_action :check_api_writable, :only => [:create, :update, :delete]
4 before_action :check_api_readable, :except => [:create, :update, :delete]
5 before_action :authorize, :only => [:create, :update, :delete]
9 before_action :require_public_data, :only => [:create, :update, :delete]
10 around_action :api_call_handle_error, :api_call_timeout
12 before_action :set_request_formats, :except => [:create, :update, :delete]
13 before_action :check_rate_limit, :only => [:create, :update, :delete]
16 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]" unless params["ways"]
18 ids = params["ways"].split(",").collect(&:to_i)
20 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
25 respond_to do |format|
32 @way = Way.find(params[:id])
34 response.last_modified = @way.timestamp
38 respond_to do |format|
48 way = Way.from_xml(request.raw_post, :create => true)
50 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
51 way.create_with_history current_user
52 render :plain => way.id.to_s
56 way = Way.find(params[:id])
57 new_way = Way.from_xml(request.raw_post)
59 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})" unless new_way && new_way.id == way.id
61 way.update_from(new_way, current_user)
62 render :plain => way.version.to_s
65 # This is the API call to delete a way
67 way = Way.find(params[:id])
68 new_way = Way.from_xml(request.raw_post)
70 if new_way && new_way.id == way.id
71 way.delete_with_history!(new_way, current_user)
72 render :plain => way.version.to_s
79 @way = Way.includes(:nodes => :node_tags).find(params[:id])
86 @way.nodes.uniq.each do |node|
89 visible_nodes[node.id] = node
94 respond_to do |format|
104 # returns all the ways which are currently using the node given in the
105 # :id parameter. note that this used to return deleted ways as well, but
106 # this seemed not to be the expected behaviour, so it was removed.
108 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
110 @ways = Way.where(:id => wayids, :visible => true)
113 respond_to do |format|