]> git.openstreetmap.org Git - rails.git/blobdiff - lib/osm.rb
Make api changeset index path resourceful
[rails.git] / lib / osm.rb
index 65eab6907a00ff6008299f28d7d2beb8b674d78c..6710ee88e02b947c1294bb97d309e0d1e60b4118 100644 (file)
@@ -8,7 +8,7 @@ module OSM
   # The base class for API Errors.
   class APIError < RuntimeError
     def initialize(message = "Generic API Error")
-      super(message)
+      super
     end
 
     def status
@@ -51,14 +51,14 @@ module OSM
 
   # Raised when to delete an already-deleted object.
   class APIAlreadyDeletedError < APIError
-    def initialize(object = "object", object_id = "")
-      @object = object
-      @object_id = object_id
+    def initialize(type = "object", id = "")
+      @type = type
+      @id = id
 
-      super("The #{object} with the id #{object_id} has already been deleted")
+      super("The #{type} with the id #{id} has already been deleted")
     end
 
-    attr_reader :object, :object_id
+    attr_reader :type, :id
 
     def status
       :gone
@@ -364,6 +364,17 @@ module OSM
     end
   end
 
+  # Raised when a size limit is exceeded
+  class APISizeLimitExceeded < APIError
+    def initialize
+      super("Size limit exceeded")
+    end
+
+    def status
+      :payload_too_large
+    end
+  end
+
   # Helper methods for going to/from mercator and lat/lng.
   class Mercator
     include Math
@@ -524,7 +535,8 @@ module OSM
 
   # Return the HTTP client to use
   def self.http_client
-    @http_client ||= Faraday.new(:request => { :timeout => 15 })
+    @http_client ||= Faraday.new(:request => { :timeout => 15 },
+                                 :headers => { :user_agent => Settings.server_url })
   end
 
   # Return the MaxMindDB database handle