aboutsummaryrefslogtreecommitdiffstats
path: root/shoutboxapicommunicator.py
diff options
context:
space:
mode:
Diffstat (limited to 'shoutboxapicommunicator.py')
-rw-r--r--shoutboxapicommunicator.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/shoutboxapicommunicator.py b/shoutboxapicommunicator.py
index 28a5b74..7138aa9 100644
--- a/shoutboxapicommunicator.py
+++ b/shoutboxapicommunicator.py
@@ -1,15 +1,20 @@
import json
-
import requests
import logging
+from basecommunicator import BaseCommunicator
+
+class ShoutboxCommunicator(BaseCommunicator):
+ """Class for communication with the shoutbox API"""
-class Communicator(object):
+ url = "http://localhost:8000"
+ interval = 10
@staticmethod
- def fetch(url):
+ def fetch():
+ """Get and return a list of new messages from the API"""
try:
- r = requests.get(url)
+ r = requests.get(ShoutboxCommunicator.url)
logging.info("Response from API OK.")
except:
@@ -24,10 +29,11 @@ class Communicator(object):
return content
@staticmethod
- def send(url, data):
+ def send(data):
+ """Send a JSON message to the API"""
try:
- requests.post(url, data)
+ requests.post(ShoutboxCommunicator.url, data)
user = json.loads(data)["user"]
logging.info("Sent message from {} to shoutbox.".format(user))
except:
- logging.warning("Failed to send message to shoutbox API!") \ No newline at end of file
+ logging.warning("Failed to send message to shoutbox API!")