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)
20 node.create_with_history @user
21 render :text => node.id.to_s, :content_type => "text/plain"
23 raise OSM::APIBadXMLError.new(:node, request.raw_post)
27 # Dump the details on a node given in params[:id]
29 node = Node.find(params[:id])
31 response.headers['Last-Modified'] = node.timestamp.rfc822
32 render :text => node.to_xml.to_s, :content_type => "text/xml"
34 render :text => "", :status => :gone
38 # Update a node from given XML
40 node = Node.find(params[:id])
41 new_node = Node.from_xml(request.raw_post)
43 if new_node and new_node.id == node.id
44 node.update_from(new_node, @user)
45 render :text => node.version.to_s, :content_type => "text/plain"
47 render :nothing => true, :status => :bad_request
51 # Delete a node. Doesn't actually delete it, but retains its history
52 # in a wiki-like way. We therefore treat it like an update, so the delete
53 # method returns the new version number.
55 node = Node.find(params[:id])
56 new_node = Node.from_xml(request.raw_post)
58 if new_node and new_node.id == node.id
59 node.delete_with_history!(new_node, @user)
60 render :text => node.version.to_s, :content_type => "text/plain"
62 render :nothing => true, :status => :bad_request
66 # Dump the details on many nodes whose ids are given in the "nodes" parameter.
68 ids = params['nodes'].split(',').collect { |n| n.to_i }
71 doc = OSM::API.new.get_xml_doc
73 Node.find(ids).each do |node|
74 doc.root << node.to_xml_node
77 render :text => doc.to_s, :content_type => "text/xml"
79 render :nothing => true, :status => :bad_request