class Representation
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.
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 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.
Nested
Definitions
def self.for(resource, response, &block)
Instantiate a new representation from a resource and response.
If a block is given, it is called with the resource and response, and the return value is used as the representation.
Signature
-
returns
Representation
the representation of the resource.
Implementation
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 initialize(resource, value: nil, metadata: {})
Implementation
def initialize(resource, value: nil, metadata: {})
@resource = resource
@value = value
@metadata = metadata
end