Class: DeployCouch::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_couch/http_client.rb

Instance Method Summary collapse

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, options = {:suppress_exceptions=>false})
  request(Net::HTTP::Delete.new(uri),options)
end

#get(uri, options = {:suppress_exceptions=>false}) ⇒ Object



13
14
15
# File 'lib/deploy_couch/http_client.rb', line 13

def get(uri, options = {:suppress_exceptions=>false})
  request(Net::HTTP::Get.new(uri),options)
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, options = {:suppress_exceptions=>false})
  req = Net::HTTP::Post.new(uri)
  req["content-type"] = "application/json"
  req.body = json
  request(req,options)
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, options = {:suppress_exceptions=>false})
  req = Net::HTTP::Put.new(uri)
  req["content-type"] = "application/json"
  req.body = json
  request(req,options)
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, options)
  res = Net::HTTP.start(@host, @port) { |http|http.request(req) }
  isError = !res.kind_of?(Net::HTTPSuccess)
  shouldSupress = options[:suppress_exceptions]   
  if isError and !shouldSupress  
    handle_error(req, res)
  end
  res
end