2 class WaysController < ApiController
3 before_action :check_api_writable, :only => [:create, :update, :delete]
4 before_action :authorize, :only => [:create, :update, :delete]
8 before_action :require_public_data, :only => [:create, :update, :delete]
9 before_action :set_request_formats, :except => [:create, :update, :delete]
10 before_action :check_rate_limit, :only => [:create, :update, :delete]
13 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]" unless params["ways"]
15 ids = params["ways"].split(",").collect(&:to_i)
17 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
22 respond_to do |format|
29 @way = Way.find(params[:id])
31 response.last_modified = @way.timestamp
35 respond_to do |format|
45 way = Way.from_xml(request.raw_post, :create => true)
47 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
48 way.create_with_history current_user
49 render :plain => way.id.to_s
53 way = Way.find(params[:id])
54 new_way = Way.from_xml(request.raw_post)
56 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
58 way.update_from(new_way, current_user)
59 render :plain => way.version.to_s
62 # This is the API call to delete a way
64 way = Way.find(params[:id])
65 new_way = Way.from_xml(request.raw_post)
67 if new_way && new_way.id == way.id
68 way.delete_with_history!(new_way, current_user)
69 render :plain => way.version.to_s
76 @way = Way.includes(:nodes => :node_tags).find(params[:id])
83 @way.nodes.uniq.each do |node|
86 visible_nodes[node.id] = node
91 respond_to do |format|
101 # returns all the ways which are currently using the node given in the
102 # :id parameter. note that this used to return deleted ways as well, but
103 # this seemed not to be the expected behaviour, so it was removed.
105 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
107 @ways = Way.where(:id => wayids, :visible => true)
110 respond_to do |format|