1 # The NodeController is the RESTful interface to Node objects
4 class NodesController < ApiController
7 before_action :authorize, :only => [:create, :update, :delete]
11 before_action :require_public_data, :only => [:create, :update, :delete]
12 before_action :check_api_writable, :only => [:create, :update, :delete]
13 before_action :check_api_readable, :except => [:create, :update, :delete]
14 around_action :api_call_handle_error, :api_call_timeout
16 before_action :default_format_xml
18 # Set format to xml unless client requires a specific format
19 def default_format_xml
20 request.format = "xml" unless params[:format]
23 # Create a node from XML.
27 node = Node.from_xml(request.raw_post, true)
29 # Assume that Node.from_xml has thrown an exception if there is an error parsing the xml
30 node.create_with_history current_user
31 render :plain => node.id.to_s
34 # Dump the details on a node given in params[:id]
36 @node = Node.find(params[:id])
38 response.last_modified = @node.timestamp
42 respond_to do |format|
51 # Update a node from given XML
53 node = Node.find(params[:id])
54 new_node = Node.from_xml(request.raw_post)
56 raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})" unless new_node && new_node.id == node.id
58 node.update_from(new_node, current_user)
59 render :plain => node.version.to_s
62 # Delete a node. Doesn't actually delete it, but retains its history
63 # in a wiki-like way. We therefore treat it like an update, so the delete
64 # method returns the new version number.
66 node = Node.find(params[:id])
67 new_node = Node.from_xml(request.raw_post)
69 raise OSM::APIBadUserInput, "The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})" unless new_node && new_node.id == node.id
71 node.delete_with_history!(new_node, current_user)
72 render :plain => node.version.to_s
75 # Dump the details on many nodes whose ids are given in the "nodes" parameter.
77 raise OSM::APIBadUserInput, "The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]" unless params["nodes"]
79 ids = params["nodes"].split(",").collect(&:to_i)
81 raise OSM::APIBadUserInput, "No nodes were given to search for" if ids.empty?
83 @nodes = Node.find(ids)
86 respond_to do |format|