Skip to content

Instantly share code, notes, and snippets.

@june29
Created November 3, 2008 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/21938 to your computer and use it in GitHub Desktop.
Save june29/21938 to your computer and use it in GitHub Desktop.
require "net/http"
require "json"
class CouchDB
def initialize(host, port = 5984)
@host = host
@port = port
end
def get(uri)
JSON.parse(request(Net::HTTP::Get.new(uri)).body)
end
def put(uri, hash)
req = Net::HTTP::Put.new(uri)
req["content-type"] = "application/json"
req.body = JSON.generate(hash)
request(req)
end
def request(req)
res = Net::HTTP.start(@host, @port) { |http|
http.request(req)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment