cover the other extreme in the map bounary sanitizeation. Ading some documentation, which is parsed when running rake doc:app. Fixing up a couple of tests.

This commit is contained in:
Shaun McDonald 2008-10-26 23:43:37 +00:00
parent dc2a959037
commit b45dd63283
5 changed files with 61 additions and 24 deletions

View file

@ -16,7 +16,8 @@ class ApiController < ApplicationController
# Number of GPS trace/trackpoints returned per-page # Number of GPS trace/trackpoints returned per-page
TRACEPOINTS_PER_PAGE = APP_CONFIG['tracepoints_per_page'] TRACEPOINTS_PER_PAGE = APP_CONFIG['tracepoints_per_page']
# Get an XML response containing a list of tracepoints that have been uploaded
# within the specified bounding box, and in the specified page.
def trackpoints def trackpoints
@@count+=1 @@count+=1
#retrieve the page number #retrieve the page number
@ -84,6 +85,15 @@ class ApiController < ApplicationController
render :text => doc.to_s, :content_type => "text/xml" render :text => doc.to_s, :content_type => "text/xml"
end end
# This is probably the most common call of all. It is used for getting the
# OSM data for a specified bounding box, usually for editing. First the
# bounding box (bbox) is checked to make sure that it is sane. All nodes
# are searched, then all the ways that reference those nodes are found.
# All Nodes that are referenced by those ways are fetched and added to the list
# of nodes.
# Then all the relations that reference the already found nodes and ways are
# fetched. All the nodes and ways that are referenced by those ways are then
# fetched. Finally all the xml is returned.
def map def map
GC.start GC.start
@@count+=1 @@count+=1
@ -205,6 +215,8 @@ class ApiController < ApplicationController
end end
end end
# Get a list of the tiles that have changed within a specified time
# period
def changes def changes
zoom = (params[:zoom] || '12').to_i zoom = (params[:zoom] || '12').to_i
@ -250,6 +262,11 @@ class ApiController < ApplicationController
end end
end end
# External apps that use the api are able to query the api to find out some
# parameters of the API. It currently returns:
# * minimum and maximum API versions that can be used.
# * maximum area that can be requested in a bbox request in square degrees
# * number of tracepoints that are returned in each tracepoints page
def capabilities def capabilities
doc = OSM::API.new.get_xml_doc doc = OSM::API.new.get_xml_doc

View file

@ -4,6 +4,9 @@ class MessageController < ApplicationController
before_filter :authorize_web before_filter :authorize_web
before_filter :require_user before_filter :require_user
# Allow the user to write a new message to another user. This action also
# deals with the sending of that message to the other user when the user
# clicks send.
def new def new
@title = 'send message' @title = 'send message'
if params[:message] if params[:message]
@ -22,6 +25,7 @@ class MessageController < ApplicationController
end end
end end
# Allow the user to reply to another message.
def reply def reply
message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ]) message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
@body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}" @body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}"
@ -32,6 +36,7 @@ class MessageController < ApplicationController
render :nothing => true, :status => :not_found render :nothing => true, :status => :not_found
end end
# Show a message
def read def read
@title = 'read message' @title = 'read message'
@message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ]) @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
@ -41,6 +46,7 @@ class MessageController < ApplicationController
render :nothing => true, :status => :not_found render :nothing => true, :status => :not_found
end end
# Display the list of messages that have been sent to the user.
def inbox def inbox
@title = 'inbox' @title = 'inbox'
if @user and params[:display_name] == @user.display_name if @user and params[:display_name] == @user.display_name
@ -49,6 +55,7 @@ class MessageController < ApplicationController
end end
end end
# Display the list of messages that the user has sent to other users.
def outbox def outbox
@title = 'outbox' @title = 'outbox'
if @user and params[:display_name] == @user.display_name if @user and params[:display_name] == @user.display_name
@ -57,6 +64,7 @@ class MessageController < ApplicationController
end end
end end
# Set the message as being read or unread.
def mark def mark
if params[:message_id] if params[:message_id]
id = params[:message_id] id = params[:message_id]

View file

