mirror of
https://github.com/caronc/apprise.git
synced 2024-12-12 09:51:05 +01:00
Created Development_API (markdown)
parent
666831e46b
commit
bd461aac17
78
Development_API.md
Normal file
78
Development_API.md
Normal file
@ -0,0 +1,78 @@
|
||||
# Development API
|
||||
Apprise is very easy to use as a developer. The Apprise() object handles everything for you, meanwhile the AppriseAsset() Object allows you to stray away from some default configuration to personalize the users experience (and perhaps fit your application better):
|
||||
* [[The Apprise Object|Development_API#the-apprise-object]]
|
||||
* [[The Apprise Asset Object|Development_API#the-apprise-asset-object]]
|
||||
|
||||
## The Apprise Object
|
||||
The Apprise() object is the heart and soul of this library. To instantiate an instance of the object, one might do the following:
|
||||
```python
|
||||
# Import this library
|
||||
import apprise
|
||||
|
||||
# create an Apprise instance and assign it to variable `apobj`
|
||||
apobj = apprise.Apprise()
|
||||
```
|
||||
|
||||
Use the **add()** function to append the notification URLs we want to provide notifications for.
|
||||
```python
|
||||
# Add all of the notification services by their server url.
|
||||
# A sample email notification
|
||||
isokay = apobj.add('mailto://myemail:mypass@gmail.com')
|
||||
|
||||
# add() will return a True if the URL was successfully parsed and added into
|
||||
# our notification pool. Otherwise it returns False.
|
||||
|
||||
# A sample pushbullet notification
|
||||
isokay = apobj.add('pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b')
|
||||
```
|
||||
|
||||
We can retrieve a list of the active and loaded notification services by using python's built in
|
||||
**len()** function.
|
||||
```python
|
||||
# len(apobj) returns the number of notifications loaded
|
||||
# the below calls this and prints it to the screen:
|
||||
print("There are %d notification services loaded" % len(apobj))
|
||||
```
|
||||
|
||||
You can send a notification to all of the loaded notifications services by just providing it a **title** and a **body** like so:
|
||||
```python
|
||||
# Then notify these services any time you desire. The below would
|
||||
# notify all of the services loaded into our Apprise object.
|
||||
apobj.notify(
|
||||
title='my notification title',
|
||||
body='what a great notification service!',
|
||||
)
|
||||
```
|
||||
By default, all notifications are sent as type **NotifyType.INFO** using the _default_ theme. The following other types are included with this theme:
|
||||
|
||||
| Notification Type | Description |
|
||||
| -------------------- | ----------- |
|
||||
| **NotifyType.INFO** | [![Build Status](https://github.com/caronc/apprise/blob/master/apprise/assets/themes/default/apprise-info-72x72.png)](https://github.com/caronc/apprise/tree/master/apprise/assets/themes/default) |
|
||||
| **NotifyType.SUCCESS** | [![Build Status](https://github.com/caronc/apprise/blob/master/apprise/assets/themes/default/apprise-success-72x72.png)](https://github.com/caronc/apprise/tree/master/apprise/assets/themes/default) |
|
||||
| **NotifyType.WARNING** | [![Build Status](https://github.com/caronc/apprise/blob/master/apprise/assets/themes/default/apprise-warning-72x72.png)](https://github.com/caronc/apprise/tree/master/apprise/assets/themes/default) |
|
||||
| **NotifyType.FAILURE** | [![Build Status](https://github.com/caronc/apprise/blob/master/apprise/assets/themes/default/apprise-failure-72x72.png)](https://github.com/caronc/apprise/tree/master/apprise/assets/themes/default) |
|
||||
|
||||
Should you want to send a notification using a different status, simply include it as part of your **notify()** call:
|
||||
```python
|
||||
# Import our NotifyType
|
||||
from apprise import NotifyType
|
||||
|
||||
# Then notify these services any time you desire. The below would
|
||||
# notify all of the services loaded into our Apprise object as a WARNING.
|
||||
apobj.notify(
|
||||
title='my notification title',
|
||||
body='what a great notification service!',
|
||||
notify_type=NotifyType.WARNING,
|
||||
)
|
||||
```
|
||||
|
||||
If you ever want to reset the object, you can use the **clear()** function.
|
||||
```python
|
||||
# clears out all of the loaded notification services associated with our
|
||||
# Apprise Object.
|
||||
apobj.clear()
|
||||
```
|
||||
|
||||
|
||||
## The Apprise Asset Object
|
||||
The apprise object allows you to customize your alarms by offering it different images, different sources and different themes.
|
Loading…
Reference in New Issue
Block a user