Add support for segment/:id/ways and node/:id/segments API calls. Fixes #452.
This commit is contained in:
parent
6020e0519e
commit
2c98558c86
3 changed files with 33 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue