1 # The NodeController is the RESTful interface to Node objects
3 class NodeController < ApplicationController
6 before_filter :authorize, :only => [:create, :update, :delete]
7 before_filter :require_public_data, :only => [:create, :update, :delete]
8 before_filter :check_api_writable, :only => [:create, :update, :delete]
9 before_filter :check_api_readable, :except => [:create, :update, :delete]
10 after_filter :compress_output
11 around_filter :api_call_handle_error, :api_call_timeout
13 # Create a node from XML.
17 node = Node.from_xml(request.raw_post, true)
19 # Assume that Node.from_xml has thrown an exception if there is an error parsing the xml
20 node.create_with_history @user
21 render :text => node.id.to_s, :content_type => "text/plain"
24 # Dump the details on a node given in params[:id]
26 node = Node.find(params[:id])
28 response.headers['Last-Modified'] = node.timestamp.rfc822
29 render :text => node.to_xml.to_s, :content_type => "text/xml"
31 render :text => "", :status => :gone
35 # Update a node from given XML
37 node = Node.find(params[:id])
38 new_node = Node.from_xml(request.raw_post)
40 unless new_node and new_node.id == node.id
41 raise OSM::BadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
43 node.update_from(new_node, @user)
44 render :text => node.version.to_s, :content_type => "text/plain"
47 # Delete a node. Doesn't actually delete it, but retains its history
48 # in a wiki-like way. We therefore treat it like an update, so the delete
49 # method returns the new version number.
51 node = Node.find(params[:id])
52 new_node = Node.from_xml(request.raw_post)
54 unless new_node and new_node.id == node.id
55 raise OSM::BadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
57 node.delete_with_history!(new_node, @user)
58 render :text => node.version.to_s, :content_type => "text/plain"
61 # Dump the details on many nodes whose ids are given in the "nodes" parameter.
63 ids = params['nodes'].split(',').collect { |n| n.to_i }
66 raise OSM::BadUserInput.new("No nodes were given to search for")
68 doc = OSM::API.new.get_xml_doc
70 Node.find(ids).each do |node|
71 doc.root << node.to_xml_node
74 render :text => doc.to_s, :content_type => "text/xml"