API Documentation
dweeter
dweeter
package dweeter
Encrypted messaging through the free dweet service.
- Author: Quan Lin
- License: MIT
Classes
-
DweeterError
-
CryptoDweet — A class for the free dweet service with encryption.
-
Dweeter — A class for encrypted messaging through the free dweet service.
CryptoDweet
dweeter.dweeter.CryptoDweet
class CryptoDweet(aes_cbc_key: bytes = b'aes_cbc_key', aes_cbc_iv: bytes = b'aes_cbc_iv', base_url: str = DEFAULT_BASE_URL, use_base64: bool = False)
A class for the free dweet service with encryption.
Initialization options:
CryptoDweet()
: With default key and iv, not secure.CryptoDweet(b"YOUR_KEY")
: Only set key, with default iv.CryptoDweet(b"YOUR_KEY", b"YOUR_IV")
: Set both key and iv, strongest encryption.
Parameters
-
aes_cbc_key — The key of AES CBC mode.
-
aes_cbc_iv — The IV of AES CBC mode.
-
base_url — The base url of the dweet server.
-
use_base64 — Use base64 to make dweet content dictionary more compact.
Methods
-
dweet_for — The "dweet for" API.
-
get_latest_dweet_for — The "get latest dweet for" API.
-
get_dweets_for — The "get dweets for" API.
-
async_dweet_for — The async "dweet for" API.
-
async_get_latest_dweet_for — The async "get latest dweet for" API.
-
async_get_dweets_for — The async "get dweets for" API.
dweeter.dweeter.CryptoDweet.dweet_for
method CryptoDweet.dweet_for(thing: str, content_dict: dict[str, str]) → dict
The "dweet for" API.
Parameters
-
thing : str — The thing name.
-
content_dict : dict[str, str] — The content dict.
Returns
-
dict — The result dict of "dweet for" API.
dweeter.dweeter.CryptoDweet.get_latest_dweet_for
method CryptoDweet.get_latest_dweet_for(thing: str) → list
The "get latest dweet for" API.
Parameters
-
thing : str — The thing name.
Returns
-
list — The result list of dict of "get latest dweet for" API.
dweeter.dweeter.CryptoDweet.get_dweets_for
method CryptoDweet.get_dweets_for(thing: str) → list
The "get dweets for" API.
Parameters
-
thing : str — The thing name.
Returns
-
list — The result list of dict of "get dweets for" API.
dweeter.dweeter.CryptoDweet.async_dweet_for
method CryptoDweet.async_dweet_for(thing: str, content_dict: dict[str, str]) → dict
The async "dweet for" API.
The arguments have the same meaning as in dweet_for
.
dweeter.dweeter.CryptoDweet.async_get_latest_dweet_for
method CryptoDweet.async_get_latest_dweet_for(thing: str) → list
The async "get latest dweet for" API.
The arguments have the same meaning as in get_latest_dweet_for
.
dweeter.dweeter.CryptoDweet.async_get_dweets_for
method CryptoDweet.async_get_dweets_for(thing: str) → list
The async "get dweets for" API.
The arguments have the same meaning as in get_dweets_for
.
Dweeter
dweeter.dweeter.Dweeter
class Dweeter(mailbox: str = 'default_mailbox', key: str = 'default_key', debug: bool = False, base_url: str = DEFAULT_BASE_URL, use_base64: bool = False)
A class for encrypted messaging through the free dweet service.
Parameters
-
mailbox — A virtual mailbox name.
-
key — The key to the virtual mailbox.
-
debug — If it is
True
, exceptions will be printed. Otherwise exceptions will be swallowed silently. -
base_url — The base url of the dweet server.
-
use_base64 — Use base64 to make dweet content dictionary more compact.
Notes
With the same mailbox
,
when using a different key
or different use_base64
settings,
it actually creates a different thing name in dweet service.
Methods
-
send_data — Send
data_dict
to the mailbox. -
get_new_data — Receive the latest and new
data_dict
from the mailbox. -
async_send_data — Send
data_dict
to the mailbox asynchronously. -
async_get_new_data — Receive the latest and new
data_dict
from the mailbox asynchronously.
dweeter.dweeter.Dweeter.send_data
method Dweeter.send_data(data_dict: dict) → dict
Send data_dict
to the mailbox.
Parameters
-
data_dict : dict — The data dictionary to send to the mailbox. This dictionary must be json compatible. There are 2 keys reserved for data_dict. One is
created_time
, the dweet service time. The other isremote_time
, the local time of the remote device.
Returns
-
dict — The dweet transaction dict returned from dweet service. It should include the keys of
thing
,content
,created
andtransaction
.
Raises
-
DweeterError
dweeter.dweeter.Dweeter.get_new_data
method Dweeter.get_new_data() → dict
Receive the latest and new data_dict
from the mailbox.
Returns
-
dict — The latest and new data dictionary from the mailbox. None will be returned if the latest
data_dict
is old.
Raises
-
DweeterError
dweeter.dweeter.Dweeter.async_send_data
method Dweeter.async_send_data(data_dict: dict) → dict
Send data_dict
to the mailbox asynchronously.
The arguments have the same meaning as in send_data
.
Raises
-
DweeterError
dweeter.dweeter.Dweeter.async_get_new_data
method Dweeter.async_get_new_data() → dict
Receive the latest and new data_dict
from the mailbox asynchronously.
The arguments have the same meaning as in get_new_data
.
Raises
-
DweeterError