From 59cc0015f565e89327d83bbb3b0787e7c4270ed9 Mon Sep 17 00:00:00 2001 From: Steve Coast Date: Fri, 17 Nov 2006 19:56:54 +0000 Subject: [PATCH] various things --- app/controllers/api_controller.rb | 27 +++++++++++++++++++++++++++ app/controllers/map_controller.rb | 2 -- app/controllers/node_controller.rb | 9 +++++++-- app/helpers/api_helper.rb | 2 ++ app/helpers/map_helper.rb | 2 -- app/models/api.rb | 5 +++++ app/models/map.rb | 2 -- app/models/node.rb | 7 ++++--- config/routes.rb | 8 ++++++-- db/migrate/012_create_apis.rb | 11 +++++++++++ db/migrate/012_create_maps.rb | 11 ----------- 11 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 app/controllers/api_controller.rb delete mode 100644 app/controllers/map_controller.rb create mode 100644 app/helpers/api_helper.rb delete mode 100644 app/helpers/map_helper.rb create mode 100644 app/models/api.rb delete mode 100644 app/models/map.rb create mode 100644 db/migrate/012_create_apis.rb delete mode 100644 db/migrate/012_create_maps.rb diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb new file mode 100644 index 000000000..99afae672 --- /dev/null +++ b/app/controllers/api_controller.rb @@ -0,0 +1,27 @@ +class ApiController < ApplicationController + + def map + + + doc = XML::Document.new + doc.encoding = 'UTF-8' + root = XML::Node.new 'osm' + root['version'] = '0.4' + root['generator'] = 'OpenStreetMap server' + doc.root = root + + render :text => doc.to_s + + #el1 = XML::Node.new 'node' + #el1['id'] = self.id.to_s + #el1['lat'] = self.latitude.to_s + #el1['lon'] = self.longitude.to_s + #Node.split_tags(el1, self.tags) + #el1['visible'] = self.visible.to_s + #el1['timestamp'] = self.timestamp.xmlschema + #root << el1 + end + + + +end diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb deleted file mode 100644 index c36dba1c6..000000000 --- a/app/controllers/map_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class MapController < ApplicationController -end diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 428d4b9c2..c5b4f279b 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -5,12 +5,17 @@ class NodeController < ApplicationController def create if request.put? - node = Node.from_xml(request.raw_post, true) + node = nil + begin + node = Node.from_xml(request.raw_post, true) + rescue + render :text => "XML didn't parse", :status => 400 # if we got here the doc didnt parse + return + end if node node.user_id = @user.id if node.save_with_history - render :text => node.id else render :nothing => true, :status => 500 diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb new file mode 100644 index 000000000..1f82fcf9b --- /dev/null +++ b/app/helpers/api_helper.rb @@ -0,0 +1,2 @@ +module ApiHelper +end diff --git a/app/helpers/map_helper.rb b/app/helpers/map_helper.rb deleted file mode 100644 index 65a956169..000000000 --- a/app/helpers/map_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module MapHelper -end diff --git a/app/models/api.rb b/app/models/api.rb new file mode 100644 index 000000000..ce56602db --- /dev/null +++ b/app/models/api.rb @@ -0,0 +1,5 @@ +class Api < ActiveRecord::Base + + + +end diff --git a/app/models/map.rb b/app/models/map.rb deleted file mode 100644 index e7d4ce281..000000000 --- a/app/models/map.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Map < ActiveRecord::Base -end diff --git a/app/models/node.rb b/app/models/node.rb index c37be933a..f184a6ae9 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -27,8 +27,10 @@ class Node < ActiveRecord::Base return nil end - if pt['id'] != '0' - node.id = pt['id'].to_i + unless create + if pt['id'] != '0' + node.id = pt['id'].to_i + end end node.visible = pt['visible'] and pt['visible'] == 'true' @@ -102,5 +104,4 @@ class Node < ActiveRecord::Base end end end - end diff --git a/config/routes.rb b/config/routes.rb index 4f898ea76..3ad3dddf4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ ActionController::Routing::Routes.draw do |map| -# map.connect ':controller/service.wsdl', :action => 'wsdl' + + # API map.connect 'api/0.4/node/create', :controller => 'node', :action => 'create' map.connect 'api/0.4/node/:id/history', :controller => 'node', :action => 'history', :id => nil @@ -10,9 +11,12 @@ ActionController::Routing::Routes.draw do |map| map.connect 'api/0.4/segment/:id', :controller => 'segment', :action => 'rest' map.connect 'api/0.4/way/create', :controller => 'way', :action => 'create' + map.connect 'api/0.4/way/:id/history', :controller => 'way', :action => 'history' map.connect 'api/0.4/way/:id', :controller => 'way', :action => 'rest' + + map.connect 'api/0.4/map', :controller => 'api', :action => 'map' - # misc site stuff + # web site map.connect '/', :controller => 'site', :action => 'index' map.connect '/index.html', :controller => 'site', :action => 'index' diff --git a/db/migrate/012_create_apis.rb b/db/migrate/012_create_apis.rb new file mode 100644 index 000000000..21989cfd7 --- /dev/null +++ b/db/migrate/012_create_apis.rb @@ -0,0 +1,11 @@ +class CreateApis < ActiveRecord::Migration + def self.up + create_table :apis do |t| + # t.column :name, :string + end + end + + def self.down + drop_table :apis + end +end diff --git a/db/migrate/012_create_maps.rb b/db/migrate/012_create_maps.rb deleted file mode 100644 index c44068a20..000000000 --- a/db/migrate/012_create_maps.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMaps < ActiveRecord::Migration - def self.up - create_table :maps do |t| - # t.column :name, :string - end - end - - def self.down - drop_table :maps - end -end -- 2.39.5