require 'rexml/parsers/sax2parser'
require 'rexml/text'
require 'xml/libxml'
- require 'digest/md5'
if defined?(SystemTimer)
Timer = SystemTimer
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
country = "GB" if country == "UK"
end
end
-
+
return country.upcase
end
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'
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)