Class: DeployCouch::Server
- Inherits:
-
Object
- Object
- DeployCouch::Server
- Defined in:
- lib/deploy_couch/http_client.rb
Instance Method Summary collapse
- #delete(uri, options = {:suppress_exceptions=>false}) ⇒ Object
- #get(uri, options = {:suppress_exceptions=>false}) ⇒ Object
-
#initialize(host, port) ⇒ Server
constructor
A new instance of Server.
- #post(uri, json, options = {:suppress_exceptions=>false}) ⇒ Object
- #put(uri, json, options = {:suppress_exceptions=>false}) ⇒ Object
- #request(req, options) ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
4 5 6 7 |
# File 'lib/deploy_couch/http_client.rb', line 4 def initialize(host, port) @host = host @port = port end |
Instance Method Details
#delete(uri, options = {:suppress_exceptions=>false}) ⇒ Object
9 10 11 |
# File 'lib/deploy_couch/http_client.rb', line 9 def delete(uri, = {:suppress_exceptions=>false}) request(Net::HTTP::Delete.new(uri),) end |
#get(uri, options = {:suppress_exceptions=>false}) ⇒ Object
13 14 15 |
# File 'lib/deploy_couch/http_client.rb', line 13 def get(uri, = {:suppress_exceptions=>false}) request(Net::HTTP::Get.new(uri),) end |
#post(uri, json, options = {:suppress_exceptions=>false}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/deploy_couch/http_client.rb', line 24 def post(uri, json, = {:suppress_exceptions=>false}) req = Net::HTTP::Post.new(uri) req["content-type"] = "application/json" req.body = json request(req,) end |
#put(uri, json, options = {:suppress_exceptions=>false}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/deploy_couch/http_client.rb', line 17 def put(uri, json, = {:suppress_exceptions=>false}) req = Net::HTTP::Put.new(uri) req["content-type"] = "application/json" req.body = json request(req,) end |
#request(req, options) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/deploy_couch/http_client.rb', line 31 def request(req, ) res = Net::HTTP.start(@host, @port) { |http|http.request(req) } isError = !res.kind_of?(Net::HTTPSuccess) shouldSupress = [:suppress_exceptions] if isError and !shouldSupress handle_error(req, res) end res end |