3
3
from os import getenv
4
4
from json import dumps as json_dumps
5
5
6
+ __version__ = "0.1.5"
7
+
6
8
7
9
class Client (object ):
8
10
push_token = None
@@ -51,37 +53,36 @@ def _push_json(self, data=None, path="/"):
51
53
data = json_dumps (data )
52
54
53
55
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
58
63
)
59
64
60
65
return response .json ()
61
66
62
-
63
67
def push (self , key , value , date = None , attributes = None ):
64
68
self .last_push_content = self ._push_json ({
65
69
'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
70
74
)]
71
75
})
72
76
73
77
return self .last_push_content ['status' ] == 'ok'
74
78
75
-
76
-
77
79
def insert_all (self , rows ):
78
80
self .last_push_content = self ._push_json ({
79
81
'data' : [self .process_kpi (** row ) for row in rows ]
80
82
})
81
83
82
84
return self .last_push_content ['status' ] == 'ok'
83
85
84
-
85
86
def last_push (self , number = 1 ):
86
87
return self ._push_json (path = '/lastpushes/{n}' .format (** {'n' : number }))
87
88
@@ -95,4 +96,4 @@ def insert_all(rows=[], token=None):
95
96
96
97
97
98
def last_push (token = None ):
98
- return Client (token ).last_push ()
99
+ return Client (token ).last_push ()
0 commit comments