1 # The NodeController is the RESTful interface to Node objects
3 class NodeController < ApplicationController
7 before_filter :authorize, :only => [:create, :update, :delete]
8 before_filter :require_public_data, :only => [:create, :update, :delete]
9 before_filter :check_api_writable, :only => [:create, :update, :delete]
10 before_filter :check_api_readable, :except => [:create, :update, :delete]
11 after_filter :compress_output
12 around_filter :api_call_handle_error, :api_call_timeout
14 # Create a node from XML.
18 node = Node.from_xml(request.raw_post, true)
21 node.create_with_history @user
22 render :text => node.id.to_s, :content_type => "text/plain"
24 raise OSM::APIBadXMLError.new(:node, request.raw_post)
28 # Dump the details on a node given in params[:id]
30 node = Node.find(params[:id])
32 response.headers['Last-Modified'] = node.timestamp.rfc822
33 render :text => node.to_xml.to_s, :content_type => "text/xml"
35 render :text => "", :status => :gone
39 # Update a node from given XML
41 node = Node.find(params[:id])
42 new_node = Node.from_xml(request.raw_post)
44 if new_node and new_node.id == node.id
45 node.update_from(new_node, @user)
46 render :text => node.version.to_s, :content_type => "text/plain"
48 render :nothing => true, :status => :bad_request
52 # Delete a node. Doesn't actually delete it, but retains its history
53 # in a wiki-like way. We therefore treat it like an update, so the delete
54 # method returns the new version number.
56 node = Node.find(params[:id])
57 new_node = Node.from_xml(request.raw_post)
59 if new_node and new_node.id == node.id
60 node.delete_with_history!(new_node, @user)
61 render :text => node.version.to_s, :content_type => "text/plain"
63 render :nothing => true, :status => :bad_request
67 # Dump the details on many nodes whose ids are given in the "nodes" parameter.
69 ids = params['nodes'].split(',').collect { |n| n.to_i }
72 doc = OSM::API.new.get_xml_doc
74 Node.find(ids).each do |node|
75 doc.root << node.to_xml_node
78 render :text => doc.to_s, :content_type => "text/xml"
80 render :nothing => true, :status => :bad_request