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
30 render :xml => way.to_xml.to_s
37 way = Way.find(params[:id])
38 new_way = Way.from_xml(request.raw_post)
40 unless new_way && new_way.id == way.id
41 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
44 way.update_from(new_way, current_user)
45 render :plain => way.version.to_s
48 # This is the API call to delete a way
50 way = Way.find(params[:id])
51 new_way = Way.from_xml(request.raw_post)
53 if new_way && new_way.id == way.id
54 way.delete_with_history!(new_way, current_user)
55 render :plain => way.version.to_s
62 way = Way.includes(:nodes => :node_tags).find(params[:id])
67 user_display_name_cache = {}
69 doc = OSM::API.new.get_xml_doc
70 way.nodes.uniq.each do |node|
72 doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
73 visible_nodes[node.id] = node
76 doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
78 render :xml => doc.to_s
86 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
89 ids = params["ways"].split(",").collect(&:to_i)
91 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
93 doc = OSM::API.new.get_xml_doc
95 Way.find(ids).each do |way|
96 doc.root << way.to_xml_node
99 render :xml => doc.to_s
103 # returns all the ways which are currently using the node given in the
104 # :id parameter. note that this used to return deleted ways as well, but
105 # this seemed not to be the expected behaviour, so it was removed.
107 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
109 doc = OSM::API.new.get_xml_doc
111 Way.find(wayids).each do |way|
112 doc.root << way.to_xml_node if way.visible
115 render :xml => doc.to_s