Class: Docker::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/connection.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/docker/connection.rb', line 15

def initialize(options = {})
  @base_url = options[:base_url]
  raise(ArgumentError, ':base_url missing') unless @base_url
end

Instance Method Details

#delete(path, params = {}, headers = {}) ⇒ Object



32
33
34
35
36
# File 'lib/docker/connection.rb', line 32

def delete(path, params = {}, headers = {})
  resp = perform_request(:DELETE, path, params, headers)
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
  resp
end

#get(path, params = {}, headers = {}) ⇒ Object



20
21
22
23
24
# File 'lib/docker/connection.rb', line 20

def get(path, params = {}, headers = {})
  resp = perform_request(:GET, path, params, headers)
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
  resp
end

#post(path, params = {}, body = '', headers = {}) ⇒ Object



26
27
28
29
30
# File 'lib/docker/connection.rb', line 26

def post(path, params = {}, body = '', headers = {})
  resp = perform_request(:POST, path, params, headers, body)
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
  resp
end

#stream(path, params = {}, timeout = nil, headers = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/docker/connection.rb', line 38

def stream(path, params = {}, timeout = nil, headers = {}, &block)
  raise(ArgumentError, 'Block required to handle streaming response') if block.nil?

  curl = curl_for(path, params, headers)

  begin
    timeout_raised = false
    curl.timeout = timeout if timeout
    curl.on_body {|data| block.call(data); data.size }
    curl.http(:POST)
  rescue Curl::Err::TimeoutError => e
    timeout_raised = true
  end

  Response.new(curl.body_str, curl.response_code, curl.content_type, timeout_raised)
end