lib/base/db.rb in logworm-0.7.4 vs lib/base/db.rb in logworm-0.7.5
- old
+ new
@@ -58,17 +58,18 @@
end
def self.example_url
self.make_url("db.logworm.com", "Ub5sOstT9w", "GZi0HciTVcoFHEoIZ7", "OzO71hEvWYDmncbf3C", "J7wq4X06MihhZgqDeB")
end
+
def tables()
- res = db_call(:get, "#{host_with_protocol}/")
+ db_call(:get, "#{host_with_protocol}/") || []
end
def query(table, cond)
- res = db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
+ db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
end
def results(uri)
res = db_call(:get, uri)
raise InvalidQueryException.new("#{res['error']}") if res['error']
@@ -85,13 +86,13 @@
begin
res = @connection.send(method, uri, params)
rescue SocketError
raise DatabaseException
end
- raise DatabaseException if res.code.to_i == 404
+ raise InvalidQueryException.new("#{res.body}") if res.code.to_i == 400
+ raise ForbiddenAccessException if res.code.to_i == 403
+ raise DatabaseException if res.code.to_i == 404
raise DatabaseException.new("Server returned: #{res.body}") if res.code.to_i == 500
- raise ForbiddenAccessException if res.code.to_i == 403
- raise InvalidQueryException.new("#{res.body}") if res.code.to_i == 400
begin
JSON.parse(res.body)
rescue Exception => e
raise DatabaseException.new("Database reponse cannot be parsed: #{e}")
end