2021-07-20 11:00:49 -03:00
|
|
|
from http import HTTPStatus
|
|
|
|
import requests
|
|
|
|
|
2021-07-06 11:41:36 -03:00
|
|
|
from error import get_http_error_resp
|
2021-07-20 11:00:49 -03:00
|
|
|
from flask_restful import Resource
|
|
|
|
import constants
|
|
|
|
|
|
|
|
|
|
|
|
class InfoResource(Resource):
|
|
|
|
def get(self):
|
|
|
|
try:
|
|
|
|
info_response = requests.get(f"{constants.CHARGE_ROOT}/info",
|
|
|
|
timeout=(constants.CONNECTION_TIMEOUT,
|
|
|
|
constants.RESPONSE_TIMEOUT))
|
|
|
|
if info_response.status_code != HTTPStatus.OK:
|
2021-07-06 11:41:36 -03:00
|
|
|
return get_http_error_resp('LIGHTNING_CHARGE_INFO_FAILED')
|
2021-07-20 11:00:49 -03:00
|
|
|
return info_response.json(), HTTPStatus.OK
|
|
|
|
except requests.exceptions.RequestException:
|
2021-07-06 11:41:36 -03:00
|
|
|
return get_http_error_resp('LIGHTNING_CHARGE_INFO_FAILED')
|