ability to set keys and count on temp_views
This commit is contained in:
parent
ce5bf9ffe8
commit
ea68f7af85
3 changed files with 29 additions and 11 deletions
|
@ -53,6 +53,17 @@ class CouchRest
|
|||
def delete uri
|
||||
JSON.parse(RestClient.delete(uri))
|
||||
end
|
||||
|
||||
def paramify_url url, params = nil
|
||||
if params
|
||||
query = params.collect do |k,v|
|
||||
v = JSON.unparse(v) 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
|
||||
|
|
|
@ -13,19 +13,13 @@ class CouchRest
|
|||
CouchRest.get "#{@root}/_all_docs"
|
||||
end
|
||||
|
||||
def temp_view funcs, type = 'application/json'
|
||||
JSON.parse(RestClient.post("#{@root}/_temp_view", JSON.unparse(funcs), {"Content-Type" => type}))
|
||||
def temp_view funcs, params = nil
|
||||
url = CouchRest.paramify_url "#{@root}/_temp_view", params
|
||||
JSON.parse(RestClient.post(url, JSON.unparse(funcs), {"Content-Type" => 'application/json'}))
|
||||
end
|
||||
|
||||
def view name, params = nil
|
||||
url = "#{@root}/_view/#{name}"
|
||||
if params
|
||||
query = params.collect do |k,v|
|
||||
v = JSON.unparse(v) if %w{key startkey endkey}.include?(k.to_s)
|
||||
"#{k}=#{CGI.escape(v.to_s)}"
|
||||
end.join("&")
|
||||
url = "#{url}?#{query}"
|
||||
end
|
||||
url = CouchRest.paramify_url "#{@root}/_view/#{name}", params
|
||||
CouchRest.get url
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue