GPX api done
This commit is contained in:
parent
a9e1c229d2
commit
01cfcbd845
4 changed files with 64 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
class TraceController < ApplicationController
|
||||
before_filter :authorize_web
|
||||
before_filter :authorize, :only => [:api_details, :api_data, :api_create]
|
||||
layout 'site'
|
||||
|
||||
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
|
||||
|
@ -159,4 +160,41 @@ class TraceController < ApplicationController
|
|||
trace = Trace.find(params[:id])
|
||||
send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user)
|
||||
end
|
||||
|
||||
def api_details
|
||||
trace = Trace.find(params[:id])
|
||||
doc = OSM::API.new.get_xml_doc
|
||||
doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
|
||||
render :text => doc.to_s
|
||||
end
|
||||
|
||||
def api_data
|
||||
render :action => 'data'
|
||||
end
|
||||
|
||||
def api_create
|
||||
#FIXME merge this code with create as they're pretty similar?
|
||||
|
||||
filename = "/tmp/#{rand}"
|
||||
File.open(filename, "w") { |f| f.write(request.raw_post) }
|
||||
@params['trace'] = {}
|
||||
@params['trace']['name'] = params[:filename]
|
||||
@params['trace']['tagstring'] = params[:tags]
|
||||
@params['trace']['description'] = params[:description]
|
||||
@trace = Trace.new(@params['trace'])
|
||||
@trace.inserted = false
|
||||
@trace.user = @user
|
||||
@trace.timestamp = Time.now
|
||||
|
||||
if @trace.save
|
||||
saved_filename = "/tmp/#{@trace.id}.gpx"
|
||||
File.rename(filename, saved_filename)
|
||||
logger.info("id is #{@trace.id}")
|
||||
flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
|
||||
render :nothing => true
|
||||
else
|
||||
render :nothing => true, :status => 400 # er FIXME what fricking code to return?
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class UserController < ApplicationController
|
||||
layout 'site'
|
||||
|
||||
before_filter :authorize, :only => [:preferences, :api_details]
|
||||
before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
|
||||
before_filter :authorize_web, :only => [:rename, :account, :go_public]
|
||||
before_filter :require_user, :only => [:rename, :account, :go_public]
|
||||
|
||||
|
@ -129,5 +129,13 @@ class UserController < ApplicationController
|
|||
def api_details
|
||||
render :text => @user.to_xml.to_s
|
||||
end
|
||||
|
||||
def api_gpx_files
|
||||
doc = OSM::API.new.get_xml_doc
|
||||
@user.traces.each do |trace|
|
||||
doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
|
||||
end
|
||||
render :text => doc.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -54,4 +54,16 @@ class Trace < ActiveRecord::Base
|
|||
def icon_picture_name
|
||||
"/tmp/#{id}_icon.gif"
|
||||
end
|
||||
|
||||
def to_xml_node
|
||||
el1 = XML::Node.new 'gpx_file'
|
||||
el1['id'] = self.id.to_s
|
||||
el1['name'] = self.name.to_s
|
||||
el1['lat'] = self.latitude.to_s
|
||||
el1['lon'] = self.longitude.to_s
|
||||
el1['user'] = self.user.display_name
|
||||
el1['public'] = self.user.public
|
||||
el1['timestamp'] = self.timestamp.xmlschema
|
||||
return el1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,11 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect "api/#{API_VERSION}/map", :controller => 'api', :action => 'map'
|
||||
|
||||
map.connect "api/#{API_VERSION}/user/details", :controller => 'user', :action => 'api_details'
|
||||
map.connect "api/#{API_VERSION}/user/gpx_files", :controller => 'user', :action => 'api_gpx_files'
|
||||
|
||||
map.connect "api/#{API_VERSION}/gpx/create/:filename/:description/:tags", :controller => 'trace', :action => 'api_create'
|
||||
map.connect "api/#{API_VERSION}/gpx/:id/details", :controller => 'trace', :action => 'api_details'
|
||||
map.connect "api/#{API_VERSION}/gpx/:id/data", :controller => 'trace', :action => 'api_data'
|
||||
|
||||
# web site
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue