Skip to content

Commit 3c2f4a4

Browse files
authored
Merge pull request #7 from Windham-High-School/1-email-api
Support email api
2 parents 5b31b95 + 8850c4c commit 3c2f4a4

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

servercom/implementations/circuitpy.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,16 @@ def post(self, point: DataPoint) -> bool:
366366
'/data',
367367
point.dumps(),
368368
content_type = 'application/json',
369-
headers=['User-Agent: Dude']
369+
headers=['User-Agent: CircuitPython, dude!']
370+
).code == 201
371+
372+
def email(self, msg: Email) -> bool:
373+
return self.request(
374+
'POST',
375+
'/email',
376+
msg.dumps(),
377+
content_type = 'application/json',
378+
headers=['User-Agent: CircuitPython, dude!']
370379
).code == 201
371380

372381
def __exit__(self):

servercom/implementations/common.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pass
88

99
from collections import namedtuple
10-
10+
from json import dumps
1111

1212
# Constants:
1313
DEGREE_SIGN = u"\xb0"
@@ -44,3 +44,18 @@ class ConnectionConfig:
4444
API_PORT: int = 8081
4545

4646
CUBESERVER_DEFAULT_CONFIG = ConnectionConfig()
47+
48+
class Email:
49+
"""Holds an email to be sent to the team"""
50+
51+
def __init__(self, subject, message) -> None:
52+
self.subject = subject
53+
self.message = message
54+
55+
def dumps(self) -> str:
56+
return dumps(
57+
{
58+
'subject': self.subject,
59+
'message': self.message
60+
}
61+
)

servercom/implementations/cpy.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,16 @@ def post(self, point: DataPoint) -> bool:
344344
'/data',
345345
point.dumps(),
346346
content_type = 'application/json',
347-
headers=['User-Agent: Dude']
347+
headers=['User-Agent: CPython, dude!']
348+
).code == 201
349+
def email(self, msg: Email) -> bool:
350+
return self.request(
351+
'POST',
352+
'/email',
353+
msg.dumps(),
354+
content_type = 'application/json',
355+
headers=['User-Agent: CPython, dude!']
348356
).code == 201
349-
350357
def __exit__(self):
351358
if self.v:
352359
print("Closing the server connection-")

0 commit comments

Comments
 (0)