Created
November 3, 2008 18:22
-
-
Save june29/21938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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