Add support for segment/:id/ways and node/:id/segments API calls. Fixes #452.
[rails.git] / app / controllers / segment_controller.rb
index 92825115f616a38d92e185f125ed556db619067b..5ef11084cb795809fd3eb834a8c57fdac5d1d2b2 100644 (file)
@@ -106,7 +106,22 @@ class SegmentController < ApplicationController
     ids = params['segments'].split(',').collect {|s| s.to_i }
     if ids.length > 0
       segmentlist = Segment.find(ids)
-      doc = OSM::API.get_xml_doc
+      doc = OSM::API.new.get_xml_doc
+      segmentlist.each do |segment|
+        doc.root << segment.to_xml_node
+      end 
+      render :text => doc.to_s
+    else
+      render :nothing => true, :status => 400
+    end
+  end
+
+  def segments_for_node
+    response.headers["Content-Type"] = 'text/xml'
+    segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
+    if segmentids.length > 0
+      segmentlist = Segment.find(segmentids)
+      doc = OSM::API.new.get_xml_doc
       segmentlist.each do |segment|
         doc.root << segment.to_xml_node
       end