class Async::REST::Representation

A representation consists of data, metadata describing the data, and, on occasion, metadata to describe the metadata (usually for the purpose of verifying message integrity). Metadata is in the form of name-value pairs, where the name corresponds to a standard that defines the value’s structure and semantics. Response messages may include both representation metadata and resource metadata: information about the resource that is not specific to the supplied representation.
REST components perform actions on a resource by using a representation to capture the current or intended state of that resource and transferring that representation between components. A representation is a sequence of bytes, plus representation metadata to describe those bytes. Other commonly used but less precise names for a representation include: document, file, and HTTP message entity, instance, or variant.
A representation of a resource has a value at the time the representation was created or fetched. It is usually generated by performing an HTTP request.

def self.[] wrapper

def self.[] wrapper
	klass = Class.new(self)
	
	if wrapper.is_a?(Class)
		wrapper = wrapper.new
	end
	
	klass.const_set(:WRAPPER, wrapper)
	
	return klass
end

def self.for(resource, response, &block)

@returns [Representation] the representation of the resource.

If a block is given, it is called with the resource and response, and the return value is used as the representation.

Instantiate a new representation from a resource and response.
def self.for(resource, response, &block)
	if block_given?
		return yield(resource, response, self)
	else
		return self.new(resource, value: response.read, metadata: response.headers)
	end
end

def [] **parameters

def [] **parameters
	self.with(parameters: parameters)
end

def close

def close
	@resource.close
end

def get

def get
ass::WRAPPER.call(@resource) do |response|
ponse.success?
data = response.headers
e = response.read
 ResponseError, response

def initialize(resource, value: nil, metadata: {})

Parameters:
  • value (Object) -- the value of the representation.
  • metadata (Hash | HTTP::Headers) -- the metadata associated with the representation.
  • resource (Resource) -- the RESTful resource that this representation is of.
def initialize(resource, value: nil, metadata: {})
	@resource = resource
	
	@value = value
	@metadata = metadata
end

def inspect

def inspect
	"\#<#{self.class} #{@resource.path.inspect} value=#{@value.inspect}>"
end

def value

def value
	@value ||= self.get
end

def value?

def value?
	!@value.nil?
end

def with(klass = nil, **options)

def with(klass = nil, **options)
	if klass
		klass.new(@resource.with(**options))
	else
		self.class.new(@resource.with(**options))
	end
end