@ -1,7 +1,12 @@
This is the OpenStreetMap rails server codebase. Documentation is currently extremely incomplete. Please help by writing docs and moving any SQL you see to use models etc. This is the OpenStreetMap rails server codebase. Documentation is currently
extremely incomplete. Please help by writing docs and moving any SQL you
see to use models etc.
=INSTALL =INSTALL
Full information is available at
http://wiki.openstreetmap.org/index.php/Rails
* Get rails working (http://www.rubyonrails.org/) * Get rails working (http://www.rubyonrails.org/)
* Make your db (see db/README) * Make your db (see db/README)
* Install ruby libxml bindings: * Install ruby libxml bindings:
@ -18,14 +23,17 @@ This is the OpenStreetMap rails server codebase. Documentation is currently extr
See See
http://wiki.openstreetmap.org/index.php/REST#Changes_in_the_upcoming_0.4_API The information about the next version of the protocol API 0.6 is available at
http://wiki.openstreetmap.org/index.php/OSM_Protocol_Version_0.6
http://wiki.openstreetmap.org/index.php/REST
=HACKING =HACKING
* Log in to your site (proably localhost:3000) * Log in to your site (proably localhost:3000)
* Create a user and confirm it * Create a user and confirm it (by setting the active flag to true in the users table of the database
* You want to play with the API (probably at http://localhost:3000/api/0.5/node/create etc) * You want to play with the API (probably at http://localhost:3000/api/0.6/node/create etc)
* Lots of tests are needed to test the API. * Lots of tests are needed to test the API. To run the tests use
rake test
* Lots of little things to make the site work like the old one. * Lots of little things to make the site work like the old one.
=Bugs =Bugs

View file

@ -1,10 +1,11 @@
module MapBoundary module MapBoundary
# Take an array of length 4, and return the min_lon, min_lat, max_lon and
# max_lat within their respective boundaries.
def sanitise_boundaries(bbox) def sanitise_boundaries(bbox)
min_lon = [bbox[0].to_f,-180].max min_lon = [[bbox[0].to_f,-180].max,180].min
min_lat = [bbox[1].to_f,-90].max min_lat = [[bbox[1].to_f,-90].max,90].min
max_lon = [bbox[2].to_f,+180].min max_lon = [[bbox[2].to_f,+180].min,-180].max
max_lat = [bbox[3].to_f,+90].min max_lat = [[bbox[3].to_f,+90].min,-90].max
return min_lon, min_lat, max_lon, max_lat return min_lon, min_lat, max_lon, max_lat
end end

View file

@ -12,13 +12,15 @@ class ApiControllerTest < Test::Unit::TestCase
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
@badbigbbox = %w{ -0.1,-0.1,1.1,1.1 10,10,11,11 } @badbigbbox = %w{ -0.1,-0.1,1.1,1.1 10,10,11,11 }
@badmalformedbbox = %w{ -0.1 hello S0.1,W0.1,N0.1,E0.1 @badmalformedbbox = %w{ -0.1 hello
10N2W10.1N2.1W } 10N2W10.1N2.1W }
@badlatmixedbbox = %w{ 0,0.1,0.1,0 -0.1,80,0.1,70 0.24,54.34,0.25,54.33 } @badlatmixedbbox = %w{ 0,0.1,0.1,0 -0.1,80,0.1,70 0.24,54.34,0.25,54.33 }
@badlonmixedbbox = %w{ 80,-0.1,70,0.1 54.34,0.24,54.33,0.25 } @badlonmixedbbox = %w{ 80,-0.1,70,0.1 54.34,0.24,54.33,0.25 }
@badlatlonoutboundsbbox = %w{ 191,-0.1,193,0.1 -190.1,89.9,-190,90 } #@badlatlonoutboundsbbox = %w{ 191,-0.1,193,0.1 -190.1,89.9,-190,90 }
@goodbbox = %w{ -0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0 @goodbbox = %w{ -0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0
-0.1,%20-0.1,%200.1,%200.1 -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N } -0.1,%20-0.1,%200.1,%200.1 -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N S0.1,W0.1,N0.1,E0.1}
# That last item in the goodbbox really shouldn't be there, as the API should
# reall reject it, however this is to test to see if the api changes.
end end
def basic_authorization(user, pass) def basic_authorization(user, pass)
@ -114,16 +116,17 @@ class ApiControllerTest < Test::Unit::TestCase
end end
end end
def test_latlon_outofbounds # We can't actually get an out of bounds error, as the bbox is sanitised.
@badlatlonoutboundsbbox.each do |bbox| #def test_latlon_outofbounds
[ "trackpoints", "map" ].each do |tq| # @badlatlonoutboundsbbox.each do |bbox|
get tq, :bbox => bbox # [ "trackpoints", "map" ].each do |tq|
#print @request.to_yaml # get tq, :bbox => bbox
assert_response :bad_request, "The bbox #{bbox} was expected to be out of range" # #print @request.to_yaml
assert_equal "The latitudes must be between -90 an 90, and longitudes between -180 and 180", @response.body, "bbox: #{bbox}" # assert_response :bad_request, "The bbox #{bbox} was expected to be out of range"
end # assert_equal "The latitudes must be between -90 an 90, and longitudes between -180 and 180", @response.body, "bbox: #{bbox}"
end # end
end # end
#end
def test_capabilities def test_capabilities
get :capabilities get :capabilities