Skip to content

Commit d767e75

Browse files
committed
Work in progress...
1 parent 9f44d62 commit d767e75

File tree

7 files changed

+84
-22
lines changed

7 files changed

+84
-22
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ Check working sample in [sample1.py](/sample1.py) file.
4141
## Authors and contributions
4242

4343
- [Vlada Petrović](https://github.com/VladaPetrovic)
44-
- [Oto Brglez](https://github.com/otobrglez)
44+
- [Oto Brglez](https://github.com/otobrglez)
45+
46+
## Licence
47+
48+
- [MIT](LICENSE.txt)

databox test/__init__.py

Whitespace-only changes.

databox test/test_push.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
from databox import *
3+
4+
class TestPush(unittest.TestCase):
5+
def setUp(self):
6+
self.databox_push_token = "adxg1kq5a4g04k0wk0s4wkssow8osw84"
7+
self.client = Client(self.databox_push_token)
8+
9+
def test_setup(self):
10+
self.client.push("oto", 10.0)
11+
push("aaa", 22)

databox/__init__.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
# Databox Python bindings
2-
# Authors:
3-
# Vlada Petrovic <[email protected]>
4-
# Oto Brglez <[email protected]>
5-
6-
__package_name__ = 'databox'
7-
__version__ = '0.2'
8-
__author__ = 'Vlada Petrovic'
9-
__author_email__ = '[email protected]'
10-
__description__ = (
11-
'''Push metrics to Databox. ''')
12-
__url__ = 'https://github.com/databox/databox-python'
1+
import requests
2+
from os import getenv
3+
4+
5+
class SingleClient(object):
6+
_token = None
7+
8+
class MissingToken(Exception):
9+
pass
10+
11+
@property
12+
def token(self):
13+
if self._token is None:
14+
self._token = getenv("DATABOX_PUSH_TOKEN", None)
15+
16+
if self._token is None:
17+
raise SingleClient.MissingToken("Missing Databox push token")
18+
19+
return self._token
20+
21+
def __init__(self, token=None):
22+
if self._token is None and token is not None:
23+
self._token = token
24+
25+
26+
def push(self, key, value, date=None):
27+
print "--- push --- ", self.token
28+
pass
29+
30+
31+
32+
class Client(object):
33+
_instance = None
34+
client_instance = None
35+
36+
def __init__(self, token=None):
37+
self.client_instance = SingleClient(token)
38+
39+
def __new__(cls, *args, **kwargs):
40+
if not cls._instance:
41+
cls._instance = super(Client, cls). \
42+
__new__(cls, *args, **kwargs)
43+
return cls._instance
44+
45+
@property
46+
def client(self):
47+
return self.client_instance
48+
49+
def push(self, key, value, date=None):
50+
return self.client.push(key, value, date)
51+
52+
53+
def push(key, value, date=None, token=None):
54+
return Client().push(key, value, date)

databox/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from requests.auth import HTTPBasicAuth
44

55
class PushClient(object):
6-
metrics = {"data":[]}
6+
metrics = {"data": []}
77

88
def __init__(self, api_key):
99
self.api_key = api_key

example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
3+
from databox import Client, push
4+
5+
Client("adxg1kq5a4g04k0wk0s4wkssow8osw84")
6+
7+
push("sales", 10)

setup.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# -*- coding: utf-8 -*-
2-
3-
import databox
42
from setuptools import setup, find_packages
53

64
setup(
7-
name=databox.__package_name__,
8-
version=databox.__version__,
9-
author=databox.__author__,
10-
author_email=databox.__author_email__,
11-
description=databox.__description__,
12-
url=databox.__url__,
5+
name="databox",
6+
version="0.2.0",
7+
author="Vlada Petrović",
8+
author_email="support@databox.com",
9+
description="Push metrics to Databox.",
10+
url="https://github.com/databox/databox-python",
1311
license='MIT',
1412

1513
packages=find_packages(exclude=('tests',)),

0 commit comments

Comments
 (0)