various things
This commit is contained in:
parent
5f2116df78
commit
59cc0015f5
11 changed files with 62 additions and 24 deletions
27
app/controllers/api_controller.rb
Normal file
27
app/controllers/api_controller.rb
Normal file
|
@ -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
|
|
@ -1,2 +0,0 @@
|
|||
class MapController < ApplicationController
|
||||
end
|
|
@ -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
|
||||
|
|
2
app/helpers/api_helper.rb
Normal file
2
app/helpers/api_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module ApiHelper
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module MapHelper
|
||||
end
|
5
app/models/api.rb
Normal file
5
app/models/api.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class Api < ActiveRecord::Base
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
class Map < ActiveRecord::Base
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
11
db/migrate/012_create_apis.rb
Normal file
11
db/migrate/012_create_apis.rb
Normal file
|
@ -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
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue