33from os import getenv
44from json import dumps as json_dumps
55
6+ __version__ = "0.1.5"
7+
68
79class Client (object ):
810 push_token = None
@@ -51,37 +53,36 @@ def _push_json(self, data=None, path="/"):
5153 data = json_dumps (data )
5254
5355 response = requests .post (
54- self .push_host + path ,
55- auth = HTTPBasicAuth (self .push_token , '' ),
56- headers = {'Content-Type' : 'application/json' },
57- data = data
56+ self .push_host + path ,
57+ auth = HTTPBasicAuth (self .push_token , '' ),
58+ headers = {
59+ 'Content-Type' : 'application/json' ,
60+ 'User-Agent' : "Databox/" + __version__ + " (Python)"
61+ },
62+ data = data
5863 )
5964
6065 return response .json ()
6166
62-
6367 def push (self , key , value , date = None , attributes = None ):
6468 self .last_push_content = self ._push_json ({
6569 'data' : [self .process_kpi (
66- key = key ,
67- value = value ,
68- date = date ,
69- attributes = attributes
70+ key = key ,
71+ value = value ,
72+ date = date ,
73+ attributes = attributes
7074 )]
7175 })
7276
7377 return self .last_push_content ['status' ] == 'ok'
7478
75-
76-
7779 def insert_all (self , rows ):
7880 self .last_push_content = self ._push_json ({
7981 'data' : [self .process_kpi (** row ) for row in rows ]
8082 })
8183
8284 return self .last_push_content ['status' ] == 'ok'
8385
84-
8586 def last_push (self , number = 1 ):
8687 return self ._push_json (path = '/lastpushes/{n}' .format (** {'n' : number }))
8788
@@ -95,4 +96,4 @@ def insert_all(rows=[], token=None):
9596
9697
9798def last_push (token = None ):
98- return Client (token ).last_push ()
99+ return Client (token ).last_push ()
0 commit comments