1- # Databox Python bindings
2- # Authors:
3- # Vlada Petrovic <[email protected] > 4- 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 )
0 commit comments