networkbase – Base classes for all networks

The networkbase module defines the base classes for all networks.

NetworkData – Unified information about messages

class networkbase.NetworkData

Provides an uniform way to access information about posts. The following fields should appear [*] [†]:

id
The message identification. Optional
name
The name to be displayed as author of the message. Required
username
The message author username in the network. Required
avatar
URL to the author avatar. Optional
message
The message. Required
message_time
Message timestamp (as a datetime object). Defaults to None. Optional
favourite
Boolean indicating if the message was marked as “favourite” or not. Optional
parent
The parent of this message, in case of a reply. Optional
parent_owner
Username of the owner of the parent message (in other words, “in reply to”.) Optional
reposted_by
Username friend of the current user that reposted that message. Some networks will return the original user in a separate table (Twitter, in this case, returns the original message with the original user in a “retweeted_status” structure.) In this case, the network layer will must return the original user in name, username and avatar, while the friend username will be moved to reposted_by. Optional
network
The network id source of the message. Network classes don’t need to worry about this field themselves; Networks will set it when merging information from all networks. Networks should NEVER fill this field
[*]Not all fields need to be filled if that would require more than one network call.
[†]Interfaces should be aware that optional fields may not be filled.

NetworkBase – Base class for all networks

class networkbase.NetworkBase

Base class for all networks.

AUTH

List of fields the interface must request to the user in order to retrieve information from the network. It’s a list of dictionaries, containing:

  • name: Name of the option, used in ConfigOpt (for the name in the config file and to access it through the options variable);
  • flags: The list of command line options for this option (as in OptParse);
  • prompt: The prompt to be used by interfaces when requesting the variable;
  • help: Description for the value; it’s used by ConfigOpt to show the description of the paramater in the command line options and can be used by interfaces to show tooltips about the field;
  • type: The type of the option; valid values are:
    • ‘str’: A string;
    • ‘passwd’: Password; string, but interfaces should hide the information if possible.
NAMESPACE
Namespace of the network, used to identify options.
available_requests()
Return the number of requests the user can request before being capped. If such limitation doesn’t exist for the network, a negative number should be returned.
can_delete(message)
Return True if the message can be deleted; False otherwise.
can_favourite(message)
Return True if the message can be favourited/unfavourited; False otherwise.
can_reply(message)
Return True if the message can be replied; False otherwise.
can_repost(message)
Return True if the message can be resposted; False otherwise.
delete_message(message)
Delete an update. Must return True if the message was deleted or False if not. message can be either an id or a NetworkData object with the information about the message to be deleted.
favourite(message)
Toggle the favourite status of a message. message must be a valid NetworkData object. Returns True if the request was successful or False otherwise.
is_setup()
Should return a boolean indicating if the network have all necessary options set up so it can retrieve information. Networks won’t send requests to networks that return False to this function.
Returns a link (as string) to the message in the network site. If the network doesn’t provide a link directly to the message, None shall be returned. message is a NetworkData object.
message(message_id)
Return a single NetworkData object for a specified message.
messages()
Return a list of NetworkData objects for the main “timeline” (the default list presented to the user.)
replies()
Return a list of NetworkData objects for the replies for the user messages.
reply_prefix(message)
Return the prefix to be used in case the user requests a reply for that message. message must be a NetworkData object. Returns a string.
repost(message)
Repost a message in your current timeline. message must be a valid NetworkData object. Must return the id of the new message.
update(status, reply_to=None)
Update the user status. status should be the string with the status update; reply_to should be used in case the message is a reply to another message, it could be a simple id or the NetworkData object of the original data. Must return the id for the new status.