Sha256: 83a51cd55b7470728e2bc32d1ab4bd5a4a2315431145a7fc64bd7941c6223d38

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 KB

Contents

module Yao::Resources
  module MetadataAvailable
    # @param id [String]
    # @return [Hash]
    def list_metadata(id)
      GET(metadata_path(id)).body["metadata"]
    end

    # @param id [String]
    # @param metadata [Hash]
    # @return [Hash]
    def create_metadata(id, metadata)
      res = POST(metadata_path(id)) do |req|
        req.body = {"metadata" => metadata}.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      res.body["metadata"]
    end
    alias append_metadata create_metadata

    # @param id [String]
    # @param metadata [Hash]
    # @return [Hash]
    def update_metadata(id, metadata)
      res = PUT(metadata_path(id)) do |req|
        req.body = {"metadata" => metadata}.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      res.body["metadata"]
    end
    alias replace_metadata update_metadata

    # @param id [String]
    # @param key [String]
    # @return [Hash]
    def get_metadata(id, key)
      GET(metadata_key_path(id, key)).body["meta"]
    end

    # @param id [String]
    # @param key [String]
    # @param value [String]
    # @return [Hash]
    def set_metadata(id, key, value)
      res = PUT(metadata_key_path(id, key)) do |req|
        req.body = {"meta" => {key => value}}.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      res.body["meta"]
    end

    # @param id [String]
    # @param key [String]
    def delete_metadata(id, key)
      DELETE(metadata_key_path(id, key)).body
    end

    private
    # @param id [String]
    # @return [String]
    def metadata_path(id)
      ["servers", id, "metadata"].join("/")
    end

    # @param id [String]
    # @param key [String]
    def metadata_key_path(id, key)
      ["servers", id, "metadata", key].join("/")
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yao-0.21.0 lib/yao/resources/metadata_available.rb
yao-0.20.0 lib/yao/resources/metadata_available.rb
yao-0.19.0 lib/yao/resources/metadata_available.rb
yao-0.18.0 lib/yao/resources/metadata_available.rb
yao-0.17.0 lib/yao/resources/metadata_available.rb
yao-0.16.0 lib/yao/resources/metadata_available.rb
yao-0.15.0 lib/yao/resources/metadata_available.rb
yao-0.14.0 lib/yao/resources/metadata_available.rb