dockerapi 0.22.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2de49c8dede70d8314d0e7a4fea7ccd80ae17efcc0ca2fd88baa1da9b851f48e
4
- data.tar.gz: a7b326e2932cbbe926fff006d7776ec861473eb15e56d5b4b1d8f06557e8caf3
3
+ metadata.gz: 1676c69bedabf93f4da697ee177428beb48232ba36977a6b2f92cc5f411881ae
4
+ data.tar.gz: 4d3af8188af0d79e451917ee57d0e6a05bcc47a472ee4dff6336e6a2a4ab999d
5
5
  SHA512:
6
- metadata.gz: 2930087ae646cb941897126cda7bb89cb1687a0c4a48bf83d3ed6938f12a15aa78ab6350e721d93097a628d2c6e2076671dafe0b6d5ead1fdfe579de640018a5
7
- data.tar.gz: 7c3237567b5fa181d54926e1d9e1ef88706227a9dd987ae3aef5ad1e91d56e62bbc2c4fdba0ac833260770e120ef6b87fedb647725a17b1627f07143a7015378
6
+ metadata.gz: e1f784635089efd4bb31c0e93002b3c363c856420e827ad4fc790c855fa3095cc281c4cb663d8207f5614651c95c1069eb2cadc4316fc609464d0edae2e8c493
7
+ data.tar.gz: e1826a2e006cddc84b7a09da79b8c6fbbec6d0e0961d5405a0e7e77d8da0808826edc9c7629777c7e91794e45b0a8ed8ff387673f73312f5ed27fa8c4a99b02c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.22.0)
4
+ dockerapi (1.0.0)
5
5
  base64
6
6
  excon (>= 0.97, < 2)
7
7
 
