Class: Zcloudjp::Metadata

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/zcloudjp/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#load_file, #parse_params

Constructor Details

#initialize(machine) ⇒ Metadata

TODO Should be hybrid: executable when a machine object is given or not.



13
14
15
# File 'lib/zcloudjp/metadata.rb', line 13

def initialize(machine)
  @machine = machine
end

Instance Attribute Details

#machineObject (readonly)

Returns the value of attribute machine.



8
9
10
# File 'lib/zcloudjp/metadata.rb', line 8

def machine
  @machine
end

Instance Method Details

#create(params = {}) ⇒ Object

PUT /machines/:id/metadata.:format



31
32
33
34
35
# File 'lib/zcloudjp/metadata.rb', line 31

def create(params={})
  key = params.delete(:key)
  machine.request_options = machine.request_options.merge(body: parse_params(params, :metadata).to_json)
  Zcloudjp::Client.put("/machines/#{machine.id}/metadata/#{key}", machine.request_options)
end

#delete(params = {}) ⇒ Object

DELETE /machines/:id/metadata/:key.:format



44
45
46
47
# File 'lib/zcloudjp/metadata.rb', line 44

def delete(params={})
  key = params.delete(:key)
  Zcloudjp::Client.delete("/machines/#{machine.id}/metadata/#{key}", machine.request_options)
end

#indexObject Also known as: list

GET /machines/:id/metadata.:format



18
19
20
# File 'lib/zcloudjp/metadata.rb', line 18

def index
  Zcloudjp::Client.get("/machines/#{machine.id}/metadata", machine.request_options)
end

#show(params = {}) ⇒ Object Also known as: find_by

GET /machines/:id/metadata/:key.:format



24
25
26
27
# File 'lib/zcloudjp/metadata.rb', line 24

def show(params={})
  key = params.delete(:key)
  Zcloudjp::Client.get("/machines/#{machine.id}/metadata/#{key}", machine.request_options)
end

#update(params = {}) ⇒ Object

PUT /machines/:id/metadata/:key.:format



38
39
40
41
# File 'lib/zcloudjp/metadata.rb', line 38

def update(params={})
  machine.request_options = machine.request_options.merge(body: parse_params(params, :metadata).to_json)
  Zcloudjp::Client.put("/machines/#{machine.id}/metadata", machine.request_options)
end