]> git.openstreetmap.org Git - rails.git/blobdiff - lib/osm.rb
Adding a restriction to prevent more than 2000 nodes to be added to any way. Tests...
[rails.git] / lib / osm.rb
index ae8b81f5b13f1433f8fa3162cdeded0592c27f64..b002ebbe899b824fdb3d2f818681bb961d80b310 100644 (file)
@@ -54,6 +54,32 @@ module OSM
     end
   end
 
+  # Raised when a diff is uploaded containing many changeset IDs which don't match
+  # the changeset ID that the diff was uploaded to.
+  class APIChangesetMismatchError < APIError
+    def initialize(provided, allowed)
+      @provided, @allowed = provided, allowed
+    end
+    
+    def render_opts
+      { :text => "Changeset mismatch: Provided #{@provided} but only " +
+        "#{@allowed} is allowed.", :status => :conflict }
+    end
+  end
+
+  # Raised when bad XML is encountered which stops things parsing as
+  # they should.
+  class APIBadXMLError < APIError
+    def initialize(model, xml)
+      @model, @xml = model, xml
+    end
+
+    def render_opts
+      { :text => "Cannot parse valid #{@model} from xml string #{@xml}",
+        :status => :bad_request }
+    end
+  end
+
   # Raised when the provided version is not equal to the latest in the db.
   class APIVersionMismatchError < APIError
     def initialize(provided, latest)
@@ -82,6 +108,21 @@ module OSM
         :status => :bad_request }
     end
   end
+  
+  # Raised when a way has more than the configured number of way nodes.
+  # This prevents ways from being to long and difficult to work with
+  class APITooManyWayNodesError < APIError
+    def initialize(provided, max)
+      @provided, @max = provided, max
+    end
+    
+    attr_reader :provided, :max
+    
+    def render_opts
+      { :text => "You tried to add #{provided} nodes to the way, however only #{max} are allowed",
+      :status => :bad_request }
+    end
+  end
 
   # Helper methods for going to/from mercator and lat/lng.
   class Mercator
@@ -249,7 +290,7 @@ module OSM
       doc.encoding = 'UTF-8' 
       root = XML::Node.new 'osm'
       root['version'] = API_VERSION
-      root['generator'] = 'OpenStreetMap server'
+      root['generator'] = GENERATOR
       doc.root = root
       return doc
     end