Sunspear Client¶
sunspear.backends.base¶
-
class
sunspear.backends.base.BaseBackend¶ -
activity_create(activity, **kwargs)¶ Stores a new activity to the backend.
Parameters: activity (dict) – a dict representing the activity Returns: a dict representing the newly stored activity
-
activity_delete(activity, **kwargs)¶ Performs the task of actually deleting the activity from the backend.
Parameters: activity (dict) – a dict representing the activity
-
activity_exists(activity, **kwargs)¶ Determins if an
activityalready exists in the backend.Parameters: activity (dict) – the activity we want to determin if it exists Returns: Trueif theactivityexists, otherwiseFalse
-
activity_get(activity, **kwargs)¶
-
activity_update(activity, **kwargs)¶ Performs the actual task of updating the activity in the backend.
Parameters: activity (dict) – a dict representing the activity Returns: a dict representing the newly stored activity
-
clear_all_activities()¶ Clears all activities from the backend.
-
clear_all_objects()¶ Clears all objects from the backend.
-
create_activity(activity, **kwargs)¶ Stores a new
activityin the backend. If an object with the same id already exists in the backend, aSunspearDuplicateEntryExceptionis raised. If an ID is not provided, one is generated on the fly.Activities that provide
objectsas dictionaries have their objects processed and stored usingcreate_obj, and theobjectsare replaced with their id’s within the activity.Parameters: activity (dict) – activity we want to store in the backend Raises: SunspearDuplicateEntryExceptionif the record already exists in the database.Returns: dict representing the new activity.
-
create_obj(obj, **kwargs)¶ Stores a new
objin the backend. If an object with the same id already exists in the backend, aSunspearDuplicateEntryExceptionis raised. If an ID is not provided, one is generated on the fly.Parameters: obj (dict) – obj we want to store in the backend Raises: SunspearDuplicateEntryExceptionif the record already exists in the database.Returns: dict representing the new obj.
-
create_sub_activity(activity, actor, content, extra={}, sub_activity_verb='', **kwargs)¶ Creates a new sub-activity as a child of
activity.Parameters: - activity (a string or dict) – the activity we want to create the sub-item for
- actor (a string or dict) – the
objectcreating the sub-activity - content (a string or dict) – a string or an
objectrepresenting the content of the sub-activity - extra (dict) – additional data the is to be included as part of the
sub-activityactivity - sub_activity_verb (string) – the verb of the sub activity
Returns: a tuple containing the new sub activity and the original activity the sub activity was created for.
-
delete_activity(activity, **kwargs)¶ Deletes an existing activity from the backend.
Parameters: activity (dict) – a dict representing the activity Raises: SunspearInvalidActivityExceptionif the activity doesn’t have a valid id.
-
delete_obj(obj, **kwargs)¶ Deletes an existing obj from the backend.
raises:
SunspearInvalidObjectException– if the obj doesn’t have a valid id.
Parameters: obj (dict) – a dict representing the obj Raises: SunspearInvalidObjectException
-
delete_sub_activity(sub_activity, sub_activity_verb, **kwargs)¶ Deletes a
sub_activitymade on an activity. This will also update the corresponding activity.Parameters: - sub_activity (string) – the id of the reply activity to delete
- sub_activity_verb (string) – the verb of the sub activity
-
get_activity(activity_ids=[], **kwargs)¶ Gets an activity or a list of activities from the backend.
Parameters: activity_ids (list) – a list of ids of activities that will be retrieved from the backend. Returns: a list of activities. If an activity is not found, a partial list should be returned.
-
get_new_id()¶ Generates a new unique ID. The default implementation uses uuid1 to generate a unique ID.
Returns: a new id
-
get_obj(obj_ids=[], **kwargs)¶ Gets an obj or a list of activities from the backend.
Parameters: obj (list) – a list of ids of activities that will be retrieved from the backend. Returns: a list of activities. If an obj is not found, a partial list should be returned.
-
obj_create(obj, **kwargs)¶ Stores a new obj to the backend.
Parameters: obj (dict) – a dict representing the obj Returns: a dict representing the newly stored obj
-
obj_delete(obj, **kwargs)¶
-
obj_exists(obj, **kwargs)¶ Determins if an
objectalready exists in the backend.Parameters: obj (dict) – the activity we want to determin if it exists Returns: Trueif theobjectexists, otherwiseFalse
-
obj_get(obj, **kwargs)¶
-
obj_update(obj, **kwargs)¶
-
sub_activity_create(activity, actor, content, extra={}, sub_activity_verb='', sub_activity_attribute='', **kwargs)¶ Creates a new sub-activity as a child of
activity.Parameters: - activity (a string or dict) – the activity we want to create the sub-item for
- actor (a string or dict) – the
objectcreating the sub-activity - content (a string or dict) – a string or an
objectrepresenting the content of the sub-activity - extra (dict) – additional data the is to be included as part of the
sub-activityactivity - sub_activity_verb (string) – the verb of the sub activity
- sub_activity_attribute (string) – the attribute in the activity the
sub-activitywill be a part of
Returns: a tuple containing the new sub activity and the original activity the sub activity was created for.
-
sub_activity_delete(sub_activity, sub_activity_verb, **kwargs)¶
-
update_activity(activity, **kwargs)¶ Updates an existing activity in the backend. If the object does not exist, it is created in the backend.
Parameters: activity (dict) – a dict representing the activity Raises: SunspearInvalidActivityExceptionif the activity doesn’t have a valid id.Returns: a dict representing the newly stored activity
-
update_obj(obj, **kwargs)¶ Updates an existing obj in the backend. If the object does not exist, it is created in the backend.
raises:
SunspearInvalidObjectException– if the obj doesn’t have a valid id.
Parameters: obj (dict) – a dict representing the obj Raises: SunspearInvalidObjectException Returns: a dict representing the newly stored obj
-