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
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 render :nothing => true, :status => :bad_request
26 render :nothing => true, :status => :method_not_allowed
28 rescue OSM::APIError => ex
33 # Dump the details on a node given in params[:id]
36 node = Node.find(params[:id])
38 response.headers['Last-Modified'] = node.timestamp.rfc822
39 render :text => node.to_xml.to_s, :content_type => "text/xml"
41 render :text => "", :status => :gone
43 rescue ActiveRecord::RecordNotFound
44 render :nothing => true, :status => :not_found
48 # Update a node from given XML
51 node = Node.find(params[:id])
52 new_node = Node.from_xml(request.raw_post)
54 if new_node and new_node.id == node.id
55 node.update_from(new_node, @user)
56 render :text => node.version.to_s, :content_type => "text/plain"
58 render :nothing => true, :status => :bad_request
60 rescue OSM::APIError => ex
62 rescue ActiveRecord::RecordNotFound
63 render :nothing => true, :status => :not_found
67 # Delete a node. Doesn't actually delete it, but retains its history
68 # in a wiki-like way. We therefore treat it like an update, so the delete
69 # method returns the new version number.
72 node = Node.find(params[:id])
73 new_node = Node.from_xml(request.raw_post)
75 if new_node and new_node.id == node.id
76 node.delete_with_history!(new_node, @user)
77 render :text => node.version.to_s, :content_type => "text/plain"
79 render :nothing => true, :status => :bad_request
81 rescue ActiveRecord::RecordNotFound
82 render :nothing => true, :status => :not_found
83 rescue OSM::APIError => ex
88 # Dump the details on many nodes whose ids are given in the "nodes" parameter.
90 ids = params['nodes'].split(',').collect { |n| n.to_i }
93 doc = OSM::API.new.get_xml_doc
95 Node.find(ids).each do |node|
96 doc.root << node.to_xml_node
99 render :text => doc.to_s, :content_type => "text/xml"
101 render :nothing => true, :status => :bad_request