nerveclient 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nerveclient/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import NerveEngineClient
|
nerveclient/client.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from requests.adapters import HTTPAdapter
|
|
3
|
+
from requests.packages.urllib3.util.retry import Retry
|
|
4
|
+
|
|
5
|
+
import pdb
|
|
6
|
+
|
|
7
|
+
class NerveEngineClient:
|
|
8
|
+
connectionString = None
|
|
9
|
+
apiKey = None
|
|
10
|
+
jwt = None
|
|
11
|
+
|
|
12
|
+
s = requests.Session()
|
|
13
|
+
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[429, 500, 502, 503, 504])
|
|
14
|
+
s.mount('http://', HTTPAdapter(max_retries=retries))
|
|
15
|
+
|
|
16
|
+
def __refreshJwt(self):
|
|
17
|
+
r = self.s.post(self.connectionString + "/auth", json={
|
|
18
|
+
"data": {
|
|
19
|
+
"apiKey": self.apiKey
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
r.raise_for_status()
|
|
23
|
+
json = r.json()
|
|
24
|
+
self.jwt = json["jwt"]
|
|
25
|
+
|
|
26
|
+
def __init__(self, connectionString, apiKey):
|
|
27
|
+
self.connectionString = connectionString
|
|
28
|
+
self.apiKey = apiKey
|
|
29
|
+
self.__refreshJwt()
|
|
30
|
+
|
|
31
|
+
def health(self):
|
|
32
|
+
r = self.s.get(self.connectionString + "/health")
|
|
33
|
+
return r.status_code == 200
|
|
34
|
+
|
|
35
|
+
def authed(self):
|
|
36
|
+
r = self.s.post(self.connectionString + "/auth/ping", json={
|
|
37
|
+
"jwt": self.jwt
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return r.status_code == 200
|
|
41
|
+
|
|
42
|
+
def query(self, **kwargs):
|
|
43
|
+
retry = False
|
|
44
|
+
while True:
|
|
45
|
+
args = {"jwt": self.jwt};
|
|
46
|
+
args.update(kwargs);
|
|
47
|
+
|
|
48
|
+
r = self.s.post(self.connectionString + "/query", json={"data": args});
|
|
49
|
+
|
|
50
|
+
if not retry and r.status_code == 401:
|
|
51
|
+
self.__refreshJwt()
|
|
52
|
+
retry = True
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
r.raise_for_status()
|
|
56
|
+
|
|
57
|
+
return r.json()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: nerveclient
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: A small example package
|
|
5
|
+
Author-email: Matthew Prast <mprast@get-nerve.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/get-nerve/nerve-engine-clients
|
|
7
|
+
Project-URL: Issues, https://github.com/get-nerve/nerve-engine-clients/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 2
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=2.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
nerveclient/__init__.py,sha256=EVjZmWpSoNymODALZEbuziwS0zfuYrUDwMUznfSAVFQ,38
|
|
2
|
+
nerveclient/client.py,sha256=cF00xt3K6QO6LfN0BgFThKbIuY4UskD2FjPtwNvqCRc,1530
|
|
3
|
+
nerveclient-0.1.dist-info/METADATA,sha256=Dd3lW2mlrUX9gE6ZAKjvjt2i7g5Kp1cymjekPseEvu4,570
|
|
4
|
+
nerveclient-0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
5
|
+
nerveclient-0.1.dist-info/top_level.txt,sha256=6qsjiAufL7YprFluSX9WK4aU5w6Juppu5sO5Wh9ALjE,12
|
|
6
|
+
nerveclient-0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nerveclient
|