class Couch::Server
Public Class Methods
new(host, port, options = nil)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 7 def initialize(host, port, options = nil) @host = host @port = port @options = options end
Public Instance Methods
delete(uri)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 13 def delete(uri) request(Net::HTTP::Delete.new(uri)) end
get(uri)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 17 def get(uri) request(Net::HTTP::Get.new(uri)) end
post(uri, json)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 28 def post(uri, json) req = Net::HTTP::Post.new(uri) req["content-type"] = "application/json" req.body = json request(req) end
put(uri, json)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 21 def put(uri, json) req = Net::HTTP::Put.new(uri) req["content-type"] = "application/json" req.body = json request(req) end
request(req)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 35 def request(req) res = Net::HTTP.start(@host, @port) { |http|http.request(req) } unless res.kind_of?(Net::HTTPSuccess) handle_error(req, res) end res end
Private Instance Methods
handle_error(req, res)
click to toggle source
# File lib/couchdb/couchdb_replicator/couch.rb, line 45 def handle_error(req, res) e = RuntimeError.new("#{res.code}:#{res.message}\nMETHOD:#{req.method}\nURI:#{req.path}\n#{res.body}") raise e end