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)
71 if new_way and new_way.id == way.id
72 way.delete_with_history!(new_way, @user)
73 render :text => way.version.to_s, :content_type => "text/plain"
75 render :nothing => true, :status => :bad_request
77 rescue OSM::APIError => ex
79 rescue ActiveRecord::RecordNotFound
80 render :nothing => true, :status => :not_found
86 way = Way.find(params[:id])
89 nd_ids = way.nds + [-1]
90 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
93 doc = OSM::API.new.get_xml_doc
95 doc.root << node.to_xml_node()
97 doc.root << way.to_xml_node()
99 render :text => doc.to_s, :content_type => "text/xml"
101 render :text => "", :status => :gone
103 rescue ActiveRecord::RecordNotFound
104 render :nothing => true, :status => :not_found
110 ids = params['ways'].split(',').collect { |w| w.to_i }
116 doc = OSM::API.new.get_xml_doc
118 Way.find(ids).each do |way|
119 doc.root << way.to_xml_node
122 render :text => doc.to_s, :content_type => "text/xml"
124 render :nothing => true, :status => :bad_request
129 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id[0] }.uniq
131 doc = OSM::API.new.get_xml_doc
133 Way.find(wayids).each do |way|
134 doc.root << way.to_xml_node
137 render :text => doc.to_s, :content_type => "text/xml"