diff options
author | thuva4 <tharma.thuva@gmail.com> | 2018-01-30 19:50:33 +0530 |
---|---|---|
committer | thuva4 <tharma.thuva@gmail.com> | 2018-02-08 14:55:43 +0530 |
commit | c53fc432fc7ddf004d4e1eea9bd407f3c548908d (patch) | |
tree | 89a24a0e1432951194a89797deb58c825f4d4336 /testapi/testapi-client/testapiclient/httpClient.py | |
parent | bd2e91686de6bc61b97ac66af47f830d1c82786a (diff) |
create Testapi client
implement auth in testapi client
implement pods in testapi client
Change-Id: Idd5c9dcf938ad5994e655b55d49625ab462ab710
Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/testapi-client/testapiclient/httpClient.py')
-rw-r--r-- | testapi/testapi-client/testapiclient/httpClient.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/httpClient.py b/testapi/testapi-client/testapiclient/httpClient.py new file mode 100644 index 0000000..bc45f36 --- /dev/null +++ b/testapi/testapi-client/testapiclient/httpClient.py @@ -0,0 +1,44 @@ +import json +import requests + + +class HTTPClient(): + + __instance = None + headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} + + @staticmethod + def get_Instance(): + """ Static access method. """ + if HTTPClient.__instance is None: + HTTPClient() + return HTTPClient.__instance + + def __init__(self): + """ Virtually private constructor. """ + if HTTPClient.__instance is not None: + raise Exception("This class is a singleton!") + else: + HTTPClient.__instance = self + + def get(self, url): + r = requests.get(url) + if r.status_code == 200: + return r.json() + else: + return r.text + + def post(self, url, session, data): + r = session.post(url, data=json.dumps(data), headers=HTTPClient.headers) + return r + + def put(self, url, session, data): + r = session.put(url, data=json.dumps(data), headers=HTTPClient.headers) + return r.text + + def delete(self, url, session, *args): + if(args.__len__ > 0): + r = session.delete(url, data=json.dumps(args[0]), headers=HTTPClient.headers) + else: + r = session.delete(url) + return r.text |