Skip to content

Commit bfad238

Browse files
Bug fixes and documentation
1 parent 6eb10c0 commit bfad238

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# robotframework-aprslib
2+
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
3+
4+
```robotframework-apprise``` is a [Robot Framework](https://www.robotframework.org) keyword collection for the [apprise](https://github.com/caronc/apprise) push message library. It enables Robot Framework users to send push/email messages to every message service supported by Apprise.
5+
6+
![transmit](img/message.jpg)
7+
8+
## Installation
9+
10+
- clone repository
11+
- ``pip install -r dependencies.txt``
12+
13+
## Robot Framework Library Example
14+
15+
In order to run the example code, you need to provide at least one valid target messenger. Have a look at [Apprise's list of supported messengers](https://github.com/caronc/apprise/wiki)
16+
17+
- [send_apprise_message](src/send_apprise_message.robot)
18+
19+
## Library usage and supported keywords
20+
21+
| Keyword|Description|
22+
|------- |-----------|
23+
|``Send Apprise Message``|Sends a push message through Apprise|
24+
|``Set Clients`` and ``Set Attachments``|Sets a new value list and replace the previous values|
25+
|``Add Client`` and ``Add Attachment``|Adds a value to an existing list|
26+
|``Remove Client`` and ``Remove Attachment``|Removes a value from an existing list (if present)|
27+
|``Clear All Clients`` and ``Clear All Attachments``|Completely removes the current values from the respective list|
28+
|``Set Delimiter``|Optional reconfiguration of this Robot Framework library's delimiter. See details below|
29+
30+
31+
All ``clients`` and ``attachments`` options can be passed as a ``List`` type variable or as a string. If you use a string, the default delimiter is a comma ``,``. In case you need to use a different delimiter, use the ``Set Delimiter`` keyword.
32+
33+
``Attachments`` are purely optional. Providing at least one ``Client`` is mandatory, though. Both ``Attachments`` and ``Clients`` can either be provided as a ``List`` item or as a separated string.
34+
35+
Examples:
36+
37+
# Send a message with one client and a List which contains our images
38+
@{IMAGE_LIST}= Create List http://www.mysite.com/image1.jpg http://www.mysite.com/image2.jpg
39+
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! clients=<apprise_client> attachments=${IMAGE_LIST}
40+
41+
# Send a message with one client. Our attachments use a comma-separated string (default)
42+
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! clients=<apprise_client> attachments=http://www.mysite.com/image1.jpg,http://www.mysite.com/image2.jpg
43+
44+
# Send a message with one client. Our attachments use a custom delimiter ^
45+
Set Delimiter ^
46+
Send Apprise Message title=Robot Framework Apprise Demo body=Connect to Apprise with your Robot Framework Tests! clients=<apprise_client> attachments=http://www.mysite.com/image1.jpg^http://www.mysite.com/image2.jpg
47+
48+
49+
## Known issues
50+
51+
- This library uses Apprise's default async behavior. Currently, you cannot send messages in a synchronous way.
52+
- The current version of this library does not permit you to set the target format (text, HTML). It uses Apprise's default format which is HTML.

img/message.jpg

84.6 KB
Loading

src/AppriseLibrary.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/opt/local/bin/python3
22
#
33
# Robot Framework Keyword library wrapper for
4-
# https://github.com/rossengeorgiev/aprs-python
5-
# Author: Joerg Schultze-Lutter, 2021
4+
# https://github.com/caronc/apprise
5+
# Author: Joerg Schultze-Lutter, 2022
66
#
77
# This program is free software; you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
@@ -43,12 +43,14 @@ class AppriseLibrary:
4343
DEFAULT_BODY = ""
4444
DEFAULT_CLIENTS = []
4545
DEFAULT_ATTACHMENTS = []
46+
DEFAULT_DELIMITER = ','
4647

4748
# Class-internal Apprise parameters
4849
__title = None
4950
__body = None
5051
__clients = None
5152
__attachments = None
53+
__delimiter = None
5254

5355
# This is our Apprise object
5456
__instance = None
@@ -59,10 +61,12 @@ def __init__(
5961
body: int = DEFAULT_BODY,
6062
clients: list = DEFAULT_CLIENTS,
6163
attachments: list = DEFAULT_ATTACHMENTS,
64+
delimiter: str = DEFAULT_DELIMITER,
6265
):
6366
self.__title = title
6467
self.__body = body
6568
self.__instance = None
69+
self.__delimiter = delimiter
6670
self.__clients = self.__transform_apprise_clients(clients=clients)
6771
self.__attachments = self.__transform_apprise_attachments(
6872
attachments=attachments
@@ -75,7 +79,7 @@ def __transform_apprise_clients(self, clients: object):
7579

7680
# if we deal with a string, split it up and return it as a list
7781
if isinstance(clients, str):
78-
return clients.split(",")
82+
return clients.split(self.delimiter)
7983
else:
8084
return clients
8185

@@ -88,7 +92,7 @@ def __transform_apprise_attachments(self, attachments: object):
8892

8993
# if we deal with a string, split it up and return it as a list
9094
if isinstance(attachments, str):
91-
return attachments.split(",")
95+
return attachments.split(self.delimiter)
9296
else:
9397
return attachments
9498

@@ -105,6 +109,10 @@ def title(self):
105109
def body(self):
106110
return self.__body
107111

112+
@property
113+
def delimiter(self):
114+
return self.__delimiter
115+
108116
@property
109117
def clients(self):
110118
return self.__clients
@@ -135,6 +143,14 @@ def body(self, body: str):
135143
raise ValueError("No value for 'body' has been specified")
136144
self.__body = body
137145

146+
@delimiter.setter
147+
def delimiter(self, delimiter: str):
148+
if not delimiter:
149+
raise ValueError("No value for 'delimiter' has been specified")
150+
if len(delimiter) != 1:
151+
raise ValueError("'delimiter' needs to be exactly one character")
152+
self.__delimiter = delimiter
153+
138154
@attachments.setter
139155
def attachments(self, attachments: object):
140156
if not attachments:
@@ -166,6 +182,10 @@ def get_title(self):
166182
def get_body(self):
167183
return self.body
168184

185+
@keyword("Get Delimiter")
186+
def get_delimiter(self):
187+
return self.delimiter
188+
169189
@keyword("Get Clients")
170190
def get_clients(self):
171191
return self.clients
@@ -187,6 +207,11 @@ def set_body(self, body: str = None):
187207
logger.debug(msg="Setting 'body' attribute")
188208
self.body = body
189209

210+
@keyword("Set Delimiter")
211+
def set_delimiter(self, delimiter: str = None):
212+
logger.debug(msg="Setting 'delimiter' attribute")
213+
self.delimiter = delimiter
214+
190215
@keyword("Set Clients")
191216
def set_clients(self, clients: object):
192217
logger.debug(msg="Setting 'clients' attribute")
@@ -262,6 +287,10 @@ def send_apprise_message(
262287
if attachments:
263288
self.attachments = self.__transform_apprise_attachments(attachments)
264289

290+
# Check if we have received at least one client
291+
if len(self.clients) < 1:
292+
raise ValueError("You need to specify at least one target client")
293+
265294
# Attach the clients
266295
for client in self.clients:
267296
logger.debug(msg=f"Attaching client '{client}'")
@@ -286,7 +315,10 @@ def send_apprise_message(
286315
body=self.body,
287316
attach=self.attachments,
288317
)
318+
return result
289319

290320

291321
if __name__ == "__main__":
322+
a = AppriseLibrary()
323+
a.set_delimiter(',')
292324
pass

0 commit comments

Comments
 (0)