1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_api_writable, :only => [:create, :update, :delete]
7 before_filter :check_api_readable, :except => [:create, :update, :delete]
8 after_filter :compress_output
13 way = Way.from_xml(request.raw_post, true)
16 way.create_with_history @user
17 render :text => way.id.to_s, :content_type => "text/plain"
19 render :nothing => true, :status => :bad_request
22 render :nothing => true, :status => :method_not_allowed
24 rescue OSM::APIError => ex
25 logger.warn request.raw_post
32 way = Way.find(params[:id])
34 response.headers['Last-Modified'] = way.timestamp.rfc822
37 render :text => way.to_xml.to_s, :content_type => "text/xml"
39 render :text => "", :status => :gone
41 rescue OSM::APIError => ex
43 rescue ActiveRecord::RecordNotFound
44 render :nothing => true, :status => :not_found
50 way = Way.find(params[:id])
51 new_way = Way.from_xml(request.raw_post)
53 if new_way and new_way.id == way.id
54 way.update_from(new_way, @user)
55 render :text => way.version.to_s, :content_type => "text/plain"
57 render :nothing => true, :status => :bad_request
59 rescue OSM::APIError => ex
60 logger.warn request.raw_post
62 rescue ActiveRecord::RecordNotFound
63 render :nothing => true, :status => :not_found
67 # This is the API call to delete a way
70 way = Way.find(params[:id])
71 new_way = Way.from_xml(request.raw_post)
73 if new_way and new_way.id == way.id
74 way.delete_with_history!(new_way, @user)
75 render :text => way.version.to_s, :content_type => "text/plain"
77 render :nothing => true, :status => :bad_request
79 rescue OSM::APIError => ex
81 rescue ActiveRecord::RecordNotFound
82 render :nothing => true, :status => :not_found
88 way = Way.find(params[:id])
91 nd_ids = way.nds + [-1]
92 nodes = Node.find(:all, :conditions => ["visible = ? AND id IN (#{nd_ids.join(',')})", true])
95 doc = OSM::API.new.get_xml_doc
97 doc.root << node.to_xml_node()
99 doc.root << way.to_xml_node()
101 render :text => doc.to_s, :content_type => "text/xml"
103 render :text => "", :status => :gone
105 rescue ActiveRecord::RecordNotFound
106 render :nothing => true, :status => :not_found
112 ids = params['ways'].split(',').collect { |w| w.to_i }
118 doc = OSM::API.new.get_xml_doc
120 Way.find(ids).each do |way|
121 doc.root << way.to_xml_node
124 render :text => doc.to_s, :content_type => "text/xml"
126 render :nothing => true, :status => :bad_request
131 # returns all the ways which are currently using the node given in the
132 # :id parameter. note that this used to return deleted ways as well, but
133 # this seemed not to be the expected behaviour, so it was removed.
135 wayids = WayNode.find(:all,
136 :conditions => ['node_id = ?', params[:id]]
137 ).collect { |ws| ws.id[0] }.uniq
139 doc = OSM::API.new.get_xml_doc
141 Way.find(wayids).each do |way|
142 doc.root << way.to_xml_node if way.visible
145 render :text => doc.to_s, :content_type => "text/xml"