module Hyperb::Images

images api wrapper

Public Instance Methods

create_image(params = {}) click to toggle source

create (pull) an image

@see docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Image/create.html

@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid. @raise [Hyperb::Error::InternalServerError] server error on hyper side. @raise [ArgumentError] when required arguments are not provided.

@return [HTTP::Response::Body] a streamable response object.

@param params [Hash] A customizable set of params.

@required @option params [String] :from_image image name to be pulled @option params [String] :tag image tag name

@option params [Hash] :x_registry_auth object containing either login information. @option params x_registry_auth [String] :username @option params x_registry_auth [String] :email @option params x_registry_auth [String] :password

# File lib/hyperb/images/images.rb, line 52
def create_image(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'from_image')
  path = '/images/create'
  query = { fromImage: params[:from_image] }
  query[:tag] = params[:tag] if params.key?(:tag)
  additional_headers = {}
  if params.key?(:x_registry_auth)
    auth = params[:x_registry_auth]
    additional_headers[:x_registry_auth] = Hyperb::AuthObject.new(auth).encode
  end
  res = Hyperb::Request.new(self, path, query, 'post', '', additional_headers).perform
  res
end
images(params = {}) click to toggle source

list images

@see docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Image/list.html

@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.

@return [Hyperb::Image] Array of Images.

@param params [Hash] A customizable set of params. @option params [String] :all default is true @option params [String] :filter only return image with the specified name

# File lib/hyperb/images/images.rb, line 24
def images(params = {})
  path = '/images/json'
  query = {}
  query[:all] = params[:all] || true
  query[:filter] = params[:filter] if params.key?(:filter)
  response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform)
  response.map { |image| Hyperb::Image.new(image) }
end
inspect_image(params = {}) click to toggle source

inspect an image

@see docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Image/inspect.html

@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid. @raise [Hyperb::Error::NotFound] raised when tag is not found. @raise [Hyperb::Error::InternalServerError] server error on hyper side.

@return [Hash] downcased symbolized `inspect` json response.

@param params [Hash] A customizable set of params. @option params [String] :name image name to be removed

# File lib/hyperb/images/images.rb, line 101
def inspect_image(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
  path = '/images/' + params[:name] + '/json'
  res = JSON.parse(Hyperb::Request.new(self, path, {}, 'get').perform)
  downcase_symbolize(res)
end
remove_image(params = {}) click to toggle source

remove an image

@see docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Image/remove.html

@raise [Hyperb::Error::Unauthorized] raised when credentials are not valid. @raise [Hyperb::Error::NotFound] raised when tag is not found. @raise [Hyperb::Error::Conflict] raised when the image will only be removed with force. @raise [Hyperb::Error::InternalServerError] server error.

@return [Array] array of downcase symbolized json response.

@param params [Hash] A customizable set of params. @option params [String] :name image name to be removed @option params [Boolean] :force force image to be removed

# File lib/hyperb/images/images.rb, line 80
def remove_image(params = {})
  raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
  path = '/images/' + params[:name]
  query = {}
  query[:force] = true if params.key?(:force)
  res = JSON.parse(Hyperb::Request.new(self, path, query, 'delete').perform)
  downcase_symbolize(res)
end