ripozo.dispatch.adapters package¶
Submodules¶
ripozo.dispatch.adapters.base module¶
-
class
ripozo.dispatch.adapters.base.
AdapterBase
(resource, base_url=u'')[source]¶ Bases:
object
The adapter base is responsible for specifying how a resource should be translated for the client. For example, you may want to specify a specific hypermedia protocol or format it in a manner that is specific to your client (though you should probably avoid that)
Parameters: formats (list) – A list of strings that indicate which Content-Types will match with this adapter. For example, you might include ‘application/vnd.siren+json’ in the formats for a SIREN adapter. This means that any request with that content type will be responded to in the appropriate manner. Any of the strings in the list will be considered the appropriate format for the adapter on which they are specified. -
combine_base_url_with_resource_url
(resource_url)[source]¶ Does exactly what it says it does. Uses
join_url_parts
with theself.base_url
andresource_url
argument together.Parameters: resource_url (unicode) – The part to join with the self.base_url
Returns: The joined url Return type: unicode
-
extra_headers
¶ Headers that should be added to response. For example it might be the response-type etc...
Returns: A dictionary of the headers to return. Return type: dict
-
classmethod
format_exception
(exc)[source]¶ Takes an exception and appropriately formats the response. By default it just returns a json dump of the status code and the exception message. Any exception that does not have a status_code attribute will have a status_code of 500.
Parameters: exc (Exception) – The exception to format. Returns: A tuple containing: response body, format, http response code Return type: tuple
-
formats
= None¶
-
formatted_body
¶ This property is the fully qualified and formatted response. For example, you might return a Hypermedia formatted response body such as the SIREN hypermedia protocol or HAL
Returns: The formatted response body. Return type: unicode
-
ripozo.dispatch.adapters.boring_json module¶
-
class
ripozo.dispatch.adapters.boring_json.
BoringJSONAdapter
(resource, base_url=u'')[source]¶ Bases:
ripozo.dispatch.adapters.base.AdapterBase
Just a plain old JSON dump of the properties. Nothing exciting.
Format:
- <resource_name>: {
field1: “value” field2: “value” relationship: {
relationship_field: “value”} list_relationship: [
- {
- relationship_field: “value”
relationship_field: “value”}
]
}
-
extra_headers
¶ Returns: A dictionary of headers that should be included in the response Return type: dict
-
formats
= [u'json', u'application/json']¶
-
formatted_body
¶ Returns: The formatted body that should be returned. It’s just a json.dumps
of the properties and relationshipsReturn type: unicode
ripozo.viewsets.constructor module¶
ripozo.dispatch.adapters.hal module¶
-
class
ripozo.dispatch.adapters.hal.
HalAdapter
(resource, base_url=u'')[source]¶ Bases:
ripozo.dispatch.adapters.base.AdapterBase
An adapter that formats the response in the HAL format. A description of the HAL format can be found here: HAL Specification
-
formats
= [u'hal', u'application/hal+json']¶
-
formatted_body
¶ Returns: The response body for the resource. Return type: unicode
-
generate_relationship
(relationship_list)[source]¶ Generates an appropriately formated embedded relationship in the HAL format.
Parameters: relationship (ripozo.viewsets.relationships.relationship.BaseRelationship) – The relationship that an embedded version is being created for. Returns: If it is a ListRelationship it will return a list/collection of the embedded resources. Otherwise it returns a dictionary as specified by the HAL specification. Return type: list|dict
-
ripozo.dispatch.adapters.siren module¶
-
class
ripozo.dispatch.adapters.siren.
SirenAdapter
(resource, base_url=u'')[source]¶ Bases:
ripozo.dispatch.adapters.base.AdapterBase
An adapter that formats the response in the SIREN format. A description of a SIREN format can be found here: SIREN specification
-
extra_headers
¶ The headers that should be appended to the response
Returns: a dictionary of the headers to be set on the response Return type: dict
-
formats
= [u'siren', u'application/vnd.siren+json']¶
-
formatted_body
¶ Gets the formatted body of the response in unicode form. If
self.status_code == 204
then this will return an empty string.Returns: The siren formatted response body Return type: unicode
-