Class: Couch::Server
- Inherits:
-
Object
- Object
- Couch::Server
- Defined in:
- lib/couchdbSync/couch.rb
Instance Method Summary collapse
- #delete(uri) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize(host, port, options = nil) ⇒ Server
constructor
A new instance of Server.
- #post(uri, json) ⇒ Object
- #put(uri, json) ⇒ Object
- #request(req) ⇒ Object
Constructor Details
#initialize(host, port, options = nil) ⇒ Server
Returns a new instance of Server.
7 8 9 10 11 |
# File 'lib/couchdbSync/couch.rb', line 7 def initialize(host, port, = nil) @host = host @port = port @options = end |
Instance Method Details
#delete(uri) ⇒ Object
13 14 15 |
# File 'lib/couchdbSync/couch.rb', line 13 def delete(uri) request(Net::HTTP::Delete.new(uri)) end |
#get(uri) ⇒ Object
17 18 19 |
# File 'lib/couchdbSync/couch.rb', line 17 def get(uri) request(Net::HTTP::Get.new(uri)) end |
#post(uri, json) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/couchdbSync/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) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/couchdbSync/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) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/couchdbSync/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 |