Plugin API¶
BaseSource¶
-
class
livebridge.base.
BaseSource
(*, config={}, **kwargs)¶ Bases:
object
Base class for sources.
-
type
= Defines source type¶
-
mode
= Defines source mode¶
-
__init__
(*, config={}, **kwargs)[source]¶ Base constructor for sources.
Parameters: config – Configuration passed from the control file.
-
_db
¶ Database client for accessing storage.
Returns: livebridge.storages.base.BaseStorage
-
filter_new_posts
(source_id, post_ids)[source]¶ Filters ist of post_id for new ones.
Parameters: - source_id – id of the source
- post_ids – list of post ids
Returns: list of unknown post ids.
-
get_last_updated
(source_id)[source]¶ Returns latest update-timestamp from storage for source.
Parameters: source_id – id of the source (source_id, ticker_id, blog_id pp) Returns: datetime.datetime
object of latest update datetime in db.
-
mode
= ''
-
type
= ''
-
-
class
livebridge.base.
PollingSource
(*, config={}, **kwargs)[source]¶ Bases:
livebridge.base.BaseSource
Base class for sources which are getting polled. Any custom adapter source, which should get polled, has to be inherited from this base class.
-
mode
= 'polling'¶
-
-
class
livebridge.base.
StreamingSource
(*, config={}, **kwargs)[source]¶ Bases:
livebridge.base.BaseSource
Base class for streaming sources. Any custom adapter source, which is using a websocket, SSE or any other stream as source has to be inherited from this base class.
-
listen
(callback)[source]¶ Method has to be implemented by the concrete inherited source class.
A websocket connection has to be opened and given callback method has to be called with the new post as argument.
Parameters: callback – Callback method which has to be called with list of new posts. Returns: True
-
mode
= 'streaming'¶
-
BasePost¶
-
class
livebridge.base.
BasePost
(data, *, content='', images=[])¶ Bases:
object
Base class for posts.
Every concrete implementation of this base class have to implement the poperties defined here. This is needed, so the specific targets do not have to differentiate by the post type, but rather have a unified way to access common properties from the resource, regardless of their source.
-
source
= Defines source type¶
-
__init__
(data, *, content='', images=[])[source]¶ Base constructor for targets.
Parameters: - data –
- dictionary of source post data
- content –
- string of convertered post content, optional
- images –
- list of iage_paths, optional
- data –
-
created
¶ Returns created datetime of the resource, has to be a
datetime.datetime
object.
-
get_action
()[source]¶ Returns type of action which has to be handled by the target. Can be either create, update, delete or ignore.
-
id
¶ Returns the id of the resource at its source.
-
is_deleted
¶ Returns boolean if resource is deleted or not.
-
is_draft
¶ Returns boolean if resource is in drafted state.
-
is_known
¶ Returns boolean if resource is already known to livebridge.
-
is_sticky
¶ Returns boolean if resource is sticky or not.
-
is_submitted
¶ Returns boolean if resource is in submitted state.
-
is_update
¶ Returns boolean if resource is updated or not.
-
set_existing
(existing)[source]¶ Takes existing doc at target.
Parameters: existing – - dict, resource doc at target.
-
source
= ''
-
source_id
¶ Returns the id of the source. For example the id of the blog polled.
-
target_doc
¶ Returns resource doc as at the target, when the posting was already created at the target. This property normally contains the target_doc data from the livebrigde storage item, saved in a syndication earlier.
Returns: dict
-
target_id
¶ Returns the id the target, to which this post has to be syndicated.
Returns: string
-
updated
¶ Returns updated datetime of the resource, has to be a
datetime.datetime
object.
-
BaseConverter¶
-
class
livebridge.base.
BaseConverter
¶ Bases:
object
Base class for converters.
Concrete implementations have to implement public
convert()
method.-
source
= Specifies the type of the source post¶
-
target
= Specifies the target type of the conversion¶
-
convert
(post)[source]¶ Convert incoming content of the incoming raw source post to a string suitable to the target as content.
Parameters: post – raw source post Returns: livebridge.base.ConversionResult
- result of the conversion.
-
source
= ''
-
target
= ''
-
ConversionResult¶
BaseTarget¶
-
class
livebridge.base.
BaseTarget
(*, config={}, **kwargs)¶ Bases:
object
Base class for targets.
Every concrete implementation of a target, requires to implement following methods:
post_item()
- creates new resource at targetdelete_item()
- deletes resoruce at targetupdate_item()
- updates resource at targethandle_extras()
- handle extra actions, for example set resource to sticky at the target.
If a method above is not needed, for example when no update is possible at the target, use
livebridge.posts.base.BasePost.get_action()
to ignore this action.-
type
= Defines target type¶
-
__init__
(*, config={}, **kwargs)[source]¶ Base constructor for targets.
Parameters: config – Configuration passed from the control file.
-
delete_item
(post)[source]¶ Deletes an existing resource at target.
Parameters: post – - Object of type
livebridge.posts.base.BasePost
Returns: livebridge.base.TargetResponse
of the deleted resource returned from service, empty or False if failed.
- Object of type
-
handle_extras
(post)[source]¶ Handle extra actions, for example set resource to sticky at the target. Return None if method is unneeded.
Parameters: post – - Object of type
livebridge.posts.base.BasePost
Returns: livebridge.base.TargetResponse
of the updated resource returned from service, empty or None if nothing has changed at resource.
- Object of type
-
post_item
(post)[source]¶ Creates new resource at target.
Parameters: post – - Object of type
livebridge.posts.base.BasePost
Returns: livebridge.base.TargetResponse
of the newly created resource returned from service, empty if failed.
- Object of type
-
type
= 'base'
-
update_item
(post)[source]¶ Updates existing resource resource at target.
Parameters: post – - Object of type
livebridge.posts.base.BasePost
Returns: livebridge.base.TargetResponse
of the updated resource returned from service, empty or False if failed.
- Object of type
TargetResponse¶
-
class
livebridge.base.
TargetResponse
(**kwargs)[source]¶ Bases:
collections.UserDict
Data container for returning the resource data from a service, awaits dictionary.
Data returned from a BaseTarget derived target type has to be a TargetResponse.
-
clear
() → None. Remove all items from D.¶
-
copy
()¶
-
classmethod
fromkeys
(iterable, value=None)¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
InvalidTargetResource¶
BaseStorage¶
-
class
livebridge.storages.base.
BaseStorage
[source]¶ Bases:
object
Base class for storage clients.
Every concrete implementation of a storage class, requires to implement following methods:
db()
- property holds underlying databse client.setup()
- Method for setting up storage, creating table pp.insert_post()
- insert single post into storage.get_post()
- returns single post from storage.update_post()
- updates single post in storage.delete_post()
- deletes single post in storage.get_last_updated()
- returns latest updated-timestamp or source from storage.
-
db
¶ Property holds underlying database client.
-
delete_post
(target_id, post_id)[source]¶ Deletes single post from storage.
Parameters: - target_id – id of the target
- post_id – id of post to delete
-
get_known_posts
(source_id, post_ids)[source]¶ Return a list of known post_id of a source for a given list of post ids.
Parameters: - source_id – id of the source
- post_ids – list of post ids
Returns: - list of dictionaries.
-
get_last_updated
(source_id)[source]¶ Returns latest updated-timestamp of source from storage.
Parameters: source_id – id of the source
-
get_post
(target_id, post_id)[source]¶ Returns single post from storage.
Parameters: - target_id – id of the target
- post_id – id of post
-
save_control
(data)[source]¶ Method for saving control data in storage.
Parameters: data – control_data Returns: - boolean