Class: Docker::Connection
- Inherits:
-
Object
- Object
- Docker::Connection
- Defined in:
- lib/docker/connection.rb
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
- #delete(path, params = {}, headers = {}) ⇒ Object
- #get(path, params = {}, headers = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, params = {}, body = '', headers = {}) ⇒ Object
- #stream(path, params = {}, timeout = nil, headers = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 |
# File 'lib/docker/connection.rb', line 15 def initialize( = {}) @base_url = [: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
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 |