most specs passing with CouchRest module

This commit is contained in:
Chris Anderson 2008-09-11 21:22:43 -07:00
parent 7028f7f7b3
commit 211331f4a6
5 changed files with 38 additions and 33 deletions

View file

@ -14,8 +14,43 @@ module CouchRest
autoload :Database, 'couchrest/core/database'
autoload :Pager, 'couchrest/helper/pager'
autoload :FileManager, 'couchrest/helper/file_manager'
autoload :Streamer, 'couchrest/helper/streamer'
def self.new(*opts)
Server.new(*opts)
end
# The CouchRest module methods handle the basic JSON serialization
# and deserialization, as well as query parameters.
class << self
def new(*opts)
Server.new(*opts)
end
def put uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.put(uri, payload))
end
def get uri
JSON.parse(RestClient.get(uri), :max_nesting => false)
end
def post uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.post(uri, payload))
end
def delete uri
JSON.parse(RestClient.delete(uri))
end
def paramify_url url, params = nil
if params
query = params.collect do |k,v|
v = v.to_json if %w{key startkey endkey}.include?(k.to_s)
"#{k}=#{CGI.escape(v.to_s)}"
end.join("&")
url = "#{url}?#{query}"
end
url
end
end # class << self
end

View file

@ -64,35 +64,5 @@ module CouchRest
@uuids.pop
end
class << self
def put uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.put(uri, payload))
end
def get uri
JSON.parse(RestClient.get(uri), :max_nesting => false)
end
def post uri, doc = nil
payload = doc.to_json if doc
JSON.parse(RestClient.post(uri, payload))
end
def delete uri
JSON.parse(RestClient.delete(uri))
end
def paramify_url url, params = nil
if params
query = params.collect do |k,v|
v = v.to_json if %w{key startkey endkey}.include?(k.to_s)
"#{k}=#{CGI.escape(v.to_s)}"
end.join("&")
url = "#{url}?#{query}"
end
url
end
end
end
end