fisrt commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from . import API_URL
|
||||
from .auth import AuthAPI
|
||||
|
||||
class ControllerAPI():
|
||||
@staticmethod
|
||||
def create(attrs):
|
||||
try:
|
||||
ret = requests.post(API_URL + 'api/controller/create', attrs, headers= AuthAPI.get_key())
|
||||
if ret.status_code == 200:
|
||||
return True
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print('create controller fail', e)
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def getByMac(mac_address):
|
||||
try:
|
||||
ret = requests.get(API_URL + 'api/controller/get_by_mac/' + mac_address, headers= AuthAPI.get_key())
|
||||
if ret.status_code == 200:
|
||||
return ret.json()
|
||||
except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
|
||||
print('get controller fail', e)
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def getAll():
|
||||
try:
|
||||
api_key = AuthAPI.get_key()
|
||||
ret = requests.get(API_URL + 'api/controller/get/all', headers= AuthAPI.get_key())
|
||||
if ret.status_code == 200:
|
||||
return ret.json()
|
||||
except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
|
||||
print('get all controllers fail', e)
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def updateByAttrs(attrs = None, values = None , datas:dict = None):
|
||||
try:
|
||||
ret = requests.post(API_URL + 'api/controller/update_by_attr/' + str(attrs) + '/' + str(values), datas, headers= AuthAPI.get_key())
|
||||
if ret.status_code == 200:
|
||||
return True
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print('update controller fail', e)
|
||||
return False
|
||||
|
||||
# def existController(self, mac_address):
|
||||
# try:
|
||||
# res = self._requests.get('http://' + api_url + ':3000/api/controller/get_by_mac/' + mac_address, headers= self._header, timeout = 3)
|
||||
# if len(res.json()) > 0:
|
||||
# return True
|
||||
# return False
|
||||
# except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
|
||||
# print('existController', e)
|
||||
# pass
|
||||
Reference in New Issue
Block a user