Usage¶
Initialization¶
The PushNotifier object takes four parameters.
username:
your username from https://pushnotifier.depassword:
your password from https://pushnotifier.depackage_name:
the package you want to send your messages toapi_key:
your api key from https://pushnotifier.de/account/api>>> from pushnotifier import PushNotifier >>> pn = PushNotifier('username', 'password', 'package_name', 'api_key')
login¶
The
login
method returns a dictionary with some basic information about your account if the login data is valid:>>> pn.login(password) {'username': 'username', 'avatar': 'https://gravatar.com/avatar/XXXXX', 'app_token': 'XXXXX', 'expires_at': XXXXX}
send_text¶
The
send_text
method takes three parameters of which onlytext
is required.>>> pn.send_text(text, devices, silent)By default the message gets sent to all
devices
linked to your PushNotifier account. Thesilent
parameter, which by default is set toFalse
specifies if the message triggers a sound on the device(s) it gets sent to.Example: Send the message to specific devices only and don’t trigger a sound on the receiving devices.
>>> pn.send_text(text, devices=['ID1', 'ID2'], silent=True)Errors:
MalformedRequestError DeviceNotFoundError
send_url¶
The
send_url
method has the same parameters as thesend_text
method except that it takes anurl
instead of text.>>> pn.send_url(url, devices, silent)Example:
>>> pn.send_url('https://www.example.com')Errors and returns:
send_url
raises the same errors and has the same returns assend_text
.
send_notification¶
To send a notification you have to pass 2 parameters to the method.
text
andurl
. Apart from that the method again is basically the same assend_text
andsend_url
.>>> pn.send_notification(text, url, devices, silent)Example:
>>> pn.send_url('hello world', 'https://www.example.com')Errors and returns:
send_notification
raises the same errors and has the same returns assend_text
andsend_url
.
send_image¶
To send an image you only have to pass the
path
of your image to the method.>>> pn.send_image(image_path, devices, silent)Example:
>>> pn.send_image('path/to/image.png', devices=['ID1', 'ID2', 'ID3'])Errors:
MalformedRequestError DeviceNotFoundError PayloadTooLargeError UnsupportedMediaTypeError