Class Collection
Collections base class. ComodIT server maintains collections of
entities. Entities are listed, retrieved, created and deleted through
these collections. Each collection has a unique URL. An instance of
Collection
is a local representation of a remote ComodIT
collection. Requests are sent to ComodIT server to clear or list the content of the collection, or to get a particular entity of the collection. Creation and
update of particular remote entities must be handled by subclasses. Also,
subclasses should provide local entity instantiation helpers. Indeed,
creation, update and instantiation are specific to entity type.
Note that some operations on collections are optional. For instance, a
read-only collection will not allow the deletion, update or creation of
entities. In particular, most collections do not allow clear operation.
Collection
instances may be iterated with for ...
in
construction. For instance, the following snippet prints the
name of all entities of collection c
.
>>> for r in c:
... print r.name
Above snippet is equivalent to:
>>> for r in c.list():
... print r.name
|
__init__(self,
client,
url)
Creates an instance of collection. |
|
|
|
refresh(self,
entity,
parameters={ } )
Updates the local representation of a remote entity. |
|
|
list of Entity
|
list(self,
parameters={ } )
Fetches the entities in this collection. |
|
|
iterator
|
__iter__(self)
Provides an iterator on the entities of this collection. |
|
|
Entity
|
get(self,
identifier='
' ,
parameters={ } )
Retrieves a particular entity of this collection. |
|
|
|
delete(self,
identifier,
parameters={ } )
Deletes a particular entity in this collection. |
|
|
|
clear(self,
parameters={ } )
Clears the content of the collection i.e. |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
client,
url)
(Constructor)
|
|
Creates an instance of collection. Note that Collection
class should never be instantiated directly.
- Parameters:
client (Client) - ComodIT client.
url (string) - URL of remote collection on ComodIT server. This URL must be
relative to ComodIT server's API URL and should not start with a
slash.
- Overrides:
object.__init__
|
refresh(self,
entity,
parameters={ } )
|
|
Updates the local representation of a remote entity.
- Parameters:
entity (Entity) - Entity's local representation.
parameters (dict of strings) - Query parameters to send to ComodIT server.
- Raises:
|
list(self,
parameters={ } )
|
|
Fetches the entities in this collection.
- Parameters:
parameters (dict of strings) - Query parameters to send to ComodIT server.
- Returns: list of Entity
|
Provides an iterator on the entities of this collection.
- Returns: iterator
- An iterator object
|
get(self,
identifier='
' ,
parameters={ } )
|
|
Retrieves a particular entity of this collection.
- Parameters:
identifier (string) - The identifier of the entity to retrieve.
parameters (dict of strings) - Query parameters to send to ComodIT server.
- Returns: Entity
- An entity representation.
- Raises:
|
delete(self,
identifier,
parameters={ } )
|
|
Deletes a particular entity in this collection.
- Parameters:
identifier (string) - The identifier of the entity to delete.
parameters (dict of strings) - Query parameters to send to ComodIT server.
|
clear(self,
parameters={ } )
|
|
Clears the content of the collection i.e. deletes all entities of the
collection. As a result, a subsequent call to list would return an empty list (if nobody re-added
entities to the list in the meantime).
- Parameters:
parameters (dict of strings) - Query parameters to send to ComodIT server.
|