]> git.openstreetmap.org Git - rails.git/commitdiff
Add support for segment/:id/ways and node/:id/segments API calls. Fixes #452.
authorTom Hughes <tom@compton.nu>
Thu, 21 Jun 2007 22:52:40 +0000 (22:52 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 21 Jun 2007 22:52:40 +0000 (22:52 +0000)
app/controllers/segment_controller.rb
app/controllers/way_controller.rb
config/routes.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 
index 34f1ab5e7d3818f582df5664e6d3b3728f9ab189..e7eead52fe770d223e3a5cb1cc795db0745d6871 100644 (file)
@@ -135,4 +135,19 @@ class WayController < ApplicationController
     end
   end
 
+  def ways_for_segment
+    response.headers["Content-Type"] = 'text/xml'
+    wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
+    if wayids.length > 0
+      waylist = Way.find(wayids)
+      doc = OSM::API.new.get_xml_doc
+      waylist.each do |way|
+        doc.root << way.to_xml_node
+      end
+      render :text => doc.to_s
+    else
+      render :nothing => true, :status => 400
+    end
+  end
+
 end
index bc7f08b5b1e189f80dcfbda69d2b47ea4a9a363e..67943d2b504d135110adf5e7980f69a6b8ad62b4 100644 (file)
@@ -2,11 +2,13 @@ ActionController::Routing::Routes.draw do |map|
 
   # API
   map.connect "api/#{API_VERSION}/node/create", :controller => 'node', :action => 'create'
+  map.connect "api/#{API_VERSION}/node/:id/segments", :controller => 'segment', :action => 'segments_for_node'
   map.connect "api/#{API_VERSION}/node/:id/history", :controller => 'old_node', :action => 'history', :id => nil
   map.connect "api/#{API_VERSION}/node/:id", :controller => 'node', :action => 'rest', :id => nil 
   map.connect "api/#{API_VERSION}/nodes", :controller => 'node', :action => 'nodes', :id => nil
   
   map.connect "api/#{API_VERSION}/segment/create", :controller => 'segment', :action => 'create'
+  map.connect "api/#{API_VERSION}/segment/:id/ways", :controller => 'way', :action => 'ways_for_segment'
   map.connect "api/#{API_VERSION}/segment/:id/history", :controller => 'old_segment', :action => 'history'
   map.connect "api/#{API_VERSION}/segment/:id", :controller => 'segment', :action => 'rest'
   map.connect "api/#{API_VERSION}/segments", :controller => 'segment', :action => 'segments', :id => nil