most specs passing with CouchRest module
This commit is contained in:
parent
7028f7f7b3
commit
211331f4a6
5 changed files with 38 additions and 33 deletions
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue