1 class SegmentController < ApplicationController
4 before_filter :authorize
8 segment = Segment.from_xml(request.raw_post, true)
12 segment.user_id = @user.id
14 a = Node.find(segment.node_a.to_i)
15 b = Node.find(segment.node_b.to_i)
17 unless a and a.visible and b and b.visible
18 render :nothing => true, :status => 400
21 if segment.save_with_history
22 render :text => segment.id
24 render :nothing => true, :status => 500
29 render :nothing => true, :status => 400 # if we got here the doc didnt parse
34 render :nothing => true, :status => 500 # something went very wrong
38 unless Segment.exists?(params[:id])
39 render :nothing => true, :status => 400
43 segment = Segment.find(params[:id])
48 render :text => segment.to_xml.to_s
54 segment.save_with_history
55 render :nothing => true
57 render :nothing => true, :status => 410
61 new_segment = Segment.from_xml(request.raw_post)
63 segment.timestamp = Time.now
64 segment.user_id = @user.id
66 segment.node_a = new_segment.node_a
67 segment.node_b = new_segment.node_b
68 segment.tags = new_segment.tags
69 segment.visible = new_segment.visible
71 if segment.id == new_segment.id and segment.save_with_history
72 render :nothing => true, :status => 200
74 render :nothing => true, :status => 500
82 segment = Segment.find(params[:id])
85 render :nothing => true, :staus => 404
89 doc = XML::Document.new
90 doc.encoding = 'UTF-8'
91 root = XML::Node.new 'osm'
92 root['version'] = '0.4'
93 root['generator'] = 'OpenStreetMap server'
96 segment.old_segments.each do |old_segment|
97 el1 = XML::Node.new 'segment'
98 el1['id'] = old_segment.id.to_s
99 el1['from'] = old_segment.node_a.to_s
100 el1['to'] = old_segment.node_b.to_s
101 Segment.split_tags(el1, old_segment.tags)
102 el1['visible'] = old_segment.visible.to_s
103 el1['timestamp'] = old_segment.timestamp.xmlschema
107 render :text => doc.to_s