data/README.md CHANGED
@@ -4,6 +4,7 @@ Interact with Docker API directly from Ruby code. Comprehensive implementation (
4
4
 
5
5
  * [Installation](#installation)
6
6
  * [Usage](#usage)
7
+ * [API version](#api-version)
7
8
  * [Images](#images)
8
9
  * [Containers](#containers)
9
10
  * [Volumes](#volumes)
@@ -52,6 +53,31 @@ If you need more information about the different Docker API endpoints, please se
52
53
 
53
54
  For a more detailed and comprehensive documentation about this gem's API, please see the [documentation page](https://rubydoc.info/gems/dockerapi).
54
55
 
56
+ ### API version
57
+
58
+ The Docker API is backward-compatible, which means we can specify which version of the API we want to use. Doing so is optional in order to take advantage of a specific feature.
59
+
60
+ We can specify the version to be used in 2 ways:
61
+
62
+
63
+ Use a specific version for all new instances
64
+
65
+ ```ruby
66
+ Docker::API.default_api_version="1.43"
67
+ image = Docker::API::Image.new
68
+ image.list.path
69
+ => "/v1.43/images/json"
70
+ ```
71
+
72
+ Change the version used after the instance is created
73
+
74
+ ```ruby
75
+ image = Docker::API::Image.new
76
+ image.api_version="1.43"
77
+ image.list.path
78
+ => "/v1.43/images/json"
79
+ ```
80
+
55
81
  ### Images
56
82
 
57
83
  ```ruby
@@ -592,7 +618,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
592
618
  * Update version.
593
619
  * Run tests.
594
620
  * Commit changes.
595
- * Release / push version to Rubygems & Github.
621
+ * Push a new Github tag with `git tag $(bundle exec rake version | tr -d '"') && git push --tags`.
596
622
 
597
623
  ## Contributing
598
624
 
data/Rakefile CHANGED
@@ -6,5 +6,5 @@ RSpec::Core::RakeTask.new(:spec)
6
6
  task :default => :spec
7
7
 
8
8
  task :version do
9
- p "v#{Docker::API::GEM_VERSION}"
9
+ p "v#{Docker::API::VERSION}"
10
10
  end
data/dockerapi.gemspec CHANGED
@@ -2,7 +2,7 @@ require_relative 'lib/docker/api/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "dockerapi"
5
- spec.version = Docker::API::GEM_VERSION
5
+ spec.version = Docker::API::VERSION
6
6
  spec.authors = ["Alysson A. Costa"]
7
7
  spec.email = ["alysson.avila.costa@gmail.com"]
8
8
 
@@ -1,6 +1,23 @@
1
1
  ##
2
2
  # Base class to provide general methods, helpers and implementations accross classes.
3
3
  class Docker::API::Base
4
+ attr_accessor(:api_version)
5
+
6
+ [:get, :post, :head, :delete, :put].each do | method |
7
+ define_method(method) { | path, params = {} | self.request(method: method, path: path, params: params) }
8
+ end
9
+
10
+ ##
11
+ # Call an Excon request and returns a Docker::API::Response object.
12
+ #
13
+ # @param params [Hash]: Request parameters.
14
+ def request params
15
+ params[:path] = build_path(params[:path], params[:params] ||= {})
16
+ response = Docker::API::Response.new(@connection.excon.request(params).data)
17
+ response.request_params = params
18
+ p response if Docker::API.print_response_to_stdout
19
+ response
20
+ end
4
21
 
5
22
  ##
6
23
  # Create new object and sets the validation to happen automatically when method parameters include "params" or "body".
@@ -9,6 +26,7 @@ class Docker::API::Base
9
26
  def initialize connection = nil
10
27
  raise StandardError.new("Expected connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
11
28
  @connection = connection || Docker::API::Connection.new
29
+ @api_version = Docker::API.default_api_version
12
30
  end
13
31
 
14
32
  private
@@ -43,9 +61,9 @@ class Docker::API::Base
43
61
  # @param url [String]: Endpoint URL where the file is going to be sent.
44
62
  # @param header [Hash]: Header of the request.
45
63
  # @param &block: Replace the default output to stdout behavior.
46
- def default_reader path, url, header = {"Content-Type" => "application/x-tar"}, &block
64
+ def default_reader path, base_url, params, header = {"Content-Type" => "application/x-tar"}, &block
47
65
  file = File.open(File.expand_path(path), "r")
48
- response = @connection.request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer )
66
+ response = request(method: :post, path: base_url, params: params , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer )
49
67
  file.close
50
68
  response
51
69
  end
@@ -76,7 +94,7 @@ class Docker::API::Base
76
94
  # @param path [String]: Base URL string.
77
95
  # @param hash [Hash]: Hash object to be appended to the URL as query parameters.
78
96
  def build_path path, params = {}
79
- path = "/v#{Docker::API::API_VERSION}#{path}"
97
+ path = "/v#{@api_version}#{path}"
80
98
  params.size > 0 ? [path, hash_to_params(params)].join("?") : path
81
99
  end
82
100
 
@@ -13,7 +13,7 @@ class Docker::API::Config < Docker::API::Base
13
13
  #
14
14
  # @param params [Hash]: Parameters that are appended to the URL.
15
15
  def list params = {}
16
- @connection.get(build_path("/configs",params))
16
+ get("/configs", params)
17
17
  end
18
18
 
19
19
  # Create a config
@@ -24,7 +24,7 @@ class Docker::API::Config < Docker::API::Base
24
24
  #
25
25
  # @param body [Hash]: Request body to be sent as json.
26
26
  def create body = {}
27
- @connection.request(method: :post, path: "/v#{Docker::API::API_VERSION}/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
27
+ request(method: :post, path: "/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
28
28
  end
29
29
 
30
30
  # Inspect a config
@@ -35,7 +35,7 @@ class Docker::API::Config < Docker::API::Base
35
35
  #
36
36
  # @param name [String]: The ID or name of the config.
37
37
  def details name
38
- @connection.get("/v#{Docker::API::API_VERSION}/configs/#{name}")
38
+ get("/configs/#{name}")
39
39
  end
40
40
 
41
41
  # Update a config
@@ -50,7 +50,7 @@ class Docker::API::Config < Docker::API::Base
50
50
  #
51
51
  # @param body [Hash]: Request body to be sent as json.
52
52
  def update name, params = {}, body = {}
53
- @connection.request(method: :post, path: build_path("/v#{Docker::API::API_VERSION}/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
53
+ request(method: :post, path: "/configs/#{name}/update", params: params, headers: {"Content-Type": "application/json"}, body: body.to_json)
54
54
  end
55
55
 
56
56
  # Delete a config
@@ -61,6 +61,6 @@ class Docker::API::Config < Docker::API::Base
61
61
  #
62
62
  # @param name [String]: The ID or name of the config.
63
63
  def remove name
64
- @connection.delete("/v#{Docker::API::API_VERSION}/configs/#{name}")
64
+ delete("/configs/#{name}")
65
65
  end
66
66
  end
@@ -1,20 +1,7 @@
1
1
  ##
2
2
  # Connection class.
3
3
  class Docker::API::Connection
4
- [:get, :post, :head, :delete, :put].each do | method |
5
- define_method(method) { | path | self.request(method: method, path: path) }
6
- end
7
-
8
- ##
9
- # Call an Excon request and returns a Docker::API::Response object.
10
- #
11
- # @param params [Hash]: Request parameters.
12
- def request params
13
- response = Docker::API::Response.new(@connection.request(params).data)
14
- response.request_params = params
15
- p response if Docker::API.print_response_to_stdout
16
- response
17
- end
4
+ attr_reader(:excon)
18
5
 
19
6
  ##
20
7
  # Create an Excon connection.
@@ -22,8 +9,8 @@ class Docker::API::Connection
22
9
  # @param url [String]: URL for the connection.
23
10
  # @param params [String]: Additional parameters.
24
11
  def initialize url = nil, params = {}
25
- return @connection = Excon.new('unix:///', params.merge({socket: '/var/run/docker.sock'})) unless url
26
- @connection = Excon.new(url, params)
12
+ return @excon = Excon.new('unix:///', params.merge({socket: '/var/run/docker.sock'})) unless url
13
+ @excon = Excon.new(url, params)
27
14
  end
28
15
 
29
16
  end
@@ -11,7 +11,7 @@ class Docker::API::Container < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/containers/json", params))
14
+ get("/containers/json", params)
15
15
  end
16
16
 
17
17
  ##
@@ -23,7 +23,7 @@ class Docker::API::Container < Docker::API::Base
23
23
  # @param name [String]: The ID or name of the container.
24
24
  # @param params [Hash]: Parameters that are appended to the URL.
25
25
  def details name, params = {}
26
- @connection.get(build_path("/containers/#{name}/json", params))
26
+ get("/containers/#{name}/json", params)
27
27
  end
28
28
 
29
29
  ##
@@ -35,7 +35,7 @@ class Docker::API::Container < Docker::API::Base
35
35
  # @param name [String]: The ID or name of the container.
36
36
  # @param params [Hash]: Parameters that are appended to the URL.
37
37
  def top name, params = {}
38
- @connection.get(build_path("/containers/#{name}/top", params))
38
+ get("/containers/#{name}/top", params)
39
39
  end
40
40
 
41
41
  ##
@@ -46,7 +46,7 @@ class Docker::API::Container < Docker::API::Base
46
46
  #
47
47
  # @param name [String]: The ID or name of the container.
48
48
  def changes name
49
- @connection.get(build_path("/containers/#{name}/changes"))
49
+ get("/containers/#{name}/changes")
50
50
  end
51
51
 
52
52
  ##
@@ -58,7 +58,7 @@ class Docker::API::Container < Docker::API::Base
58
58
  # @param name [String]: The ID or name of the container.
59
59
  # @param params [Hash]: Parameters that are appended to the URL.
60
60
  def start name, params = {}
61
- @connection.post(build_path("/containers/#{name}/start", params))
61
+ post("/containers/#{name}/start", params)
62
62
  end
63
63
 
64
64
  ##
@@ -70,7 +70,7 @@ class Docker::API::Container < Docker::API::Base
70
70
  # @param name [String]: The ID or name of the container.
71
71
  # @param params [Hash]: Parameters that are appended to the URL.
72
72
  def stop name, params = {}
73
- @connection.post(build_path("/containers/#{name}/stop", params))
73
+ post("/containers/#{name}/stop", params)
74
74
  end
75
75
 
76
76
  ##
@@ -82,7 +82,7 @@ class Docker::API::Container < Docker::API::Base
82
82
  # @param name [String]: The ID or name of the container.
83
83
  # @param params [Hash]: Parameters that are appended to the URL.
84
84
  def restart name, params = {}
85
- @connection.post(build_path("/containers/#{name}/restart", params))
85
+ post("/containers/#{name}/restart", params)
86
86
  end
87
87
 
88
88
  ##
@@ -94,7 +94,7 @@ class Docker::API::Container < Docker::API::Base
94
94
  # @param name [String]: The ID or name of the container.
95
95
  # @param params [Hash]: Parameters that are appended to the URL.
96
96
  def kill name, params = {}
97
- @connection.post(build_path("/containers/#{name}/kill", params))
97
+ post("/containers/#{name}/kill", params)
98
98
  end
99
99
 
100
100
  ##
@@ -106,7 +106,7 @@ class Docker::API::Container < Docker::API::Base
106
106
  # @param name [String]: The ID or name of the container.
107
107
  # @param params [Hash]: Parameters that are appended to the URL.
108
108
  def wait name, params = {}
109
- @connection.post(build_path("/containers/#{name}/wait", params))
109
+ post("/containers/#{name}/wait", params)
110
110
  end
111
111
 
112
112
  ##
@@ -118,8 +118,7 @@ class Docker::API::Container < Docker::API::Base
118
118
  # @param name [String]: The ID or name of the container.
119
119
  # @param body [Hash]: Request body to be sent as json.
120
120
  def update name, body = {}
121
-
122
- @connection.request(method: :post, path: build_path("/containers/#{name}/update"), headers: {"Content-Type": "application/json"}, body: body.to_json)
121
+ request(method: :post, path: "/containers/#{name}/update", headers: {"Content-Type": "application/json"}, body: body.to_json)
123
122
  end
124
123
 
125
124
  ##
@@ -131,7 +130,7 @@ class Docker::API::Container < Docker::API::Base
131
130
  # @param name [String]: The ID or name of the container.
132
131
  # @param params [Hash]: Parameters that are appended to the URL.
133
132
  def rename name, params = {}
134
- @connection.post(build_path("/containers/#{name}/rename", params))
133
+ post("/containers/#{name}/rename", params)
135
134
  end
136
135
 
137
136
  ##
@@ -143,7 +142,7 @@ class Docker::API::Container < Docker::API::Base
143
142
  # @param name [String]: The ID or name of the container.
144
143
  # @param params [Hash]: Parameters that are appended to the URL.
145
144
  def resize name, params = {}
146
- @connection.post(build_path("/containers/#{name}/resize", params))
145
+ post("/containers/#{name}/resize", params)
147
146
  end
148
147
 
149
148
  ##
@@ -154,7 +153,7 @@ class Docker::API::Container < Docker::API::Base
154
153
  #
155
154
  # @param params [Hash]: Parameters that are appended to the URL.
156
155
  def prune params = {}
157
- @connection.post(build_path("/containers/prune", params))
156
+ post("/containers/prune", params)
158
157
  end
159
158
 
160
159
  ##
@@ -165,7 +164,7 @@ class Docker::API::Container < Docker::API::Base
165
164
  #
166
165
  # @param name [String]: The ID or name of the container.
167
166
  def pause name
168
- @connection.post(build_path("/containers/#{name}/pause"))
167
+ post("/containers/#{name}/pause")
169
168
  end
170
169
 
171
170
  ##
@@ -176,7 +175,7 @@ class Docker::API::Container < Docker::API::Base
176
175
  #
177
176
  # @param name [String]: The ID or name of the container.
178
177
  def unpause name
179
- @connection.post(build_path("/containers/#{name}/unpause"))
178
+ post("/containers/#{name}/unpause")
180
179
  end
181
180
 
182
181
  ##
@@ -188,7 +187,7 @@ class Docker::API::Container < Docker::API::Base
188
187
  # @param name [String]: The ID or name of the container.
189
188
  # @param params [Hash]: Parameters that are appended to the URL.
190
189
  def remove name, params = {}
191
- @connection.delete(build_path("/containers/#{name}", params))
190
+ delete("/containers/#{name}", params)
192
191
  end
193
192
 
194
193
  ##
@@ -201,13 +200,12 @@ class Docker::API::Container < Docker::API::Base
201
200
  # @param params [Hash]: Parameters that are appended to the URL.
202
201
  # @param &block: Replace the default output to stdout behavior.
203
202
  def logs name, params = {}, &block
204
-
205
- path = build_path("/containers/#{name}/logs", params)
203
+ path = "/containers/#{name}/logs"
206
204
 
207
205
  if [true, 1 ].include? params[:follow]
208
- @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
206
+ request(method: :get, path: path, params: params, response_block: block_given? ? block : default_streamer)
209
207
  else
210
- @connection.get(path)
208
+ get(path, params)
211
209
  end
212
210
  end
213
211
 
@@ -221,7 +219,7 @@ class Docker::API::Container < Docker::API::Base
221
219
  # @param params [Hash]: Parameters that are appended to the URL.
222
220
  # @param &block: Replace the default output to stdout behavior.
223
221
  def attach name, params = {}, &block
224
- @connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer)
222
+ request(method: :post, path: "/containers/#{name}/attach", params: params , response_block: block_given? ? block : default_streamer)
225
223
  end
226
224
 
227
225
  ##
@@ -233,7 +231,7 @@ class Docker::API::Container < Docker::API::Base
233
231
  # @param params [Hash]: Parameters that are appended to the URL.
234
232
  # @param body [Hash]: Request body to be sent as json.
235
233
  def create params = {}, body = {}
236
- @connection.request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
234
+ request(method: :post, path: "/containers/create", params: params, headers: {"Content-Type": "application/json"}, body: body.to_json)
237
235
  end
238
236
 
239
237
  ##
@@ -246,11 +244,12 @@ class Docker::API::Container < Docker::API::Base
246
244
  # @param params [Hash]: Parameters that are appended to the URL.
247
245
  # @param &block: Replace the default output to stdout behavior.
248
246
  def stats name, params = {}, &block
249
- path = build_path("/containers/#{name}/stats", params)
247
+ path = "/containers/#{name}/stats"
248
+
250
249
  if [true, 1 ].include? params[:stream]
251
- @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
250
+ request(method: :get, path: path, params: params, response_block: block_given? ? block : default_streamer)
252
251
  else
253
- @connection.get(path)
252
+ get(path, params)
254
253
  end
255
254
  end
256
255
 
@@ -266,7 +265,7 @@ class Docker::API::Container < Docker::API::Base
266
265
  def export name, path, &block
267
266
  response = self.details(name)
268
267
  return response unless response.status == 200
269
- @connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path))
268
+ request(method: :get, path: "/containers/#{name}/export", response_block: block_given? ? block : default_writer(path))
270
269
  end
271
270
 
272
271
  ##
@@ -282,11 +281,11 @@ class Docker::API::Container < Docker::API::Base
282
281
  # @param params [Hash]: Parameters that are appended to the URL.
283
282
  # @param &block: Replace the default file writing behavior.
284
283
  def get_archive name, path, params = {}, &block
285
- response = @connection.head(build_path("/containers/#{name}/archive", params))
284
+ response = head("/containers/#{name}/archive", params)
286
285
  return response unless response.status == 200
287
286
 
288
287
  file = File.open( File.expand_path( path ) , "wb")
289
- response = @connection.request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
288
+ response = request(method: :get, path: "/containers/#{name}/archive", params: params , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
290
289
  file.close
291
290
  response
292
291
  end
@@ -304,7 +303,7 @@ class Docker::API::Container < Docker::API::Base
304
303
  # @param params [Hash]: Parameters that are appended to the URL.
305
304
  def put_archive name, path, params = {}
306
305
  file = File.open( File.expand_path( path ) , "r")
307
- response = @connection.request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
306
+ response = request(method: :put, path: "/containers/#{name}/archive", params: params , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
308
307
  file.close
309
308
  response
310
309
  end
@@ -12,7 +12,7 @@ class Docker::API::Exec < Docker::API::Base
12
12
  # @param name [String]: The ID or name of the container.
13
13
  # @param body [Hash]: Request body to be sent as json.
14
14
  def create name, body = {}
15
- @connection.request(method: :post, path: build_path("/containers/#{name}/exec"), headers: {"Content-Type": "application/json"}, body: body.to_json )
15
+ request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
16
16
  end
17
17
 
18
18
  ##
@@ -25,7 +25,7 @@ class Docker::API::Exec < Docker::API::Base
25
25
  # @param body [Hash]: Request body to be sent as json.
26
26
  # @param &block: Replace the default output to stdout behavior.
27
27
  def start name, body = {}, &block
28
- @connection.request(method: :post, path: build_path("/exec/#{name}/start"), headers: {"Content-Type": "application/json"}, body: body.to_json,
28
+ request(method: :post, path: "/exec/#{name}/start", headers: {"Content-Type": "application/json"}, body: body.to_json,
29
29
  response_block: block_given? ? block : default_streamer )
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ class Docker::API::Exec < Docker::API::Base
38
38
  # @param name [String]: Exec instance ID.
39
39
  # @param body [Hash]: Request body to be sent as json.
40
40
  def resize name, params = {}
41
- @connection.post(build_path("/exec/#{name}/resize", params))
41
+ post("/exec/#{name}/resize", params)
42
42
  end
43
43
 
44
44
  ##
@@ -49,7 +49,7 @@ class Docker::API::Exec < Docker::API::Base
49
49
  #
50
50
  # @param name [String]: Exec instance ID.
51
51
  def details name
52
- @connection.get(build_path("/exec/#{name}/json"))
52
+ get("/exec/#{name}/json")
53
53
  end
54
54
 
55
55
  end
@@ -11,7 +11,7 @@ class Docker::API::Image < Docker::API::Base
11
11
  #
12
12
  # @param name [String]: The ID or name of the image.
13
13
  def details name
14
- @connection.get(build_path("/images/#{name}/json"))
14
+ get("/images/#{name}/json")
15
15
  end
16
16
 
17
17
  ##
@@ -23,9 +23,9 @@ class Docker::API::Image < Docker::API::Base
23
23
  # @param name [String]: The ID or name of the image.
24
24
  # @param authentication [Hash]: Authentication parameters.
25
25
  def distribution name, authentication = {}
26
- request = {method: :get, path: build_path("/distribution/#{name}/json")}
26
+ request = {method: :get, path: "/distribution/#{name}/json"}
27
27
  request[:headers] = {"X-Registry-Auth" => auth_encoder(authentication)} if authentication.any?
28
- @connection.request(request)
28
+ request(request)
29
29
  end
30
30
 
31
31
  ##
@@ -36,7 +36,7 @@ class Docker::API::Image < Docker::API::Base
36
36
  #
37
37
  # @param name [String]: The ID or name of the image.
38
38
  def history name
39
- @connection.get(build_path("/images/#{name}/history"))
39
+ get("/images/#{name}/history")
40
40
  end
41
41
 
42
42
  ##
@@ -47,7 +47,7 @@ class Docker::API::Image < Docker::API::Base
47
47
  #
48
48
  # @param params [Hash]: Parameters that are appended to the URL.
49
49
  def list params = {}
50
- @connection.get(build_path("/images/json", params))
50
+ get("/images/json", params)
51
51
  end
52
52
 
53
53
  ##
@@ -58,7 +58,7 @@ class Docker::API::Image < Docker::API::Base
58
58
  #
59
59
  # @param params [Hash]: Parameters that are appended to the URL.
60
60
  def search params = {}
61
- @connection.get(build_path("/images/search", params))
61
+ get("/images/search", params)
62
62
  end
63
63
 
64
64
  ##
@@ -70,7 +70,7 @@ class Docker::API::Image < Docker::API::Base
70
70
  # @param name [String]: The ID or name of the image.
71
71
  # @param params [Hash]: Parameters that are appended to the URL.
72
72
  def tag name, params = {}
73
- @connection.post(build_path("/images/#{name}/tag", params))
73
+ post("/images/#{name}/tag", params)
74
74
  end
75
75
 
76
76
  ##
@@ -81,7 +81,7 @@ class Docker::API::Image < Docker::API::Base
81
81
  #
82
82
  # @param params [Hash]: Parameters that are appended to the URL.
83
83
  def prune params = {}
84
- @connection.post(build_path("/images/prune", params))
84
+ post("/images/prune", params)
85
85
  end
86
86
 
87
87
  ##
@@ -95,7 +95,7 @@ class Docker::API::Image < Docker::API::Base
95
95
  # @param name [String]: The ID or name of the image.
96
96
  # @param params [Hash]: Parameters that are appended to the URL.
97
97
  def remove name, params = {}
98
- @connection.delete(build_path("/images/#{name}", params))
98
+ delete("/images/#{name}", params)
99
99
  end
100
100
 
101
101
  ##
@@ -108,7 +108,7 @@ class Docker::API::Image < Docker::API::Base
108
108
  # @param path [String]: Path to the exported file.
109
109
  # @param &block: Replace the default file writing behavior.
110
110
  def export name, path, &block
111
- @connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path))
111
+ request(method: :get, path: "/images/#{name}/get" , response_block: block_given? ? block : default_writer(path))
112
112
  end
113
113
 
114
114
  ##
@@ -117,10 +117,10 @@ class Docker::API::Image < Docker::API::Base
117
117
  # Docker API: POST /images/load
118
118
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageLoad
119
119
  #
120
- # @param name [String]: The ID or name of the image.
120
+ # @param path [String]: Path to the file to be read.
121
121
  # @param params [Hash]: Parameters that are appended to the URL.
122
122
  def import path, params = {}
123
- default_reader(path, build_path("/images/load", params))
123
+ default_reader(path, "/images/load", params)
124
124
  end
125
125
 
126
126
  ##
@@ -134,7 +134,7 @@ class Docker::API::Image < Docker::API::Base
134
134
  # @param authentication [Hash]: Authentication parameters.
135
135
  def push name, params = {}, authentication = {}
136
136
  raise StandardError.new("Provide authentication parameters to push an image") unless authentication.any?
137
- @connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } )
137
+ request(method: :post, path: "/images/#{name}/push", params: params, headers: { "X-Registry-Auth" => auth_encoder(authentication) } )
138
138
  end
139
139
 
140
140
  ##
@@ -148,7 +148,7 @@ class Docker::API::Image < Docker::API::Base
148
148
  def commit params = {}, body = {}
149
149
  container = Docker::API::Container.new(@connection).details(params[:container])
150
150
  return container if [404, 301].include? container.status
151
- @connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json)
151
+ request(method: :post, path: "/commit", params: params, headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json)
152
152
  end
153
153
 
154
154
  ##
@@ -161,14 +161,14 @@ class Docker::API::Image < Docker::API::Base
161
161
  # @param authentication [Hash]: Authentication parameters.
162
162
  # @param &block: Replace the default output to stdout behavior.
163
163
  def create params = {}, authentication = {}, &block
164
- request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block : default_streamer }
164
+ request = {method: :post, path: "/images/create", params: params, response_block: block_given? ? block : default_streamer }
165
165
  if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file
166
166
  path = params[:fromSrc]
167
167
  params[:fromSrc] = "-"
168
- default_reader(path, build_path("/images/create", params))
168
+ default_reader(path, "/images/create", params)
169
169
  else
170
170
  request[:headers] = { "X-Registry-Auth" => auth_encoder(authentication) } if authentication.any?
171
- @connection.request(request)
171
+ request(request)
172
172
  end
173
173
  end
174
174
 
@@ -189,9 +189,9 @@ class Docker::API::Image < Docker::API::Base
189
189
  headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.any?
190
190
 
191
191
  if path == nil and params.has_key? :remote
192
- response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer)
192
+ response = request(method: :post, path: "/build", params: params, headers: headers, response_block: block_given? ? block : default_streamer)
193
193
  else
194
- default_reader(path, build_path("/build", params), headers)
194
+ default_reader(path, "/build", params, headers)
195
195
  end
196
196
  end
197
197
 
@@ -203,6 +203,6 @@ class Docker::API::Image < Docker::API::Base
203
203
  #
204
204
  # @param params [Hash]: Parameters that are appended to the URL.
205
205
  def delete_cache params = {}
206
- @connection.post(build_path("/build/prune", params))
206
+ post("/build/prune", params)
207
207
  end
208
208
  end
@@ -11,7 +11,7 @@ class Docker::API::Network < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/networks", params))
14
+ get("/networks", params)
15
15
  end
16
16
 
17
17
  ##
@@ -23,7 +23,7 @@ class Docker::API::Network < Docker::API::Base
23
23
  # @param name [String]: The ID or name of the network.
24
24
  # @param params [Hash]: Parameters that are appended to the URL.
25
25
  def details name, params = {}
26
- @connection.get(build_path("/networks/#{name}", params))
26
+ get("/networks/#{name}", params)
27
27
  end
28
28
 
29
29
  ##
@@ -34,7 +34,7 @@ class Docker::API::Network < Docker::API::Base
34
34
  #
35
35
  # @param body [Hash]: Request body to be sent as json.
36
36
  def create body = {}
37
- @connection.request(method: :post, path: build_path("/networks/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
37
+ request(method: :post, path: "/networks/create", headers: {"Content-Type" => "application/json"}, body: body.to_json)
38
38
  end
39
39
 
40
40
  ##
@@ -45,7 +45,7 @@ class Docker::API::Network < Docker::API::Base
45
45
  #
46
46
  # @param name [String]: The ID or name of the network.
47
47
  def remove name
48
- @connection.delete(build_path("/networks/#{name}"))
48
+ delete("/networks/#{name}")
49
49
  end
50
50
 
51
51
  ##
@@ -56,7 +56,7 @@ class Docker::API::Network < Docker::API::Base
56
56
  #
57
57
  # @param params [Hash]: Parameters that are appended to the URL.
58
58
  def prune params = {}
59
- @connection.post(build_path("/networks/prune", params))
59
+ post("/networks/prune", params)
60
60
  end
61
61
 
62
62
  ##
@@ -68,7 +68,7 @@ class Docker::API::Network < Docker::API::Base
68
68
  # @param name [String]: The ID or name of the network.
69
69
  # @param body [Hash]: Request body to be sent as json.
70
70
  def connect name, body = {}
71
- @connection.request(method: :post, path: build_path("/networks/#{name}/connect"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
71
+ request(method: :post, path: "/networks/#{name}/connect", headers: {"Content-Type" => "application/json"}, body: body.to_json)
72
72
  end
73
73
 
74
74
  ##
@@ -80,7 +80,7 @@ class Docker::API::Network < Docker::API::Base
80
80
  # @param name [String]: The ID or name of the network.
81
81
  # @param body [Hash]: Request body to be sent as json.
82
82
  def disconnect name, body = {}
83
- @connection.request(method: :post, path: build_path("/networks/#{name}/disconnect"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
83
+ request(method: :post, path: "/networks/#{name}/disconnect", headers: {"Content-Type" => "application/json"}, body: body.to_json)
84
84
  end
85
85
 
86
86
  end
@@ -12,7 +12,7 @@ class Docker::API::Node < Docker::API::Base
12
12
  #
13
13
  # @param params [Hash]: Parameters that are appended to the URL.
14
14
  def list params = {}
15
- @connection.get(build_path("/nodes", params))
15
+ get("/nodes", params)
16
16
  end
17
17
 
18
18
  ##
@@ -25,7 +25,7 @@ class Docker::API::Node < Docker::API::Base
25
25
  # @param params [Hash]: Parameters that are appended to the URL.
26
26
  # @param body [Hash]: Request body to be sent as json.
27
27
  def update name, params = {}, body = {}
28
- @connection.request(method: :post, path: build_path("/nodes/#{name}/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json)
28
+ request(method: :post, path: "/nodes/#{name}/update", params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json)
29
29
  end
30
30
 
31
31
  ##
@@ -37,7 +37,7 @@ class Docker::API::Node < Docker::API::Base
37
37
  # @param name [String]: The ID or name of the node.
38
38
  # @param params [Hash]: Parameters that are appended to the URL.
39
39
  def remove name, params = {}
40
- @connection.delete(build_path("/nodes/#{name}", params))
40
+ delete("/nodes/#{name}", params)
41
41
  end
42
42
 
43
43
  ##
@@ -48,6 +48,6 @@ class Docker::API::Node < Docker::API::Base
48
48
  #
49
49
  # @param name [String]: The ID or name of the node.
50
50
  def details name
51
- @connection.get(build_path("/nodes/#{name}"))
51
+ get("/nodes/#{name}")
52
52
  end
53
53
  end
@@ -11,7 +11,7 @@ class Docker::API::Plugin < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/plugins", params))
14
+ get("/plugins", params)
15
15
  end
16
16
 
17
17
  # Get plugin privileges
@@ -22,7 +22,7 @@ class Docker::API::Plugin < Docker::API::Base
22
22
  #
23
23
  # @param params [Hash]: Parameters that are appended to the URL.
24
24
  def privileges params = {}
25
- @connection.get(build_path("/plugins/privileges", params))
25
+ get("/plugins/privileges", params)
26
26
  end
27
27
 
28
28
  # Install a plugin
@@ -41,7 +41,7 @@ class Docker::API::Plugin < Docker::API::Base
41
41
  def install params = {}, privileges = [], authentication = {}
42
42
  headers = {"Content-Type" => "application/json"}
43
43
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
44
- @connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json )
44
+ request(method: :post, path: "/plugins/pull", params: params, headers: headers, body: privileges.to_json )
45
45
  end
46
46
 
47
47
  # Inspect a plugin
@@ -52,7 +52,7 @@ class Docker::API::Plugin < Docker::API::Base
52
52
  #
53
53
  # @param name [String]: The ID or name of the plugin.
54
54
  def details name
55
- @connection.get(build_path("/plugins/#{name}/json"))
55
+ get("/plugins/#{name}/json")
56
56
  end
57
57
 
58
58
  # Remove a plugin
@@ -65,7 +65,7 @@ class Docker::API::Plugin < Docker::API::Base
65
65
  #
66
66
  # @param params [Hash]: Parameters that are appended to the URL.
67
67
  def remove name, params = {}
68
- @connection.delete(build_path("/plugins/#{name}",params))
68
+ delete("/plugins/#{name}",params)
69
69
  end
70
70
 
71
71
  # Enable a plugin
@@ -78,7 +78,7 @@ class Docker::API::Plugin < Docker::API::Base
78
78
  #
79
79
  # @param params [Hash]: Parameters that are appended to the URL.
80
80
  def enable name, params = {}
81
- @connection.post(build_path("/plugins/#{name}/enable", params))
81
+ post("/plugins/#{name}/enable", params)
82
82
  end
83
83
 
84
84
  # Disable a plugin
@@ -89,7 +89,7 @@ class Docker::API::Plugin < Docker::API::Base
89
89
  #
90
90
  # @param name [String]: The ID or name of the plugin.
91
91
  def disable name
92
- @connection.post(build_path("/plugins/#{name}/disable"))
92
+ post("/plugins/#{name}/disable")
93
93
  end
94
94
 
95
95
  # Upgrade a plugin
@@ -108,7 +108,7 @@ class Docker::API::Plugin < Docker::API::Base
108
108
  def upgrade name, params = {}, privileges = [], authentication = {}
109
109
  headers = {"Content-Type" => "application/json"}
110
110
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
111
- @connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json )
111
+ request(method: :post, path: "/plugins/#{name}/upgrade", params: params, headers: headers, body: privileges.to_json )
112
112
  end
113
113
 
114
114
  # Create a plugin
@@ -122,7 +122,7 @@ class Docker::API::Plugin < Docker::API::Base
122
122
  # @param path [String]: Path to tar file that contains rootfs folder and config.json file.
123
123
  def create name, path
124
124
  file = File.open( File.expand_path( path ) , "r")
125
- response = @connection.request(method: :post, path: build_path("/plugins/create?name=#{name}"), body: file.read.to_s )
125
+ response = request(method: :post, path: "/plugins/create?name=#{name}", body: file.read.to_s )
126
126
  file.close
127
127
  response
128
128
  end
@@ -138,9 +138,9 @@ class Docker::API::Plugin < Docker::API::Base
138
138
  # @param authentication [Hash]: Authentication parameters.
139
139
  def push name, authentication = {}
140
140
  if authentication.keys.size > 0
141
- @connection.request(method: :post, path: build_path("/plugins/#{name}/push"), headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)})
141
+ request(method: :post, path: "/plugins/#{name}/push", headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)})
142
142
  else
143
- @connection.post(build_path("/plugins/#{name}/push"))
143
+ post("/plugins/#{name}/push")
144
144
  end
145
145
  end
146
146
 
@@ -154,7 +154,7 @@ class Docker::API::Plugin < Docker::API::Base
154
154
  #
155
155
  # @param config [Array]: Plugin configuration to be sent as json in request body.
156
156
  def configure name, config
157
- @connection.request(method: :post, path: build_path("/plugins/#{name}/set"), headers: {"Content-Type" => "application/json"}, body:config.to_json)
157
+ request(method: :post, path: "/plugins/#{name}/set", headers: {"Content-Type" => "application/json"}, body:config.to_json)
158
158
  end
159
159
 
160
160
  end
@@ -11,7 +11,7 @@ class Docker::API::Secret < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/secrets",params))
14
+ get("/secrets",params)
15
15
  end
16
16
 
17
17
  # Create a secret
@@ -21,7 +21,7 @@ class Docker::API::Secret < Docker::API::Base
21
21
  #
22
22
  # @param body [Hash]: Request body to be sent as json.
23
23
  def create body = {}
24
- @connection.request(method: :post, path: build_path("/secrets/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
24
+ request(method: :post, path: "/secrets/create", headers: {"Content-Type" => "application/json"}, body: body.to_json)
25
25
  end
26
26
 
27
27
  # Inspect a secret
@@ -31,7 +31,7 @@ class Docker::API::Secret < Docker::API::Base
31
31
  #
32
32
  # @param name [String]: The ID or name of the secret.
33
33
  def details name
34
- @connection.get(build_path("/secrets/#{name}"))
34
+ get("/secrets/#{name}")
35
35
  end
36
36
 
37
37
  # Update a secret
@@ -43,7 +43,7 @@ class Docker::API::Secret < Docker::API::Base
43
43
  # @param params [Hash]: Parameters that are appended to the URL.
44
44
  # @param body [Hash]: Request body to be sent as json.
45
45
  def update name, params = {}, body = {}
46
- @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type" => "application/json"}, body: body.to_json)
46
+ request(method: :post, path: "/secrets/#{name}/update",params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json)
47
47
  end
48
48
 
49
49
  # Delete a secret
@@ -53,6 +53,6 @@ class Docker::API::Secret < Docker::API::Base
53
53
  #
54
54
  # @param name [String]: The ID or name of the secret.
55
55
  def remove name
56
- @connection.delete(build_path("/secrets/#{name}"))
56
+ delete("/secrets/#{name}")
57
57
  end
58
58
  end
@@ -11,7 +11,7 @@ class Docker::API::Service < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/services", params))
14
+ get("/services", params)
15
15
  end
16
16
 
17
17
  # Create a service
@@ -24,7 +24,7 @@ class Docker::API::Service < Docker::API::Base
24
24
  def create body = {}, authentication = {}
25
25
  headers = {"Content-Type" => "application/json"}
26
26
  headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
27
- @connection.request(method: :post, path: build_path("/services/create"), headers: headers, body: body.to_json)
27
+ request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
28
28
  end
29
29
 
30
30
  # Update a service
@@ -40,7 +40,7 @@ class Docker::API::Service < Docker::API::Base
40
40
  # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
41
41
  headers = {"Content-Type" => "application/json"}
42
42
  headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
43
- @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
43
+ request(method: :post, path: "/services/#{name}/update", params: params, headers: headers, body: body.to_json)
44
44
  end
45
45
 
46
46
  # Inspect a service
@@ -51,7 +51,7 @@ class Docker::API::Service < Docker::API::Base
51
51
  # @param name [String]: The ID or name of the service.
52
52
  # @param params [Hash]: Parameters that are appended to the URL.
53
53
  def details name, params = {}
54
- @connection.get(build_path("/services/#{name}", params))
54
+ get("/services/#{name}", params)
55
55
  end
56
56
 
57
57
  # Get stdout and stderr logs from a service.
@@ -62,7 +62,7 @@ class Docker::API::Service < Docker::API::Base
62
62
  # @param name [String]: The ID or name of the service.
63
63
  # @param params [Hash]: Parameters that are appended to the URL.
64
64
  def logs name, params = {}
65
- @connection.get(build_path("/services/#{name}/logs", params))
65
+ get("/services/#{name}/logs", params)
66
66
  end
67
67
 
68
68
  # Delete a service
@@ -72,6 +72,6 @@ class Docker::API::Service < Docker::API::Base
72
72
  #
73
73
  # @param name [String]: The ID or name of the service.
74
74
  def remove name
75
- @connection.delete(build_path("/services/#{name}"))
75
+ delete("/services/#{name}")
76
76
  end
77
77
  end
@@ -11,7 +11,7 @@ class Docker::API::Swarm < Docker::API::Base
11
11
  #
12
12
  # @param body [Hash]: Request body to be sent as json.
13
13
  def init body = {}
14
- @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
14
+ request(method: :post, path: "/swarm/init", headers: {"Content-Type" => "application/json"}, body: body.to_json)
15
15
  end
16
16
 
17
17
  ##
@@ -23,7 +23,7 @@ class Docker::API::Swarm < Docker::API::Base
23
23
  # @param params [Hash]: Parameters that are appended to the URL.
24
24
  # @param body [Hash]: Request body to be sent as json.
25
25
  def update params = {}, body = {}
26
- @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json)
26
+ request(method: :post, path: "/swarm/update", params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json)
27
27
  end
28
28
 
29
29
  ##
@@ -32,7 +32,7 @@ class Docker::API::Swarm < Docker::API::Base
32
32
  # Docker API: GET /swarm
33
33
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect
34
34
  def details
35
- @connection.get(build_path("/swarm"))
35
+ get("/swarm")
36
36
  end
37
37
 
38
38
  ##
@@ -41,7 +41,7 @@ class Docker::API::Swarm < Docker::API::Base
41
41
  # Docker API: GET /swarm/unlockkey
42
42
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey
43
43
  def unlock_key
44
- @connection.get(build_path("/swarm/unlockkey"))
44
+ get("/swarm/unlockkey")
45
45
  end
46
46
 
47
47
  ##
@@ -52,7 +52,7 @@ class Docker::API::Swarm < Docker::API::Base
52
52
  #
53
53
  # @param body [Hash]: Request body to be sent as json.
54
54
  def unlock body = {}
55
- @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
55
+ request(method: :post, path: "/swarm/unlock", headers: {"Content-Type" => "application/json"}, body: body.to_json)
56
56
  end
57
57
 
58
58
  ##
@@ -63,7 +63,7 @@ class Docker::API::Swarm < Docker::API::Base
63
63
  #
64
64
  # @param body [Hash]: Request body to be sent as json.
65
65
  def join body = {}
66
- @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
66
+ request(method: :post, path: "/swarm/join", headers: {"Content-Type" => "application/json"}, body: body.to_json)
67
67
  end
68
68
 
69
69
  ##
@@ -74,6 +74,6 @@ class Docker::API::Swarm < Docker::API::Base
74
74
  #
75
75
  # @param params [Hash]: Parameters that are appended to the URL.
76
76
  def leave params = {}
77
- @connection.post(build_path("/swarm/leave", params))
77
+ post("/swarm/leave", params)
78
78
  end
79
79
  end
@@ -11,7 +11,7 @@ class Docker::API::System < Docker::API::Base
11
11
  #
12
12
  # @param body [Hash]: Request body to be sent as json.
13
13
  def auth body = {}
14
- @connection.request(method: :post, path: build_path("/auth"), headers: { "Content-Type" => "application/json" }, body: body.to_json)
14
+ request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
15
15
  end
16
16
 
17
17
  ##
@@ -23,7 +23,7 @@ class Docker::API::System < Docker::API::Base
23
23
  # @param params [Hash]: Parameters that are appended to the URL.
24
24
  # @param &block: Replace the default output to stdout behavior.
25
25
  def events params = {}, &block
26
- @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer )
26
+ request(method: :get, path: "/events", params: params, response_block: block_given? ? block : default_streamer )
27
27
  end
28
28
 
29
29
  ##
@@ -32,7 +32,7 @@ class Docker::API::System < Docker::API::Base
32
32
  # Docker API: GET /_ping
33
33
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing
34
34
  def ping
35
- @connection.get(build_path("/_ping"))
35
+ get("/_ping")
36
36
  end
37
37
 
38
38
  ##
@@ -41,7 +41,7 @@ class Docker::API::System < Docker::API::Base
41
41
  # Docker API: GET /info
42
42
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo
43
43
  def info
44
- @connection.get(build_path("/info"))
44
+ get("/info")
45
45
  end
46
46
 
47
47
  ##
@@ -50,7 +50,7 @@ class Docker::API::System < Docker::API::Base
50
50
  # Docker API: GET /version
51
51
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion
52
52
  def version
53
- @connection.get(build_path("/version"))
53
+ get("/version")
54
54
  end
55
55
 
56
56
  ##
@@ -59,7 +59,7 @@ class Docker::API::System < Docker::API::Base
59
59
  # Docker API: GET /system/df
60
60
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage
61
61
  def df params = {}
62
- @connection.get(build_path("/system/df", params))
62
+ get("/system/df", params)
63
63
  end
64
64
 
65
65
  end
@@ -11,7 +11,7 @@ class Docker::API::Task < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/tasks",params))
14
+ get("/tasks",params)
15
15
  end
16
16
 
17
17
  # Inspect a task
@@ -21,7 +21,7 @@ class Docker::API::Task < Docker::API::Base
21
21
  #
22
22
  # @param name [String]: The ID or name of the task.
23
23
  def details name
24
- @connection.get(build_path("/tasks/#{name}"))
24
+ get("/tasks/#{name}")
25
25
  end
26
26
 
27
27
  # Get stdout and stderr logs from a task.
@@ -33,12 +33,12 @@ class Docker::API::Task < Docker::API::Base
33
33
  # @param params (Hash) : Parameters that are appended to the URL.
34
34
  # @param &block: Replace the default output to stdout behavior.
35
35
  def logs name, params = {}, &block
36
- path = build_path("/tasks/#{name}/logs", params)
36
+ path = "/tasks/#{name}/logs"
37
37
 
38
38
  if [true, 1 ].include? params[:follow]
39
- @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
39
+ request(method: :get, path: path , params: params, response_block: block_given? ? block : default_streamer)
40
40
  else
41
- @connection.get(path)
41
+ get(path, params)
42
42
  end
43
43
  end
44
44
  end
@@ -1,9 +1,5 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.22.0"
4
-
5
- API_VERSION = "1.43"
6
-
7
- VERSION = "Gem: #{Docker::API::GEM_VERSION} | API: #{Docker::API::API_VERSION}"
3
+ VERSION = "1.0.0"
8
4
  end
9
5
  end
@@ -11,7 +11,7 @@ class Docker::API::Volume < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- @connection.get(build_path("/volumes", params))
14
+ get("/volumes", params)
15
15
  end
16
16
 
17
17
  ##
@@ -22,7 +22,7 @@ class Docker::API::Volume < Docker::API::Base
22
22
  #
23
23
  # @param name [String]: The ID or name of the volume.
24
24
  def details name
25
- @connection.get(build_path("/volumes/#{name}"))
25
+ get("/volumes/#{name}")
26
26
  end
27
27
 
28
28
  ##
@@ -33,7 +33,7 @@ class Docker::API::Volume < Docker::API::Base
33
33
  #
34
34
  # @param body [Hash]: Request body to be sent as json.
35
35
  def create body = {}
36
- @connection.request(method: :post, path: build_path("/volumes/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json)
36
+ request(method: :post, path: "/volumes/create", headers: {"Content-Type" => "application/json"}, body: body.to_json)
37
37
  end
38
38
 
39
39
  ##
@@ -45,7 +45,7 @@ class Docker::API::Volume < Docker::API::Base
45
45
  # @param name [String]: The ID or name of the volume.
46
46
  # @param params [Hash]: Parameters that are appended to the URL.
47
47
  def remove name, params = {}
48
- @connection.delete(build_path("/volumes/#{name}",params))
48
+ delete("/volumes/#{name}",params)
49
49
  end
50
50
 
51
51
  ##
@@ -56,6 +56,6 @@ class Docker::API::Volume < Docker::API::Base
56
56
  #
57
57
  # @param params [Hash]: Parameters that are appended to the URL.
58
58
  def prune params = {}
59
- @connection.post(build_path("/volumes/prune", params))
59
+ post("/volumes/prune", params)
60
60
  end
61
61
  end
data/lib/dockerapi.rb CHANGED
@@ -43,6 +43,16 @@ module Docker
43
43
  @@print_response_to_stdout = bool
44
44
  end
45
45
  self.print_response_to_stdout = false
46
+
47
+ ##
48
+ # This variable controls the default Docker API version.
49
+ def self.default_api_version
50
+ @@default_api_version
51
+ end
52
+ def self.default_api_version=(s)
53
+ @@default_api_version = s
54
+ end
55
+ self.default_api_version = "1.43"
46
56
 
47
57
  end
48
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alysson A. Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-25 00:00:00.000000000 Z
11
+ date: 2025-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64