Class: Docker::API::Base

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

Overview

Base class to provide general methods, helpers and implementations accross classes.

Direct Known Subclasses

Config, Container, Exec, Image, Network, Node, Plugin, Secret, Service, Swarm, System, Task, Volume

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ Base

Create new object and sets the validation to happen automatically when method parameters include “params” or “body”.

Parameters:

Raises:

  • (StandardError)


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

def initialize connection = nil
    raise StandardError.new("Expected connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
    @connection = connection || Docker::API::Connection.new
    @api_version = Docker::API.default_api_version
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



4
5
6
# File 'lib/docker/api/base.rb', line 4

def api_version
  @api_version
end

Instance Method Details

#request(params) ⇒ Object

Call an Excon request and returns a Docker::API::Response object.

Parameters:

  • params (Hash)

    : Request parameters.



14
15
16
17
18
19
20
# File 'lib/docker/api/base.rb', line 14

def request params
    params[:path] = build_path(params[:path], params[:params] ||= {})
    response = Docker::API::Response.new(@connection.excon.request(params).data)
    response.request_params = params
    p response if Docker::API.print_response_to_stdout 
    response
end