Class: Visor::Image::Meta
- Inherits:
-
Object
- Object
- Visor::Image::Meta
- Includes:
- Common::Exception
- Defined in:
- lib/image/meta.rb
Overview
The API for the VISoR Meta Server. This class supports all image metadata manipulation operations.
This is the entry-point for the VISoR Image Server to communicate with the VISoR Meta Server, here are processed and logged all the calls to the meta server coming from it.
Constant Summary collapse
- DEFAULT_HOST =
'0.0.0.0'
- DEFAULT_PORT =
4567
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
-
#delete_image(id) ⇒ Hash
Removes an image record based on its _id and returns its metadata.
-
#get_image(id) ⇒ Hash
Retrieves detailed image metadata of the image with the given id.
-
#get_images(query = {}, owner = nil) ⇒ Array
Retrieves brief metadata of all public images.
-
#get_images_detail(query = {}, owner = nil) ⇒ Array
Retrieves detailed metadata of all public images.
-
#initialize(opts = {}) ⇒ Meta
constructor
Initializes a new new VISoR Meta Image.
-
#post_image(meta) ⇒ Hash
Register a new image on the server with the given metadata and returns its metadata.
-
#put_image(id, meta) ⇒ Hash
Updates an image record with the given metadata and returns its metadata.
Constructor Details
#initialize(opts = {}) ⇒ Meta
Initializes a new new VISoR Meta Image.
27 28 29 30 31 |
# File 'lib/image/meta.rb', line 27 def initialize(opts = {}) @host = opts[:host] || DEFAULT_HOST @port = opts[:port] || DEFAULT_PORT @ssl = opts[:ssl] || false end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
19 20 21 |
# File 'lib/image/meta.rb', line 19 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
19 20 21 |
# File 'lib/image/meta.rb', line 19 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
19 20 21 |
# File 'lib/image/meta.rb', line 19 def ssl @ssl end |
Instance Method Details
#delete_image(id) ⇒ Hash
Removes an image record based on its _id and returns its metadata.
142 143 144 145 |
# File 'lib/image/meta.rb', line 142 def delete_image(id) http = request.delete path: "/images/#{id}", head: delete_headers return_response(http) end |
#get_image(id) ⇒ Hash
Retrieves detailed image metadata of the image with the given id.
99 100 101 102 |
# File 'lib/image/meta.rb', line 99 def get_image(id) http = request.get path: "/images/#{id}", head: get_headers return_response(http) end |
#get_images(query = {}, owner = nil) ⇒ Array
Retrieves brief metadata of all public images. Options for filtering the returned results can be passed in.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/image/meta.rb', line 46 def get_images(query = {}, owner=nil) http = request.get path: '/images', query: query.merge({access: 'public'}), head: get_headers pub = return_response(http) priv = [] if owner http = request.get path: '/images', query: query.merge({access: 'private', owner: owner}), head: get_headers begin priv = return_response(http) rescue => e nil end end pub + priv end |
#get_images_detail(query = {}, owner = nil) ⇒ Array
Retrieves detailed metadata of all public images.
Filtering and querying works the same as with #get_images. The only difference is the number of disclosed attributes.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/image/meta.rb', line 76 def get_images_detail(query = {}, owner=nil) http = request.get path: '/images/detail', query: query, head: get_headers pub = return_response(http) priv = [] if owner http = request.get path: '/images/detail', query: query.merge({access: 'private', owner: owner}), head: get_headers begin priv = return_response(http) rescue => e nil end end pub + priv end |
#post_image(meta) ⇒ Hash
Register a new image on the server with the given metadata and returns its metadata.
112 113 114 115 116 |
# File 'lib/image/meta.rb', line 112 def post_image() body = prepare_body() http = request.post path: '/images', body: body, head: post_headers return_response(http) end |
#put_image(id, meta) ⇒ Hash
Updates an image record with the given metadata and returns its metadata.
128 129 130 131 132 |
# File 'lib/image/meta.rb', line 128 def put_image(id, ) body = prepare_body() http = request.put path: "/images/#{id}", body: body, head: put_headers return_response(http) end |