X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/52611a5bfa69165179bd871b925b5f8b14942e2e..25645ed51a5b2bbbd0b50d66258d1aeceb4aa223:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index 393011dac..2ed98b92d 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -5,7 +5,6 @@ module OSM require 'rexml/parsers/sax2parser' require 'rexml/text' require 'xml/libxml' - require 'digest/md5' if defined?(SystemTimer) Timer = SystemTimer @@ -298,6 +297,40 @@ module OSM end end + # Raised when the note provided is already open + class APINoteAlreadyOpenError < APIError + def initialize(note) + @note = note + end + + attr_reader :note + + def status + :conflict + end + + def to_s + "The note #{@note.id} is already open" + end + end + + # raised when a two preferences have a duplicate key string. + class APIDuplicatePreferenceError < APIError + def initialize(key) + @key = key + end + + attr_reader :key + + def status + :bad_request + end + + def to_s + "Duplicate preferences with key #{@key}" + end + end + # Helper methods for going to/from mercator and lat/lng. class Mercator include Math @@ -497,7 +530,7 @@ module OSM country = "GB" if country == "UK" end end - + return country.upcase end @@ -516,6 +549,13 @@ module OSM return nil end + # Parse a float, raising a specified exception on failure + def self.parse_float(str, klass, *args) + Float(str) + rescue + raise klass.new(*args) + end + # Construct a random token of a given length def self.make_token(length = 30) chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' @@ -528,12 +568,6 @@ module OSM return token end - # Return an encrypted version of a password - def self.encrypt_password(password, salt) - return Digest::MD5.hexdigest(password) if salt.nil? - return Digest::MD5.hexdigest(salt + password) - end - # Return an SQL fragment to select a given area of the globe def self.sql_for_area(bbox, prefix = nil) tilesql = QuadTile.sql_for_area(bbox, prefix)