1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_write_availability, :only => [:create, :update, :delete]
7 before_filter :check_read_availability, :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
31 way = Way.find(params[:id])
33 response.headers['Last-Modified'] = way.timestamp.rfc822
36 render :text => way.to_xml.to_s, :content_type => "text/xml"
38 render :text => "", :status => :gone
40 rescue OSM::APIError => ex
42 rescue ActiveRecord::RecordNotFound
43 render :nothing => true, :status => :not_found
49 way = Way.find(params[:id])
50 new_way = Way.from_xml(request.raw_post)
52 if new_way and new_way.id == way.id
53 way.update_from(new_way, @user)
54 render :text => way.version.to_s, :content_type => "text/plain"
56 render :nothing => true, :status => :bad_request
58 rescue OSM::APIError => ex
60 rescue ActiveRecord::RecordNotFound
61 render :nothing => true, :status => :not_found
65 # This is the API call to delete a way
68 way = Way.find(params[:id])
69 new_way = Way.from_xml(request.raw_post)
70 if new_way and new_way.id == way.id
71 way.delete_with_history(new_way, @user)
73 # if we get here, all is fine, otherwise something will catch below.
74 render :nothing => true
76 render :nothing => true, :status => :bad_request
78 rescue OSM::APIError => ex
80 rescue ActiveRecord::RecordNotFound
81 render :nothing => true, :status => :not_found
87 way = Way.find(params[:id])
90 nd_ids = way.nds + [-1]
91 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
94 doc = OSM::API.new.get_xml_doc
96 doc.root << node.to_xml_node()
98 doc.root << way.to_xml_node()
100 render :text => doc.to_s, :content_type => "text/xml"
102 render :text => "", :status => :gone
104 rescue ActiveRecord::RecordNotFound
105 render :nothing => true, :status => :not_found
111 ids = params['ways'].split(',').collect { |w| w.to_i }
117 doc = OSM::API.new.get_xml_doc
119 Way.find(ids).each do |way|
120 doc.root << way.to_xml_node
123 render :text => doc.to_s, :content_type => "text/xml"
125 render :nothing => true, :status => :bad_request
130 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id[0] }.uniq
132 doc = OSM::API.new.get_xml_doc
134 Way.find(wayids).each do |way|
135 doc.root << way.to_xml_node
138 render :text => doc.to_s, :content_type => "text/xml"