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
12 way = Way.from_xml(request.raw_post, true)
15 unless way.preconditions_ok?
16 render :text => "", :status => :precondition_failed
19 way.save_with_history!
21 render :text => way.id.to_s, :content_type => "text/plain"
24 render :nothing => true, :status => :bad_request
27 render :nothing => true, :status => :method_not_allowed
33 way = Way.find(params[:id])
35 response.headers['Last-Modified'] = way.timestamp.rfc822
38 render :text => way.to_xml.to_s, :content_type => "text/xml"
40 render :text => "", :status => :gone
42 rescue OSM::APIError => ex
44 rescue ActiveRecord::RecordNotFound
45 render :nothing => true, :status => :not_found
51 way = Way.find(params[:id])
52 new_way = Way.from_xml(request.raw_post)
54 if new_way and new_way.id == way.id
55 way.update_from(new_way, @user)
56 render :text => way.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 # This is the API call to delete a way
70 way = Way.find(params[:id])
71 new_way = Way.from_xml(request.raw_post)
72 if new_way and new_way.id == way.id
73 way.delete_with_history(@user)
75 # if we get here, all is fine, otherwise something will catch below.
76 render :nothing => true
78 render :nothing => true, :status => :bad_request
80 rescue OSM::APIError => ex
82 rescue ActiveRecord::RecordNotFound
83 render :nothing => true, :status => :not_found
89 way = Way.find(params[:id])
92 nd_ids = way.nds + [-1]
93 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
96 doc = OSM::API.new.get_xml_doc
98 doc.root << node.to_xml_node()
100 doc.root << way.to_xml_node()
102 render :text => doc.to_s, :content_type => "text/xml"
104 render :text => "", :status => :gone
106 rescue ActiveRecord::RecordNotFound
107 render :nothing => true, :status => :not_found
113 ids = params['ways'].split(',').collect { |w| w.to_i }
119 doc = OSM::API.new.get_xml_doc
121 Way.find(ids).each do |way|
122 doc.root << way.to_xml_node
125 render :text => doc.to_s, :content_type => "text/xml"
127 render :nothing => true, :status => :bad_request
132 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id[0] }.uniq
134 doc = OSM::API.new.get_xml_doc
136 Way.find(wayids).each do |way|
137 doc.root << way.to_xml_node
140 render :text => doc.to_s, :content_type => "text/xml"