From 2c98558c86f50a26b96d4b0feebdb93195a10455 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 21 Jun 2007 22:52:40 +0000 Subject: [PATCH] Add support for segment/:id/ways and node/:id/segments API calls. Fixes #452. --- app/controllers/segment_controller.rb | 17 ++++++++++++++++- app/controllers/way_controller.rb | 15 +++++++++++++++ config/routes.rb | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 92825115f..5ef11084c 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -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 diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index 34f1ab5e7..e7eead52f 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index bc7f08b5b..67943d2b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 -- 2.43.2