Sha256: f21c76d17cfe946cc91f33b540e1637576570beaba93770d7e0853aa8d2e9325

Contents?: true

Size: 1.27 KB

Versions: 56

Compression:

Stored size: 1.27 KB

Contents

module Yao::Resources
  module MetadataAvailable
    def list_metadata(id)
      GET(metadata_path(id)).body["metadata"]
    end

    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

    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

    def get_metadata(id, key)
      GET(metadata_key_path(id, key)).body["meta"]
    end

    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

    def delete_metadata(id, key)
      DELETE(metadata_key_path(id, key)).body
    end

    private
    def metadata_path(id)
      ["servers", id, "metadata"].join("/")
    end

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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
yao-0.13.4 lib/yao/resources/metadata_available.rb
yao-0.13.3 lib/yao/resources/metadata_available.rb
yao-0.13.2 lib/yao/resources/metadata_available.rb
yao-0.13.1 lib/yao/resources/metadata_available.rb
yao-0.13.0 lib/yao/resources/metadata_available.rb
yao-0.12.0 lib/yao/resources/metadata_available.rb
yao-0.11.3 lib/yao/resources/metadata_available.rb
yao-0.11.2 lib/yao/resources/metadata_available.rb
yao-0.11.1 lib/yao/resources/metadata_available.rb
yao-0.11.0 lib/yao/resources/metadata_available.rb
yao-0.10.1 lib/yao/resources/metadata_available.rb
yao-0.10.0 lib/yao/resources/metadata_available.rb
yao-0.9.1 lib/yao/resources/metadata_available.rb
yao-0.9.0 lib/yao/resources/metadata_available.rb
yao-0.8.0 lib/yao/resources/metadata_available.rb
yao-0.7.0 lib/yao/resources/metadata_available.rb
yao-0.6.3 lib/yao/resources/metadata_available.rb
yao-0.6.2 lib/yao/resources/metadata_available.rb
yao-0.6.1 lib/yao/resources/metadata_available.rb
yao-0.6.0 lib/yao/resources/metadata_available.rb