Class: Couch::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/couch/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Client


5
6
7
8
# File 'lib/couch/client.rb', line 5

def initialize(uri)
  @uri = uri
  @http = HTTPkit::Client.start(config)
end

Instance Method Details

#configObject


10
11
12
13
14
15
16
# File 'lib/couch/client.rb', line 10

def config
  { address: @uri.host, port: @uri.port, ssl: @uri.scheme == 'https',
    handlers: [HTTPkit::Client::SSLHandler.new,
               HTTPkit::Client::KeepAliveHandler.new,
               HTTPkit::Client::TimeoutsHandler.new],
    timeout: 120, connect_timeout: 120 }
end

#request(http_method, uri, body = nil) ⇒ Object


18
19
20
21
22
# File 'lib/couch/client.rb', line 18

def request(http_method, uri, body = nil)
  request = Request.new(http_method, uri, {}, body)
  response = @http.perform(request).sync
  Response.build(response)
end