Class: M2X::Client::Resource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/m2x/resource.rb

Overview

Wrapper for M2X::Client resources

Direct Known Subclasses

Collection, Device, Distribution, Job, Key, Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes) ⇒ Resource

Returns a new instance of Resource.



11
12
13
14
# File 'lib/m2x/resource.rb', line 11

def initialize(client, attributes)
  @client     = client
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/m2x/resource.rb', line 7

def attributes
  @attributes
end

Instance Method Details

#delete!Object

Delete the resource



35
36
37
# File 'lib/m2x/resource.rb', line 35

def delete!
  @client.delete(path)
end

#inspectObject



39
40
41
# File 'lib/m2x/resource.rb', line 39

def inspect
  "<#{self.class.name}: #{attributes.inspect}>"
end

#pathObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/m2x/resource.rb', line 43

def path
  raise NotImplementedError
end

#refreshObject

Refresh the resource details and return self



24
25
26
27
# File 'lib/m2x/resource.rb', line 24

def refresh
  view
  self
end

#update!(params) ⇒ Object

Update an existing resource details



30
31
32
# File 'lib/m2x/resource.rb', line 30

def update!(params)
  @client.put(path, nil, params, "Content-Type" => "application/json")
end

#viewObject

Return the resource details



17
18
19
20
21
# File 'lib/m2x/resource.rb', line 17

def view
  res = @client.get(path)

  @attributes = res.json if res.success?
end