lib/couchrest/extensions.rb in couch_surfer-0.3.2 vs lib/couchrest/extensions.rb in couch_surfer-0.3.3

- old
+ new

@@ -1,17 +1,25 @@ module CouchRest class Database # Query a CouchDB view as defined by a <tt>_design</tt> document. Accepts # paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi #/db/_design/examples/_list/index-posts/posts-by-date - + def list(list_name, view_name, doc_name, params = {}) url = CouchRest.paramify_url "#{@root}/_design/#{doc_name}/_list/#{list_name}/#{view_name}", params response = RestClient.get(url) JSON.parse(response) rescue response end + + # PUT an attachment directly to CouchDB + def put_attachment(doc, name, file, options = {}) + docid = escape_docid(doc['_id']) + uri = url_for_attachment(doc, name) + JSON.parse(HttpAbstraction.put(uri, file, options)) + end + end class Design # Dispatches to any named view. # (using the database where this design doc was saved) \ No newline at end of file