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 if !way.preconditions_ok?
16 render :text => "", :status => :precondition_failed
19 way.user_id = @user.id
20 way.save_with_history!
22 render :text => way.id.to_s, :content_type => "text/plain"
25 render :nothing => true, :status => :bad_request
28 render :nothing => true, :status => :method_not_allowed
34 way = Way.find(params[:id])
36 response.headers['Last-Modified'] = way.timestamp.rfc822
39 render :text => way.to_xml.to_s, :content_type => "text/xml"
41 render :text => "", :status => :gone
43 rescue OSM::APIError => ex
45 rescue ActiveRecord::RecordNotFound
46 render :nothing => true, :status => :not_found
52 way = Way.find(params[:id])
53 new_way = Way.from_xml(request.raw_post)
55 if new_way and new_way.id == way.id
56 way.update_from(new_way, @user)
57 render :text => way.version.to_s, :content_type => "text/plain"
59 render :nothing => true, :status => :bad_request
61 rescue OSM::APIError => ex
63 rescue ActiveRecord::RecordNotFound
64 render :nothing => true, :status => :not_found
68 # This is the API call to delete a way
71 way = Way.find(params[:id])
72 way.delete_with_history(@user)
74 # if we get here, all is fine, otherwise something will catch below.
75 render :nothing => true
76 rescue OSM::APIError => ex
78 rescue ActiveRecord::RecordNotFound
79 render :nothing => true, :status => :not_found
85 way = Way.find(params[:id])
88 nd_ids = way.nds + [-1]
89 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
92 doc = OSM::API.new.get_xml_doc
94 doc.root << node.to_xml_node()
96 doc.root << way.to_xml_node()
98 render :text => doc.to_s, :content_type => "text/xml"
100 render :text => "", :status => :gone
102 rescue ActiveRecord::RecordNotFound
103 render :nothing => true, :status => :not_found
109 ids = params['ways'].split(',').collect { |w| w.to_i }
115 doc = OSM::API.new.get_xml_doc
117 Way.find(ids).each do |way|
118 doc.root << way.to_xml_node
121 render :text => doc.to_s, :content_type => "text/xml"
123 render :nothing => true, :status => :bad_request
128 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id[0] }.uniq
130 doc = OSM::API.new.get_xml_doc
132 Way.find(wayids).each do |way|
133 doc.root << way.to_xml_node
136 render :text => doc.to_s, :content_type => "text/xml"