Class: Visor::Image::Meta

Inherits:
Object
  • Object
show all
Includes:
Common::Exception
Defined in:
lib/image/meta.rb

Overview

The API for the VISOR Meta System (VMS) server. This class supports all image metadata manipulation operations.

This is the API used by the VISOR Image System (VIS) to communicate with the VMS in order to accomplish metadata retrieving and registering operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Meta

Initializes a new new VMS interface.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :host (String)

    The host address where VMS server resides.

  • :port (String)

    The host port where VMS server listens.



23
24
25
26
# File 'lib/image/meta.rb', line 23

def initialize(opts = {})
  @host = opts[:host]
  @port = opts[:port]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/image/meta.rb', line 16

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/image/meta.rb', line 16

def port
  @port
end

Instance Method Details

#delete_image(id) ⇒ Hash

Removes an image record based on its _id and returns its metadata.

Parameters:

  • id (String)

    The image’s _id which will be deleted.

Returns:

  • (Hash)

    The already deleted detailed image metadata. This is useful for recovery on accidental delete.

Raises:

  • (NotFound)

    If the target image metadata was not found.



119
120
121
122
# File 'lib/image/meta.rb', line 119

def delete_image(id)
  http = request.delete path: "/images/#{id}", head: delete_headers
  return_response(http)
end

#get_image(id) ⇒ Hash

Retrieves detailed metadata of the image with the given id.

Parameters:

  • id (String)

    The wanted image’s _id.

Returns:

  • (Hash)

    The requested image detailed metadata.

Raises:

  • (NotFound)

    If image metadata was not found.



76
77
78
79
# File 'lib/image/meta.rb', line 76

def get_image(id)
  http = request.get path: "/images/#{id}", head: get_headers
  return_response(http)
end

#get_images(query = {}, owner = nil) ⇒ Array

Retrieves all public and user’s private images brief metadata. Options for filtering the returned results can be passed in.

Parameters:

  • owner (nil) (defaults to: nil)
    String

    The user’s access key to look for its private images too.

  • query (Hash) (defaults to: {})

    a customizable set of options

Options Hash (query):

  • : (String)

    The image attribute value to filter returned results.

  • :sort (String) — default: "_id"

    The image attribute to sort returned results.

  • :dir (String) — default: "asc"

    The direction to sort results (“asc”/“desc”).

Returns:

  • (Array)

    All images brief metadata. Just BRIEF attributes are returned.

Raises:

  • (NotFound)

    If there are no images registered on VMS.



41
42
43
44
45
# File 'lib/image/meta.rb', line 41

def get_images(query = {}, owner=nil)
  query.merge!(owner: owner) if owner
  http = request.get path: '/images', query: query, head: get_headers
  return_response(http)
end

#get_images_detail(query = {}, owner = nil) ⇒ Array

Retrieves all public and user’s private images detailed metadata.

Filtering and querying works the same as with #get_images. The only difference is the number of disclosed attributes.

Parameters:

  • owner (nil) (defaults to: nil)
    String

    The user’s access_key to look for its private images too.

  • query (Hash) (defaults to: {})

    a customizable set of options

Options Hash (query):

  • :attribute_name (String)

    The image attribute value to filter returned results.

  • :sort (String) — default: "_id"

    The image attribute to sort returned results.

  • :dir (String) — default: "asc"

    The direction to sort results (“asc”/“desc”).

Returns:

  • (Array)

    All public images detailed metadata. The DETAIL_EXC fields are excluded from results.

Raises:

  • (NotFound)

    If there are no images registered on the server.



62
63
64
65
66
# File 'lib/image/meta.rb', line 62

def get_images_detail(query = {}, owner=nil)
  query.merge!(owner: owner) if owner
  http = request.get path: '/images/detail', query: query, head: get_headers
  return_response(http)
end

#post_image(meta, address) ⇒ Hash

Register a new image metadata on VMS and return it.

Parameters:

  • meta (Hash)

    The image metadata.

Returns:

  • (Hash)

    The already inserted detailed image metadata.

Raises:

  • (Invalid)

    If image metadata validation fails.



89
90
91
92
93
# File 'lib/image/meta.rb', line 89

def post_image(meta, address)
  body = prepare_body(meta)
  http = request.post path: '/images', body: body, head: post_headers(address)
  return_response(http)
end

#put_image(id, meta) ⇒ Hash

Updates an image metadata with the given metadata and returns it.

Parameters:

  • id (String)

    The image’s _id which will be updated.

  • meta (Hash)

    The image metadata.

Returns:

  • (Hash)

    The already updated detailed image metadata.

Raises:

  • (Invalid)

    If image meta validation fails.

  • (NotFound)

    If the target image metadata was not found.



105
106
107
108
109
# File 'lib/image/meta.rb', line 105

def put_image(id, meta)
  body = prepare_body(meta)
  http = request.put path: "/images/#{id}", body: body, head: put_headers
  return_response(http)
end