docker-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,71 +13,80 @@ class Docker::Connection
13
13
  end
14
14
 
15
15
  def initialize(options = {})
16
- @curl = Curl::Easy.new
17
16
  @base_url = options[:base_url]
18
17
  raise(ArgumentError, ':base_url missing') unless @base_url
19
18
  end
20
19
 
21
20
  def get(path, params = {}, headers = {})
22
- resp = perform_request(:GET, path, params, nil, headers)
21
+ resp = perform_request(:GET, path, params, headers)
23
22
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
24
23
  resp
25
24
  end
26
25
 
27
26
  def post(path, params = {}, body = '', headers = {})
28
- resp = perform_request(:POST, path, params, body, headers)
27
+ resp = perform_request(:POST, path, params, headers, body)
29
28
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
30
29
  resp
31
30
  end
32
31
 
33
32
  def delete(path, params = {}, headers = {})
34
- resp = perform_request(:DELETE, path, params, nil, headers)
33
+ resp = perform_request(:DELETE, path, params, headers)
35
34
  raise(Docker::Error::InternalServerError, resp.body) if resp.status == 500
36
35
  resp
37
36
  end
38
37
 
39
38
  def stream(path, params = {}, timeout = nil, headers = {}, &block)
40
39
  raise(ArgumentError, 'Block required to handle streaming response') if block.nil?
40
+
41
+ curl = curl_for(path, params, headers)
42
+
41
43
  begin
42
44
  timeout_raised = false
43
- set_url(path, params)
44
- set_headers(headers)
45
- @curl.timeout = timeout if timeout
46
- @curl.on_body {|data| block.call(data); data.size }
47
- @curl.http(:POST)
45
+ curl.timeout = timeout if timeout
46
+ curl.on_body {|data| block.call(data); data.size }
47
+ curl.http(:POST)
48
48
  rescue Curl::Err::TimeoutError => e
49
49
  timeout_raised = true
50
50
  end
51
- Response.new(@curl.body_str, @curl.response_code, @curl.content_type, timeout_raised)
51
+
52
+ Response.new(curl.body_str, curl.response_code, curl.content_type, timeout_raised)
52
53
  end
53
54
 
54
55
 
55
56
  private
56
57
 
57
- def perform_request(verb, path, query_params, body, headers)
58
- set_url(path, query_params)
59
- set_headers(headers)
60
- set_body(body)
61
- @curl.http(verb)
62
- Response.new(@curl.body_str, @curl.response_code, @curl.content_type)
58
+ def perform_request(verb, path, query_params = {}, headers = {}, body = nil)
59
+ curl = curl_for(path, query_params, headers, body)
60
+
61
+ curl.http(verb)
62
+
63
+ Response.new(curl.body_str, curl.response_code, curl.content_type)
63
64
  end
64
65
 
65
- def set_body(body)
66
- @curl.post_body = body if body
66
+ def curl_for(path, query_params = {}, headers = {}, body = nil)
67
+ Curl::Easy.new do |curl|
68
+ set_url(curl, path, query_params)
69
+ set_headers(curl, headers)
70
+ set_body(curl, body)
71
+ end
72
+ end
73
+
74
+ def set_body(curl, body)
75
+ curl.post_body = body if body
67
76
  end
68
77
 
69
- def set_url(path, query_params)
78
+ def set_url(curl, path, query_params)
70
79
  params = query_params.collect do |key, value|
71
- "#{@curl.escape(key)}=#{@curl.escape(value)}"
80
+ "#{curl.escape(key)}=#{curl.escape(value)}"
72
81
  end
73
82
  param_str = params.empty? ? '' : "?#{params.join('&')}"
74
- @curl.url = "#{@base_url}#{path}#{param_str}"
83
+ curl.url = "#{@base_url}#{path}#{param_str}"
75
84
  end
76
85
 
77
- def set_headers(headers)
86
+ def set_headers(curl, headers)
78
87
  headers.each do |key, value|
79
- @curl.headers[key] = value
88
+ curl.headers[key] = value
80
89
  end
81
90
  end
82
91
 
83
- end
92
+ end
@@ -1,3 +1,3 @@
1
1
  module Docker
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -20,7 +20,7 @@ describe Docker::Connection, :vcr do
20
20
  end
21
21
 
22
22
  it "returns a valid response for a basic request" do
23
- response = subject.send(:perform_request, :GET, '/containers/ps', {}, nil, {})
23
+ response = subject.send(:perform_request, :GET, '/containers/ps', {}, {}, nil)
24
24
  response.should be_kind_of(Docker::Connection::Response)
25
25
  response.status.should == 200
26
26
  response.content_type.should == "application/json"
@@ -28,7 +28,7 @@ describe Docker::Connection, :vcr do
28
28
  end
29
29
 
30
30
  it "returns status 404 for non existent path" do
31
- response = subject.send(:perform_request, :GET, '/invalid_path', {}, nil, {})
31
+ response = subject.send(:perform_request, :GET, '/invalid_path', {}, {}, nil)
32
32
  response.status.should == 404
33
33
  end
34
34
 
@@ -78,4 +78,4 @@ describe Docker::Connection, :vcr do
78
78
  # Alternative syntax
79
79
  # "Hello".should == 'Hello'
80
80
  # expect("Hello").to eq("Hello")
81
- end
81
+ end
@@ -110,7 +110,7 @@ describe Docker::Resource::Container do
110
110
  it "inspects the container's filesystem changes" do
111
111
  changes = subject.changes(@c)
112
112
  changes.should be_kind_of(Array)
113
- changes.any? {|c| c['path'] == '/tmp/changes'}
113
+ changes.any? {|c| c['Path'] == '/tmp/changes'}.should be_true
114
114
  end
115
115
  end
116
116
 
@@ -23,6 +23,7 @@ RSpec.configure do |config|
23
23
  config.treat_symbols_as_metadata_keys_with_true_values = true
24
24
  config.run_all_when_everything_filtered = true
25
25
  config.filter_run :focus
26
+ config.filter_run_excluding :live
26
27
  config.order = 'random'
27
28
  config.include Helpers
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler