Skip to content

Commit 6bfe120

Browse files
committed
Added setup.py
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 7a171b7 commit 6bfe120

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ include
44
pip-selfcheck.json
55
.Python
66
.DS_Store
7-
__pycache__
7+
__pycache__
8+
dist
9+
*.egg-info

labstack/email.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
import json
55
from .common import API_URL
66

7+
def _email_file_from_path(path):
8+
with open(path, 'rb') as file:
9+
return {
10+
'name': os.path.basename(path),
11+
'content': base64.b64encode(file.read()).decode('utf-8')
12+
}
13+
714
class _Email():
815
def __init__(self, interceptor):
916
self.path = '/email'
1017
self.interceptor = interceptor
1118

1219
def send(self, message):
1320
message._add_files()
14-
r = requests.post(API_URL + self.path, auth=self.interceptor, data=message.toJSON())
21+
r = requests.post(API_URL + self.path, auth=self.interceptor, data=message.to_json())
22+
data = r.json()
1523
if not 200 <= r.status_code < 300:
16-
response = r.json()
17-
raise EmailError(response['code'], r['message'])
24+
raise EmailError(data['code'], data['message'])
25+
return EmailMessage.from_json(data)
1826

1927
class EmailMessage():
2028
def __init__(self, to, sender, subject):
@@ -40,7 +48,7 @@ def add_inline(self, path):
4048
def add_attachment(self, path):
4149
self.attachments.append(path)
4250

43-
def toJSON(self):
51+
def to_json(self):
4452
return json.dumps({
4553
'to': self.to,
4654
'from': self.sender,
@@ -50,13 +58,14 @@ def toJSON(self):
5058
'attachments': self._attachments
5159
})
5260

53-
def _email_file_from_path(path):
54-
with open(path, 'rb') as file:
55-
return {
56-
'name': os.path.basename(path),
57-
'content': base64.b64encode(file.read()).decode('utf-8')
58-
}
59-
61+
@classmethod
62+
def from_json(self, message):
63+
em = EmailMessage(message['to'], message['from'], message['subject'])
64+
em.id = message['id']
65+
em.time = message['time']
66+
em.status = message['status']
67+
return em
68+
6069
class EmailError(Exception):
6170
def __init__(self, code, message):
6271
self.code = code

setup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='labstack',
5+
version='0.0.1',
6+
description='Official Python client library for the LabStack REST API',
7+
long_description='`<https://github.com/labstack/labstack-python>`_',
8+
keywords='labstack cube email log mqtt store',
9+
author='Vishal Rana',
10+
author_email='vr@labstack.com',
11+
license='MIT',
12+
install_requires=[
13+
'requests==2.18.1'
14+
],
15+
classifiers=[
16+
'Programming Language :: Python :: 2.6',
17+
'Programming Language :: Python :: 2.7',
18+
'Programming Language :: Python :: 3.2',
19+
'Programming Language :: Python :: 3.3',
20+
'Programming Language :: Python :: 3.4',
21+
'Programming Language :: Python :: 3.5',
22+
'Programming Language :: Python :: 3.6'
23+
]
24+
)

0 commit comments

Comments
 (0)