API Reference¶
Classes for representing a Collection+JSON document.
-
class
collection_json.
Array
(item_class, collection_name, items)¶ Bases:
collection_json.ComparableObject
,list
Object representing a Collection+JSON array.
-
find
(name=None, rel=None)¶ Return a list of items in the array matching name and/or rel.
If both name and rel parameters are provided, returned items must match both properties.
-
get
(name=None, rel=None)¶ Return the first item in the array matching name and/or rel.
If both name and rel parameters are provided, the returned item must match both properties.
If no item is found, raises ValueError.
-
to_dict
()¶ Return a dictionary representing an Array object.
-
-
class
collection_json.
ArrayProperty
(cls, name)¶ Bases:
object
A descriptor that converts from any enumerable to a typed Array.
-
class
collection_json.
Collection
(href, links=None, items=None, queries=None, template=None, error=None, version='1.0')¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON document.
-
error
¶ A descriptor for assigning only a specific type of instance.
Additionally supports assigning a dictionary convertable to the type.
-
static
from_json
(data)¶ Return a Collection instance.
This method parses a json string into a Collection object.
Raises ValueError when no valid document is provided.
-
items
¶ A descriptor that converts from any enumerable to a typed Array.
-
links
¶ A descriptor that converts from any enumerable to a typed Array.
-
queries
¶ A descriptor that converts from any enumerable to a typed Array.
-
template
¶ A descriptor for assigning only a specific type of instance.
Additionally supports assigning a dictionary convertable to the type.
-
to_dict
()¶ Return a dictionary representing a Collection object.
-
-
class
collection_json.
ComparableObject
¶ Bases:
object
Abstract base class for objects implementing equality comparison.
This class provides default __eq__ and __ne__ implementations.
-
class
collection_json.
Data
(name, value=None, prompt=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON data object.
-
to_dict
()¶ Return a dictionary representing a Data object.
-
-
class
collection_json.
Error
(code=None, message=None, title=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON error object.
-
to_dict
()¶ Return a dictionary representing the Error instance.
-
-
class
collection_json.
Item
(href=None, data=None, links=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON item object.
-
data
¶ A descriptor that converts from any enumerable to a typed Array.
-
links
¶ A descriptor that converts from any enumerable to a typed Array.
-
properties
¶ Return a list of names that can be looked up on the item.
-
to_dict
()¶ Return a dictionary representing an Item object.
-
-
class
collection_json.
Link
(href, rel, name=None, render=None, prompt=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON link object.
-
to_dict
()¶ Return a dictionary representing a Link object.
-
-
class
collection_json.
Query
(href, rel, name=None, prompt=None, data=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON query object.
-
data
¶ A descriptor that converts from any enumerable to a typed Array.
-
to_dict
()¶ Return a dictionary representing a Query object.
-
-
class
collection_json.
Template
(data=None)¶ Bases:
collection_json.ComparableObject
Object representing a Collection+JSON template object.
-
data
¶ A descriptor that converts from any enumerable to a typed Array.
-
static
from_json
(data)¶ Return a template instance.
Convenience method for parsing ‘write’ responses, which should only contain a template object.
This method parses a json string into a Template object.
Raises ValueError when no valid document is provided.
-
properties
¶ Return a list of names that can be looked up on the template.
-
to_dict
()¶ Return a dictionary representing a Template object.
-
-
class
collection_json.
TypedProperty
(cls, name)¶ Bases:
object
A descriptor for assigning only a specific type of instance.
Additionally supports assigning a dictionary convertable to the type.