1 class SegmentController < ApplicationController
4 before_filter :authorize
5 after_filter :compress_output
8 response.headers["Content-Type"] = 'text/xml'
10 segment = Segment.from_xml(request.raw_post, true)
13 segment.user_id = @user.id
15 segment.from_node = Node.find(segment.node_a.to_i)
16 segment.to_node = Node.find(segment.node_b.to_i)
18 if segment.from_node == segment.to_node
19 render :nothing => true, :status => HTTP_EXPECTATION_FAILED
23 unless segment.preconditions_ok? # are the nodes visible?
24 render :nothing => true, :status => HTTP_PRECONDITION_FAILED
28 if segment.save_with_history
29 render :text => segment.id.to_s
31 render :nothing => true, :status => 500
36 render :nothing => true, :status => 400 # if we got here the doc didnt parse
41 render :nothing => true, :status => 500 # something went very wrong
45 response.headers["Content-Type"] = 'text/xml'
46 unless Segment.exists?(params[:id])
47 render :nothing => true, :status => 404
51 segment = Segment.find(params[:id])
56 render :text => segment.to_xml.to_s
62 segment.save_with_history
63 render :nothing => true
65 render :nothing => true, :status => 410
69 new_segment = Segment.from_xml(request.raw_post)
71 segment.timestamp = Time.now
72 segment.user_id = @user.id
74 if new_segment.node_a == new_segment.node_b
75 render :nothing => true, :status => HTTP_EXPECTATION_FAILED
79 segment.node_a = new_segment.node_a
80 segment.node_b = new_segment.node_b
82 segment.tags = new_segment.tags
83 segment.visible = new_segment.visible
85 if segment.id == new_segment.id and segment.save_with_history
86 render :nothing => true, :status => HTTP_OK
88 render :nothing => true, :status => 500
96 response.headers["Content-Type"] = 'text/xml'
97 ids = params['segments'].split(',').collect {|s| s.to_i }
99 segmentlist = Segment.find(ids)
100 doc = OSM::API.get_xml_doc
101 segmentlist.each do |segment|
102 doc.root << segment.to_xml_node
104 render :text => doc.to_s
106 render :nothing => true, :status => 400