Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f3f5c4588 | |||
| db33d81edd | |||
| 3b54a8a830 | |||
| 7e12c6e6b4 | |||
| 2c86f5f9c5 | |||
|
|
fa0d340437 | ||
| 6037d30721 | |||
|
|
af38c81ad5 | ||
| aae679a292 | |||
| a7d7c2864c | |||
| b32c84e3db | |||
| 8b3cf944dd | |||
| c1497f0b00 | |||
| ef926fd983 | |||
| 61af626207 | |||
| 72fb58fa12 | |||
| 23d8fa5624 | |||
|
|
5c977e3732 | ||
| 1c541fa4d6 | |||
| cb5b85e9d4 | |||
| ec399c8b0a | |||
| 40c0c9aa69 | |||
| 736182b200 | |||
| 5b1bf8c1c4 |
@@ -5,7 +5,14 @@ Georide api lib
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from georideapilib.exception import (
|
||||||
|
LoginException,
|
||||||
|
SeverException,
|
||||||
|
UnauthorizedException
|
||||||
|
)
|
||||||
from georideapilib.objects import (
|
from georideapilib.objects import (
|
||||||
GeoRideTracker,
|
GeoRideTracker,
|
||||||
GeoRideAccount,
|
GeoRideAccount,
|
||||||
@@ -13,16 +20,12 @@ from georideapilib.objects import (
|
|||||||
GeoRideTrackerTrip,
|
GeoRideTrackerTrip,
|
||||||
GeoRideTrackerPosition,
|
GeoRideTrackerPosition,
|
||||||
GeoRideSharedTrip,
|
GeoRideSharedTrip,
|
||||||
GeoRideTrackerBeacon
|
GeoRideTrackerBeacon,
|
||||||
|
GeoRideMaintenance
|
||||||
)
|
)
|
||||||
|
|
||||||
from georideapilib.exception import (
|
GEORIDE_API_HOST = "https://api.georide.com"
|
||||||
LoginException,
|
GEORIDE_SOCKET_HOST = "https://socket.georide.com"
|
||||||
SeverException,
|
|
||||||
UnauthorizedException
|
|
||||||
)
|
|
||||||
|
|
||||||
GEORIDE_API_HOST = "https://api.georide.fr"
|
|
||||||
GEORIDE_API_ENDPOINT_LOGIN = "/user/login"
|
GEORIDE_API_ENDPOINT_LOGIN = "/user/login"
|
||||||
GEORIDE_API_ENDPOINT_NEW_TOKEN = "/user/new-token"
|
GEORIDE_API_ENDPOINT_NEW_TOKEN = "/user/new-token"
|
||||||
GEORIDE_API_ENDPOINT_LOGOUT = "/user/logout"
|
GEORIDE_API_ENDPOINT_LOGOUT = "/user/logout"
|
||||||
@@ -40,19 +43,24 @@ GEORIDE_API_ENDPOINT_TRACKER_ALARM_OFF = "/tracker/{trackerId}/sonor-alarm/off"
|
|||||||
GEORIDE_API_ENDPOINT_TRACKER_ALARM_ON = "/tracker/{trackerId}/sonor-alarm/on"
|
GEORIDE_API_ENDPOINT_TRACKER_ALARM_ON = "/tracker/{trackerId}/sonor-alarm/on"
|
||||||
GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_OFF = "/tracker/{trackerId}/eco-mode/off"
|
GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_OFF = "/tracker/{trackerId}/eco-mode/off"
|
||||||
GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_ON = "/tracker/{trackerId}/eco-mode/on"
|
GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_ON = "/tracker/{trackerId}/eco-mode/on"
|
||||||
|
GEORIDE_API_ENDPOINT_TRACKER_DELETE_MAINTENANCE = "/tracker/{trackerId}/maintenance/{maintenanceId}"
|
||||||
|
GEORIDE_API_ENDPOINT_TRACKER_MAINTENANCE = "/tracker/{trackerId}/maintenance"
|
||||||
|
|
||||||
_SESSION = requests.Session()
|
_SESSION = requests.Session()
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_authorisation_token(email, password):
|
def get_authorisation_token(email, password):
|
||||||
""" return an authorization token or no"""
|
""" return an authorization token or no"""
|
||||||
data = {"email": email, "password": password}
|
data = {"email": email, "password": password}
|
||||||
encoded_data = json.dumps(data).encode('utf-8')
|
encoded_data = json.dumps(data).encode('utf-8')
|
||||||
|
|
||||||
response = _SESSION.post(
|
response = _send_request(
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_LOGIN,
|
"POST",
|
||||||
|
GEORIDE_API_ENDPOINT_LOGIN,
|
||||||
|
token=None,
|
||||||
data=encoded_data,
|
data=encoded_data,
|
||||||
headers={'Content-Type': 'application/json'})
|
)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
_LOGGER.debug("Login success")
|
_LOGGER.debug("Login success")
|
||||||
@@ -70,16 +78,17 @@ def get_authorisation_token(email, password):
|
|||||||
|
|
||||||
def renew_token(token):
|
def renew_token(token):
|
||||||
""" renew the authorization token """
|
""" renew the authorization token """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.get(
|
"GET",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_NEW_TOKEN,
|
GEORIDE_API_ENDPOINT_NEW_TOKEN,
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
_LOGGER.debug("Token updated")
|
_LOGGER.debug("Token updated")
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
new_token = response_data['authToken']
|
new_token = response_data['authToken']
|
||||||
elif response.status_code == 401:
|
elif response.status_code == 401:
|
||||||
_LOGGER.warnning("Renew token refused")
|
_LOGGER.warning("Renew token refused")
|
||||||
raise UnauthorizedException(renew_token, "Renew token refused")
|
raise UnauthorizedException(renew_token, "Renew token refused")
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
||||||
@@ -87,39 +96,43 @@ def renew_token(token):
|
|||||||
"Georide login, http error code: {}".format(response.status_code))
|
"Georide login, http error code: {}".format(response.status_code))
|
||||||
return new_token
|
return new_token
|
||||||
|
|
||||||
|
|
||||||
def revoke_token(token):
|
def revoke_token(token):
|
||||||
""" invalidate the authorization token """
|
""" invalidate the authorization token """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_LOGOUT,
|
GEORIDE_API_ENDPOINT_LOGOUT,
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
if response.status_code == 401:
|
if response.status_code == 401:
|
||||||
_LOGGER.warnning("Token allready revoked")
|
_LOGGER.warning("Token already revoked")
|
||||||
raise UnauthorizedException(revoke_token, "Token allready revoked")
|
raise UnauthorizedException(revoke_token, "Token allready revoked")
|
||||||
if response.status_code == 403:
|
if response.status_code == 403:
|
||||||
_LOGGER.warnning("Token allready revoked")
|
_LOGGER.warning("Token already revoked")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_user(token):
|
def get_user(token):
|
||||||
""" get the georide user info """
|
""" get the georide user info """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.get(
|
"GET",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_USER,
|
GEORIDE_API_ENDPOINT_USER,
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
_LOGGER.debug(response_data)
|
_LOGGER.debug(response_data)
|
||||||
account = GeoRideUser.from_json(response_data)
|
account = GeoRideUser.from_json(response_data)
|
||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
def get_trackers(token):
|
def get_trackers(token):
|
||||||
""" get user trackers """
|
""" get user trackers """
|
||||||
|
response = _send_request(
|
||||||
headers = {"Authorization": "Bearer " + token}
|
"GET",
|
||||||
response = _SESSION.get(
|
GEORIDE_API_ENDPOINT_TRACKERS,
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKERS,
|
token
|
||||||
headers=headers)
|
)
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
trackers = []
|
trackers = []
|
||||||
@@ -128,13 +141,14 @@ def get_trackers(token):
|
|||||||
trackers.append(GeoRideTracker.from_json(json_tracker))
|
trackers.append(GeoRideTracker.from_json(json_tracker))
|
||||||
return trackers
|
return trackers
|
||||||
|
|
||||||
|
|
||||||
def get_tracker_beacons(token, tracker_id):
|
def get_tracker_beacons(token, tracker_id):
|
||||||
""" get user trackers """
|
""" get user trackers """
|
||||||
|
response = _send_request(
|
||||||
headers = {"Authorization": "Bearer " + token}
|
"GET",
|
||||||
response = _SESSION.get(
|
GEORIDE_API_ENDPOINT_TRACKER_BEACON.format(trackerId=str(tracker_id)),
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_BEACON.format(trackerId=str(tracker_id)),
|
token
|
||||||
headers=headers)
|
)
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
trackers_beacons = []
|
trackers_beacons = []
|
||||||
@@ -145,13 +159,15 @@ def get_tracker_beacons(token, tracker_id):
|
|||||||
trackers_beacons.append(GeoRideTrackerBeacon.from_json(json_tracker_beacon))
|
trackers_beacons.append(GeoRideTrackerBeacon.from_json(json_tracker_beacon))
|
||||||
return trackers_beacons
|
return trackers_beacons
|
||||||
|
|
||||||
|
|
||||||
def get_trips(token, tracker_id, from_date, to_date):
|
def get_trips(token, tracker_id, from_date, to_date):
|
||||||
""" return all trips between two dates """
|
""" return all trips between two dates """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.get(
|
"GET",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRIPS.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_TRIPS.format(trackerId=str(tracker_id)),
|
||||||
params={'from': from_date, 'to': to_date},
|
token,
|
||||||
headers=headers)
|
{'from': from_date, 'to': to_date}
|
||||||
|
)
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
trips = []
|
trips = []
|
||||||
@@ -160,13 +176,15 @@ def get_trips(token, tracker_id, from_date, to_date):
|
|||||||
trips.append(GeoRideTrackerTrip.from_json(json_trip))
|
trips.append(GeoRideTrackerTrip.from_json(json_trip))
|
||||||
return trips
|
return trips
|
||||||
|
|
||||||
|
|
||||||
def get_positions(token, tracker_id, from_date, to_date):
|
def get_positions(token, tracker_id, from_date, to_date):
|
||||||
""" return all trips between two dates """
|
""" return positions from dates """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.get(
|
"GET",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_POSITIONS.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_POSITIONS.format(trackerId=str(tracker_id)),
|
||||||
params={'from': from_date, 'to': to_date},
|
token,
|
||||||
headers=headers)
|
{'from': from_date, 'to': to_date}
|
||||||
|
)
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
positions = []
|
positions = []
|
||||||
@@ -175,18 +193,22 @@ def get_positions(token, tracker_id, from_date, to_date):
|
|||||||
positions.append(GeoRideTrackerPosition.from_json(json_position))
|
positions.append(GeoRideTrackerPosition.from_json(json_position))
|
||||||
return positions
|
return positions
|
||||||
|
|
||||||
|
|
||||||
def share_a_trip_by_trip_id(token, tracker_id, trip_id):
|
def share_a_trip_by_trip_id(token, tracker_id, trip_id):
|
||||||
""" share trip by trip id """
|
""" share trip by trip id """
|
||||||
return _share_a_trip(token, tracker_id, trip_id=trip_id)
|
return _share_a_trip(token, tracker_id, trip_id=trip_id)
|
||||||
|
|
||||||
|
|
||||||
def share_a_trip_by_date(token, tracker_id, from_date, to_date):
|
def share_a_trip_by_date(token, tracker_id, from_date, to_date):
|
||||||
""" share trips between two dates """
|
""" share trips between two dates """
|
||||||
return _share_a_trip(token, tracker_id, from_date=from_date, to_date=to_date)
|
return _share_a_trip(token, tracker_id, from_date=from_date, to_date=to_date)
|
||||||
|
|
||||||
|
|
||||||
def share_a_trip_by_trip_merge_id(token, tracker_id, trip_merged_id):
|
def share_a_trip_by_trip_merge_id(token, tracker_id, trip_merged_id):
|
||||||
""" share trip by trip merged id """
|
""" share trip by trip merged id """
|
||||||
return _share_a_trip(token, tracker_id, trip_merged_id=trip_merged_id)
|
return _share_a_trip(token, tracker_id, trip_merged_id=trip_merged_id)
|
||||||
|
|
||||||
|
|
||||||
def _share_a_trip(token, tracker_id, trip_id=None, from_date=None, # pylint: disable= R0913
|
def _share_a_trip(token, tracker_id, trip_id=None, from_date=None, # pylint: disable= R0913
|
||||||
to_date=None, trip_merged_id=None):
|
to_date=None, trip_merged_id=None):
|
||||||
""" share trip by trib_id or between two dates or trip_merged_id """
|
""" share trip by trib_id or between two dates or trip_merged_id """
|
||||||
@@ -200,91 +222,156 @@ def _share_a_trip(token, tracker_id, trip_id=None, from_date=None, # pylint: dis
|
|||||||
|
|
||||||
encoded_data = json.dumps(data).encode('utf-8')
|
encoded_data = json.dumps(data).encode('utf-8')
|
||||||
|
|
||||||
headers = {
|
response = _send_request(
|
||||||
"Authorization": "Bearer " + token,
|
"POST",
|
||||||
'Content-Type': 'application/json'
|
GEORIDE_API_ENDPOINT_TRIP_SHARE.format(trackerId=str(tracker_id)),
|
||||||
}
|
token,
|
||||||
response = _SESSION.post(
|
data=encoded_data
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRIP_SHARE.format(trackerId=str(tracker_id)),
|
)
|
||||||
data=encoded_data,
|
|
||||||
headers=headers)
|
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return GeoRideSharedTrip.from_json(response_data)
|
return GeoRideSharedTrip.from_json(response_data)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def lock_tracker(token, tracker_id):
|
def lock_tracker(token, tracker_id):
|
||||||
""" used to lock a tracker """
|
""" used to lock a tracker """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_LOCK.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_LOCK.format(trackerId=str(tracker_id)),
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def unlock_tracker(token, tracker_id):
|
def unlock_tracker(token, tracker_id):
|
||||||
""" used to unlock a tracker """
|
""" used to unlock a tracker """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_UNLOCK.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_UNLOCK.format(trackerId=str(tracker_id)),
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def toogle_lock_tracker(token, tracker_id):
|
def toogle_lock_tracker(token, tracker_id):
|
||||||
""" used to toggle lock a tracker """
|
""" used to toggle lock a tracker """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TOGGLE_LOCK.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_TOGGLE_LOCK.format(trackerId=str(tracker_id)),
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
return response_data['locked']
|
return response_data['locked']
|
||||||
|
|
||||||
|
|
||||||
def change_tracker_siren_state(token, tracker_id, state: bool):
|
def change_tracker_siren_state(token, tracker_id, state: bool):
|
||||||
""" used to toggle lock a tracker """
|
""" used to change siren state """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
endpoint = (GEORIDE_API_ENDPOINT_TRACKER_ALARM_ON.format(trackerId=str(tracker_id))) if state \
|
||||||
response = None
|
else (GEORIDE_API_ENDPOINT_TRACKER_ALARM_OFF.format(trackerId=str(tracker_id)))
|
||||||
if state == True:
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ALARM_ON.format(trackerId=str(tracker_id)),
|
endpoint,
|
||||||
headers=headers)
|
token
|
||||||
else:
|
)
|
||||||
response = _SESSION.post(
|
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ALARM_OFF.format(trackerId=str(tracker_id)),
|
|
||||||
headers=headers)
|
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def change_tracker_eco_mode_state(token, tracker_id, state: bool):
|
def change_tracker_eco_mode_state(token, tracker_id, state: bool):
|
||||||
""" used to toggle lock a tracker """
|
""" used to toggle eco mode state """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
endpoint = (GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_ON.format(trackerId=str(tracker_id))) if state \
|
||||||
response = None
|
else (GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_OFF.format(trackerId=str(tracker_id)))
|
||||||
if state == True:
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_ON.format(trackerId=str(tracker_id)),
|
endpoint,
|
||||||
headers=headers)
|
token
|
||||||
else:
|
)
|
||||||
response = _SESSION.post(
|
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_OFF.format(trackerId=str(tracker_id)),
|
|
||||||
headers=headers)
|
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def add_or_update_maintenance(token, tracker_id, maintenance_json):
|
||||||
|
""" used to add or update a maintenance """
|
||||||
|
response = _send_request(
|
||||||
|
"POST",
|
||||||
|
GEORIDE_API_ENDPOINT_TRACKER_MAINTENANCE.format(trackerId=str(tracker_id)),
|
||||||
|
token,
|
||||||
|
data=maintenance_json
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code == 204:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def delete_maintenance(token, tracker_id, maintenance_id):
|
||||||
|
""" used to add or update a maintenance """
|
||||||
|
response = _send_request(
|
||||||
|
"DELETE",
|
||||||
|
GEORIDE_API_ENDPOINT_TRACKER_DELETE_MAINTENANCE.format(
|
||||||
|
trackerId=str(tracker_id),
|
||||||
|
maintenanceId=str(maintenance_id)
|
||||||
|
),
|
||||||
|
token
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code == 204:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_maintenances_for_tracker(token, tracker_id):
|
||||||
|
""" used to retrieve maintenances """
|
||||||
|
response = _send_request(
|
||||||
|
"GET",
|
||||||
|
GEORIDE_API_ENDPOINT_TRACKER_MAINTENANCE.format(trackerId=str(tracker_id)),
|
||||||
|
token
|
||||||
|
)
|
||||||
|
|
||||||
|
response_data = response.json()
|
||||||
|
maintenances = []
|
||||||
|
if response.status_code == 200:
|
||||||
|
for maintenance in response_data['maintenanceList']:
|
||||||
|
maintenances.append(GeoRideMaintenance.from_json(maintenance))
|
||||||
|
return maintenances
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def shutdown_tracker(token, tracker_id):
|
def shutdown_tracker(token, tracker_id):
|
||||||
""" used to toggle lock a tracker """
|
""" used to toggle lock a tracker """
|
||||||
headers = {"Authorization": "Bearer " + token}
|
response = _send_request(
|
||||||
response = _SESSION.post(
|
"POST",
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_SHUTDOWN_TRACKER.format(trackerId=str(tracker_id)),
|
GEORIDE_API_ENDPOINT_SHUTDOWN_TRACKER.format(trackerId=str(tracker_id)),
|
||||||
headers=headers)
|
token
|
||||||
|
)
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response_data['locked']
|
return response_data['locked']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _send_request(method, endpoint, token, params=None, data=None):
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Content-Type": "application/json"} if token else {
|
||||||
|
"Content-Type": "application/json"}
|
||||||
|
endpoint_url = GEORIDE_API_HOST + endpoint
|
||||||
|
|
||||||
|
if method == "POST":
|
||||||
|
return _SESSION.post(endpoint_url, data=data, headers=headers)
|
||||||
|
elif method == "GET":
|
||||||
|
return _SESSION.get(endpoint_url, params=params, headers=headers)
|
||||||
|
elif method == "DELETE":
|
||||||
|
return _SESSION.delete(endpoint_url, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print("Not a main module")
|
print("Not a main module")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class GeoRideAccount:
|
|||||||
""" Account object representation """
|
""" Account object representation """
|
||||||
def __init__(self, account_id, email, is_admin, auth_token):
|
def __init__(self, account_id, email, is_admin, auth_token):
|
||||||
self._account_id = account_id
|
self._account_id = account_id
|
||||||
self._email = emailgit
|
self._email = email
|
||||||
self._is_admin = is_admin
|
self._is_admin = is_admin
|
||||||
self._auth_token = auth_token
|
self._auth_token = auth_token
|
||||||
|
|
||||||
|
|||||||
100
georideapilib/objects/GeoRideMaintenance.py
Normal file
100
georideapilib/objects/GeoRideMaintenance.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class GeoRideMaintenance:
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
name,
|
||||||
|
lastMaintenanceDistance,
|
||||||
|
everyMaintenance,
|
||||||
|
lastMaintenanceDate=None,
|
||||||
|
id=None,
|
||||||
|
todo=None,
|
||||||
|
trackerId=None,
|
||||||
|
dateUnitType=None,
|
||||||
|
createdAt=None,
|
||||||
|
updatedAt=None):
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.todo = todo
|
||||||
|
self.trackerId = trackerId
|
||||||
|
self.lastMaintenanceDistance = lastMaintenanceDistance
|
||||||
|
self.lastMaintenanceDate = lastMaintenanceDate
|
||||||
|
self.dateUnitType = dateUnitType
|
||||||
|
self.everyMaintenance = everyMaintenance
|
||||||
|
self.createdAt = createdAt
|
||||||
|
self.updatedAt = updatedAt
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_id(self):
|
||||||
|
return self.id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_todo(self):
|
||||||
|
return self.todo
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tracker_id(self):
|
||||||
|
return self.trackerId
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_maintenance_distance(self):
|
||||||
|
return self.lastMaintenanceDistance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_maintenance_date(self):
|
||||||
|
return self.lastMaintenanceDate
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_unit_type(self):
|
||||||
|
return self.dateUnitType
|
||||||
|
|
||||||
|
@property
|
||||||
|
def every_maintenance(self):
|
||||||
|
return self.everyMaintenance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def created_at(self):
|
||||||
|
return self.createdAt
|
||||||
|
|
||||||
|
@property
|
||||||
|
def updated_at(self):
|
||||||
|
return self.updatedAt
|
||||||
|
|
||||||
|
def to_distance_maintenance_json(self):
|
||||||
|
return json.dumps({
|
||||||
|
"name": self.name,
|
||||||
|
"everyMaintenance": self.everyMaintenance,
|
||||||
|
"lastMaintenanceDistance": self.lastMaintenanceDistance
|
||||||
|
}).encode("utf-8")
|
||||||
|
|
||||||
|
def to_date_maintenance_json(self):
|
||||||
|
return json.dumps({
|
||||||
|
"name": self.name,
|
||||||
|
"everyMaintenance": self.everyMaintenance,
|
||||||
|
"lastMaintenanceDate": self.lastMaintenanceDate,
|
||||||
|
"dateUnitType": self.dateUnitType
|
||||||
|
}).encode("utf-8")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json_obj):
|
||||||
|
"""return new object fromjson"""
|
||||||
|
return GeoRideMaintenance(
|
||||||
|
name=json_obj['name'],
|
||||||
|
id=json_obj['id'],
|
||||||
|
todo=json_obj['todo'],
|
||||||
|
trackerId=json_obj['trackerId'],
|
||||||
|
lastMaintenanceDistance=json_obj['lastMaintenanceDistance'],
|
||||||
|
lastMaintenanceDate=json_obj['lastMaintenanceDate'],
|
||||||
|
dateUnitType=json_obj['dateUnitType'],
|
||||||
|
everyMaintenance=json_obj['everyMaintenance'],
|
||||||
|
createdAt=json_obj['createdAt'],
|
||||||
|
updatedAt=json_obj['updatedAt']
|
||||||
|
)
|
||||||
@@ -462,7 +462,7 @@ class GeoRideTracker(metaclass=JsonMgtMetaClass): # pylint: disable=R0904,R0902
|
|||||||
return self._ecall_crash_mode
|
return self._ecall_crash_mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _ssistance_theft_activated(self):
|
def assistance_theft_activated(self):
|
||||||
""" assistanceTheftActivated property """
|
""" assistanceTheftActivated property """
|
||||||
return self._assistance_theft_activated
|
return self._assistance_theft_activated
|
||||||
|
|
||||||
@@ -486,13 +486,6 @@ class GeoRideTracker(metaclass=JsonMgtMetaClass): # pylint: disable=R0904,R0902
|
|||||||
def from_json(cls, json):
|
def from_json(cls, json):
|
||||||
"""return new object fromjson"""
|
"""return new object fromjson"""
|
||||||
|
|
||||||
"version": 3,
|
|
||||||
"eCallCrashMode": "default",
|
|
||||||
"assistanceTheftActivated": True,
|
|
||||||
"model": "georide-3",
|
|
||||||
"businessModel": "leasing",
|
|
||||||
"hasTheftCaseOpened": False,
|
|
||||||
|
|
||||||
return GeoRideTracker(
|
return GeoRideTracker(
|
||||||
json['trackerId'], # Mandatory
|
json['trackerId'], # Mandatory
|
||||||
json['trackerName'], # Mandatory
|
json['trackerName'], # Mandatory
|
||||||
@@ -502,26 +495,26 @@ class GeoRideTracker(metaclass=JsonMgtMetaClass): # pylint: disable=R0904,R0902
|
|||||||
cls.json_field_protect(json,'isOldTracker', False),
|
cls.json_field_protect(json,'isOldTracker', False),
|
||||||
cls.json_field_protect(json,'autoLockFreezedTo'),
|
cls.json_field_protect(json,'autoLockFreezedTo'),
|
||||||
cls.json_field_protect(json,'fixtime'),
|
cls.json_field_protect(json,'fixtime'),
|
||||||
json['role'], # Mandatory
|
cls.json_field_protect(json,'role', "owner"),
|
||||||
json['lastPaymentDate'],# Mandatory
|
cls.json_field_protect(json,'lastPaymentDate', None),
|
||||||
cls.json_field_protect(json,'giftCardId'),
|
cls.json_field_protect(json,'giftCardId'),
|
||||||
cls.json_field_protect(json,'expires'),
|
cls.json_field_protect(json,'expires'),
|
||||||
cls.json_field_protect(json,'activationDate'),
|
cls.json_field_protect(json,'activationDate'),
|
||||||
json['odometer'],#Mandatory
|
cls.json_field_protect(json,'odometer', False),
|
||||||
cls.json_field_protect(json,'isStolen', False),
|
cls.json_field_protect(json,'isStolen', False),
|
||||||
cls.json_field_protect(json,'isCrashed', False),
|
cls.json_field_protect(json,'isCrashed', False),
|
||||||
cls.json_field_protect(json,'crashDetectionDisabled'),
|
cls.json_field_protect(json,'crashDetectionDisabled'),
|
||||||
json['speed'], # Mandatory
|
cls.json_field_protect(json,'speed', 0), # Mandatory
|
||||||
json['moving'], # Mandatory
|
cls.json_field_protect(json,'moving', False),
|
||||||
cls.json_field_protect(json,'positionId', -1),
|
cls.json_field_protect(json,'positionId', -1),
|
||||||
json['latitude'], # Mandatory
|
cls.json_field_protect(json,'latitude', 47.0),
|
||||||
json['longitude'], # Mandatory
|
cls.json_field_protect(json,'longitude', -1.0),
|
||||||
cls.json_field_protect(json,'altitude', 0),
|
cls.json_field_protect(json,'altitude', 0),
|
||||||
cls.json_field_protect(json,'lockedPositionId'),
|
cls.json_field_protect(json,'lockedPositionId'),
|
||||||
cls.json_field_protect(json,'lockedLatitude'),
|
cls.json_field_protect(json,'lockedLatitude'),
|
||||||
cls.json_field_protect(json,'lockedLongitude'),
|
cls.json_field_protect(json,'lockedLongitude'),
|
||||||
json['isLocked'], # Mandatory
|
cls.json_field_protect(json,'isLocked', False),
|
||||||
json['canSeePosition'],# Mandatory
|
cls.json_field_protect(json,'canSeePosition', False),
|
||||||
cls.json_field_protect(json,'canLock', False),
|
cls.json_field_protect(json,'canLock', False),
|
||||||
cls.json_field_protect(json,'canUnlock', False),
|
cls.json_field_protect(json,'canUnlock', False),
|
||||||
cls.json_field_protect(json,'canShare', False),
|
cls.json_field_protect(json,'canShare', False),
|
||||||
@@ -530,7 +523,7 @@ class GeoRideTracker(metaclass=JsonMgtMetaClass): # pylint: disable=R0904,R0902
|
|||||||
cls.json_field_protect(json,'canSeeStatistics', False),
|
cls.json_field_protect(json,'canSeeStatistics', False),
|
||||||
cls.json_field_protect(json,'canSendBrokenDownSignal', False),
|
cls.json_field_protect(json,'canSendBrokenDownSignal', False),
|
||||||
cls.json_field_protect(json,'canSendStolenSignal', False),
|
cls.json_field_protect(json,'canSendStolenSignal', False),
|
||||||
json['status'],# Mandatory
|
cls.json_field_protect(json,'status', 'unknown'),
|
||||||
cls.json_field_protect(json,'subscriptionId', -1),
|
cls.json_field_protect(json,'subscriptionId', -1),
|
||||||
cls.json_field_protect(json,'externalBatteryVoltage', -1.0),
|
cls.json_field_protect(json,'externalBatteryVoltage', -1.0),
|
||||||
cls.json_field_protect(json,'internalBatteryVoltage', -1.0),
|
cls.json_field_protect(json,'internalBatteryVoltage', -1.0),
|
||||||
@@ -550,7 +543,12 @@ class GeoRideTracker(metaclass=JsonMgtMetaClass): # pylint: disable=R0904,R0902
|
|||||||
cls.json_field_protect(json,'softwareVersion', 1),
|
cls.json_field_protect(json,'softwareVersion', 1),
|
||||||
cls.json_field_protect(json,'hasBeacon', False),
|
cls.json_field_protect(json,'hasBeacon', False),
|
||||||
cls.json_field_protect(json,'hasOutdatedBeacons', False),
|
cls.json_field_protect(json,'hasOutdatedBeacons', False),
|
||||||
cls.json_field_protect(json,'eCallActivated', False)
|
cls.json_field_protect(json,'eCallActivated', False),
|
||||||
|
cls.json_field_protect(json,'eCallCrashMode'),
|
||||||
|
cls.json_field_protect(json,'assistanceTheftActivated'),
|
||||||
|
cls.json_field_protect(json,'model'),
|
||||||
|
cls.json_field_protect(json,'businessModel'),
|
||||||
|
cls.json_field_protect(json,'hasTheftCaseOpened'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_all_data(self, tracker):
|
def update_all_data(self, tracker):
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ from .GeoRideTrackerBeacon import *
|
|||||||
from .GeoRideTrackerPosition import *
|
from .GeoRideTrackerPosition import *
|
||||||
from .GeoRideTrackerTrip import *
|
from .GeoRideTrackerTrip import *
|
||||||
from .GeoRideUser import *
|
from .GeoRideUser import *
|
||||||
|
from .GeoRideMaintenance import *
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import socketio
|
import socketio
|
||||||
|
|
||||||
from georideapilib.api import GEORIDE_API_HOST
|
from georideapilib.api import GEORIDE_SOCKET_HOST
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
sio = socketio.Client(reconnection=True) # pylint: disable=C0103
|
sio = socketio.Client(reconnection=True, reconnection_attempts=5, reconnection_delay=1000, reconnection_delay_max=5000, randomization_factor=0.5) # pylint: disable=C0103
|
||||||
|
|
||||||
@sio.on('connect')
|
@sio.on('connect')
|
||||||
def on_connect():
|
def on_connect():
|
||||||
@@ -104,8 +104,9 @@ class GeoRideSocket():
|
|||||||
def connect(self, auth_token):
|
def connect(self, auth_token):
|
||||||
""" connect to the georide socket"""
|
""" connect to the georide socket"""
|
||||||
if self._initialised is not False:
|
if self._initialised is not False:
|
||||||
sio.connect(GEORIDE_API_HOST, headers={'token': auth_token})
|
sio.connect(GEORIDE_SOCKET_HOST, headers={'token': auth_token})
|
||||||
sio.wait()
|
sio.wait()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Please call init() before")
|
_LOGGER.error("Please call init() before")
|
||||||
|
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -19,13 +19,13 @@ CURRENT_DIR = os.path.dirname(__file__)
|
|||||||
setup(
|
setup(
|
||||||
name='georideapilib',
|
name='georideapilib',
|
||||||
packages=['georideapilib', 'georideapilib.objects'], # this must be the same as the name above
|
packages=['georideapilib', 'georideapilib.objects'], # this must be the same as the name above
|
||||||
version='0.9.0',
|
version='1.2.0',
|
||||||
description='Lib to control GeoRide tracker devices with theire rest api',
|
description='Lib to control GeoRide tracker devices with theire rest api',
|
||||||
author='Matthieu DUVAL',
|
author='Matthieu DUVAL',
|
||||||
author_email='georideapilib@duval-dev.fr',
|
author_email='georideapilib@duval-dev.fr',
|
||||||
# use the URL to the github repo
|
# use the URL to the github repo
|
||||||
url='https://github.com/hacf/georide-api',
|
url='https://github.com/hacf/georide-api',
|
||||||
download_url='https://codeload.github.com/hacf/georide-api/tar.gz/0.8.1',
|
download_url='https://codeload.github.com/hacf/georide-api/tar.gz/1.0.0',
|
||||||
keywords=['rest', 'georide', 'api', 'grutier', 'GeoRide'], # arbitrary keywords
|
keywords=['rest', 'georide', 'api', 'grutier', 'GeoRide'], # arbitrary keywords
|
||||||
classifiers=[],
|
classifiers=[],
|
||||||
install_requires=["python-socketio[client]==4.6.1"],
|
install_requires=["python-socketio[client]==4.6.1"],
|
||||||
|
|||||||
Reference in New Issue
Block a user