simply http client process 17/53217/4
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 7 Mar 2018 09:06:22 +0000 (17:06 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 7 Mar 2018 09:27:11 +0000 (17:27 +0800)
Change-Id: I85b87be7d57b7c3ecb087b27729bc86934283366
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
testapi/testapi-client/testapiclient/http_client.py [moved from testapi/testapi-client/testapiclient/httpClient.py with 74% similarity]
testapi/testapi-client/testapiclient/pods.py
testapi/testapi-client/testapiclient/projects.py

@@ -3,7 +3,7 @@ import json
 import requests
 
 
-class HTTPClient():
+class HTTPClient(object):
 
     __instance = None
     headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
@@ -49,3 +49,24 @@ class HTTPClient():
         else:
             r = session.delete(url)
         return r.text
+
+
+def http_request(method, *args, **kwargs):
+    client = HTTPClient.get_Instance()
+    return getattr(client, method)(*args, **kwargs)
+
+
+def get(url):
+    return http_request('get', url)
+
+
+def post(url, session, data):
+    return http_request('post', url, session, data)
+
+
+def put(url, session, data):
+    return http_request('put', url, session, data)
+
+
+def delete(url, session, data):
+    return http_request('delete', url, session, data)
index 64bb74d..0864c22 100644 (file)
@@ -2,7 +2,7 @@ import json
 
 from testapiclient import command
 from testapiclient import config
-from testapiclient import httpClient
+from testapiclient import http_client
 from testapiclient import identity
 from testapiclient import user
 
@@ -20,7 +20,6 @@ class PodGet(command.Lister):
         return parser
 
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         url = PODS_URL
         if(parsed_args.name):
             url = PODS_URL + "?name=" + parsed_args.name
@@ -40,7 +39,6 @@ class PodGetOne(command.ShowOne):
         return parser
 
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         pods = http_client.get(PODS_URL + "/" + parsed_args.name)
         print pods
 
@@ -61,7 +59,6 @@ class PodCreate(command.Command):
 
     @identity.authenticate
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         response = http_client.post(PODS_URL,
                                     user.User.session,
                                     parsed_args.pod)
@@ -84,6 +81,5 @@ class PodDelete(command.Command):
 
     @identity.authenticate
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         print http_client.delete(PODS_URL + "/" + parsed_args.name,
                                  user.User.session)
index cd55e74..ee2e884 100644 (file)
@@ -2,7 +2,7 @@ import json
 
 from testapiclient import command
 from testapiclient import config
-from testapiclient import httpClient
+from testapiclient import http_client
 from testapiclient import identity
 from testapiclient import user
 
@@ -19,7 +19,6 @@ class ProjectGet(command.Lister):
         return parser
 
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         url = PROJECTS_URL
         if parsed_args.name:
             url = url + "?name=" + parsed_args.name
@@ -38,7 +37,6 @@ class ProjectGetOne(command.ShowOne):
         return parser
 
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         url = PROJECTS_URL + "/" + parsed_args.name
         project = http_client.get(url)
         print project
@@ -57,7 +55,6 @@ class ProjectCreate(command.Command):
 
     @identity.authenticate
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         response = http_client.post(ProjectCreate.projects_url,
                                     user.User.session,
                                     parsed_args.project)
@@ -79,7 +76,6 @@ class ProjectDelete(command.Command):
 
     @identity.authenticate
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         projects = http_client.delete(
             PROJECTS_URL + "/" + parsed_args.name,
             user.User.session)
@@ -103,7 +99,6 @@ class ProjectPut(command.Command):
 
     @identity.authenticate
     def take_action(self, parsed_args):
-        http_client = httpClient.HTTPClient.get_Instance()
         projects = http_client.put(
             PROJECTS_URL + "/" + parsed_args.name,
             user.User.session,