Compare commits
26 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 | |||
| 39b2c3c776 | |||
|
|
7e399cf982 |
@@ -1,9 +1,7 @@
|
|||||||
""" Example georideapilib code """
|
""" Example georideapilib code """
|
||||||
|
import logging.config
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
logging.config.fileConfig('logging.conf')
|
logging.config.fileConfig('logging.conf')
|
||||||
from georideapilib.objects import GeoRideAccount
|
from georideapilib.objects import GeoRideAccount
|
||||||
import georideapilib.api as GeoRideApi
|
import georideapilib.api as GeoRideApi
|
||||||
@@ -13,11 +11,13 @@ from threading import Thread
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger('example')
|
_LOGGER = logging.getLogger('example')
|
||||||
|
|
||||||
|
DATE_START="2019-10-10"
|
||||||
|
DATE_END="2019-10-24"
|
||||||
|
|
||||||
def example():
|
def example():
|
||||||
""" simple example function """
|
""" simple example function """
|
||||||
# token = "<your_token>"# pylint: disable=C0301
|
# token = "<your_token>"# pylint: disable=C0301
|
||||||
# account = GeorideAccount(0, "<your_email>", False, token)
|
# account = GeoRideAccount(0, "<your_email>", False, token)
|
||||||
|
|
||||||
|
|
||||||
account = GeoRideApi.get_authorisation_token("<your_email>", "<your_password>")
|
account = GeoRideApi.get_authorisation_token("<your_email>", "<your_password>")
|
||||||
@@ -40,7 +40,7 @@ def example():
|
|||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
|
|
||||||
thread = Thread(target=connect_socket, args=(account))
|
thread = Thread(target=connect_socket, args=[account])
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -55,21 +55,26 @@ def example():
|
|||||||
tracker = trackers[0]
|
tracker = trackers[0]
|
||||||
_LOGGER.info("Tracker name: %s", tracker.tracker_name)
|
_LOGGER.info("Tracker name: %s", tracker.tracker_name)
|
||||||
|
|
||||||
trips = GeoRideApi.get_trips(account.auth_token, tracker.tracker_id, "2019-10-10", "2019-10-24")
|
trips = GeoRideApi.get_trips(account.auth_token, tracker.tracker_id, DATE_START, DATE_END)
|
||||||
trip = trips[0]
|
if len(trips) < 1:
|
||||||
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
_LOGGER.info("No trip found for tracker name: %s between: %s and %s", tracker.tracker_name, DATE_START, DATE_END)
|
||||||
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
|
else:
|
||||||
trip.nice_end_address)
|
trip = trips[0]
|
||||||
|
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
|
||||||
|
trip.nice_end_address)
|
||||||
|
|
||||||
positions = GeoRideApi.get_positions(account.auth_token, tracker.tracker_id,
|
positions = GeoRideApi.get_positions(account.auth_token, tracker.tracker_id,
|
||||||
"2019-10-10", "2019-10-24")
|
DATE_START, DATE_END)
|
||||||
position = positions[0]
|
if len(positions) < 1:
|
||||||
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
|
_LOGGER.info("No positions found for tracker name: %s between: %s and %s", tracker.tracker_name, DATE_START, DATE_END)
|
||||||
position.latitude)
|
else:
|
||||||
|
position = positions[0]
|
||||||
|
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
|
||||||
|
position.latitude)
|
||||||
|
|
||||||
trip_shared = GeoRideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
|
trip_shared = GeoRideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
|
||||||
"2019-10-10", "2019-10-24")
|
DATE_START, DATE_END)
|
||||||
_LOGGER.info("tripShared url: %s, id: %s", trip_shared.url, trip_shared.share_id)
|
_LOGGER.info("tripShared url: %s, id: %s", trip_shared.url, trip_shared.share_id)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|||||||
@@ -5,56 +5,63 @@ Georide api lib
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import requests
|
|
||||||
|
|
||||||
from georideapilib.objects import (
|
import requests
|
||||||
GeoRideTracker,
|
|
||||||
GeoRideAccount,
|
|
||||||
GeoRideUser,
|
|
||||||
GeoRideTrackerTrip,
|
|
||||||
GeoRideTrackerPosition,
|
|
||||||
GeoRideSharedTrip,
|
|
||||||
GeoRideTrackerBeacon
|
|
||||||
)
|
|
||||||
|
|
||||||
from georideapilib.exception import (
|
from georideapilib.exception import (
|
||||||
LoginException,
|
LoginException,
|
||||||
SeverException,
|
SeverException,
|
||||||
UnauthorizedException
|
UnauthorizedException
|
||||||
)
|
)
|
||||||
|
from georideapilib.objects import (
|
||||||
|
GeoRideTracker,
|
||||||
|
GeoRideAccount,
|
||||||
|
GeoRideUser,
|
||||||
|
GeoRideTrackerTrip,
|
||||||
|
GeoRideTrackerPosition,
|
||||||
|
GeoRideSharedTrip,
|
||||||
|
GeoRideTrackerBeacon,
|
||||||
|
GeoRideMaintenance
|
||||||
|
)
|
||||||
|
|
||||||
GEORIDE_API_HOST = "https://api.georide.fr"
|
GEORIDE_API_HOST = "https://api.georide.com"
|
||||||
|
GEORIDE_SOCKET_HOST = "https://socket.georide.com"
|
||||||
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"
|
||||||
GEORIDE_API_ENDPOINT_USER = "/user"
|
GEORIDE_API_ENDPOINT_USER = "/user"
|
||||||
GEORIDE_API_ENDPOINT_TRACKERS = "/user/trackers"
|
GEORIDE_API_ENDPOINT_TRACKERS = "/user/trackers"
|
||||||
GEORIDE_API_ENDPOINT_TRIPS = "/tracker/:trackerId/trips"
|
GEORIDE_API_ENDPOINT_TRIPS = "/tracker/{trackerId}/trips"
|
||||||
GEORIDE_API_ENDPOINT_LOCK = "/tracker/:trackerId/lock"
|
GEORIDE_API_ENDPOINT_LOCK = "/tracker/{trackerId}/lock"
|
||||||
GEORIDE_API_ENDPOINT_TRACKER_BEACON = "/tracker/:trackerId/beacon"
|
GEORIDE_API_ENDPOINT_TRACKER_BEACON = "/tracker/{trackerId}/beacon"
|
||||||
GEORIDE_API_ENDPOINT_UNLOCK = "/tracker/:trackerId/unlock"
|
GEORIDE_API_ENDPOINT_UNLOCK = "/tracker/{trackerId}/unlock"
|
||||||
GEORIDE_API_ENDPOINT_TOGGLE_LOCK = "/tracker/:trackerId/toggleLock"
|
GEORIDE_API_ENDPOINT_TOGGLE_LOCK = "/tracker/{trackerId}/toggleLock"
|
||||||
GEORIDE_API_ENDPOINT_POSITIONS = "/tracker/:trackerId/trips/positions"
|
GEORIDE_API_ENDPOINT_POSITIONS = "/tracker/{trackerId}/trips/positions"
|
||||||
GEORIDE_API_ENDPOINT_TRIP_SHARE = "/tracker/:trackerId/share/trip"
|
GEORIDE_API_ENDPOINT_TRIP_SHARE = "/tracker/{trackerId}/share/trip"
|
||||||
GEORIDE_API_ENDPOINT_SHUTDOWN_TRACKER = "/tracker/:trackerId/shutdown"
|
GEORIDE_API_ENDPOINT_SHUTDOWN_TRACKER = "/tracker/{trackerId}/shutdown"
|
||||||
GEORIDE_API_ENDPOINT_TRACKER_ALARM_OFF = "/tracker/:trackerId/sonor-alarm/off"
|
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")
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
@@ -64,63 +71,68 @@ def get_authorisation_token(email, password):
|
|||||||
raise LoginException(get_authorisation_token, "Login failed")
|
raise LoginException(get_authorisation_token, "Login failed")
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
||||||
raise SeverException(get_authorisation_token,
|
raise SeverException(get_authorisation_token,
|
||||||
"Georide login, http error code: {}".format(response.status_code))
|
"Georide login, http error code: {}".format(response.status_code))
|
||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
raise SeverException(renew_token,
|
raise SeverException(renew_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 == 401:
|
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 = []
|
||||||
@@ -129,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.replace(':trackerId', str(tracker_id)),
|
token
|
||||||
headers=headers)
|
)
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
trackers_beacons = []
|
trackers_beacons = []
|
||||||
@@ -146,48 +159,58 @@ 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.replace(':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 = []
|
||||||
for json_trip in response_data:
|
if response.status_code == 200:
|
||||||
trips.append(GeoRideTrackerTrip.from_json(json_trip))
|
for json_trip in response_data:
|
||||||
|
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.replace(':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 = []
|
||||||
for json_position in response_data:
|
if response.status_code == 200:
|
||||||
positions.append(GeoRideTrackerPosition.from_json(json_position))
|
for json_position in response_data:
|
||||||
|
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
|
|
||||||
to_date=None, trip_merged_id=None):
|
def _share_a_trip(token, tracker_id, trip_id=None, from_date=None, # pylint: disable= R0913
|
||||||
|
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 """
|
||||||
data = None
|
data = None
|
||||||
if trip_id is not None:
|
if trip_id is not None:
|
||||||
@@ -199,87 +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.replace(':trackerId', str(tracker_id)),
|
)
|
||||||
data=encoded_data,
|
|
||||||
headers=headers)
|
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
return GeoRideSharedTrip.from_json(response_data)
|
if response.status_code == 200:
|
||||||
|
return GeoRideSharedTrip.from_json(response_data)
|
||||||
|
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.replace(':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.replace(':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.replace(':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.replace(':trackerId', str(tracker_id)),
|
endpoint,
|
||||||
headers=headers)
|
token
|
||||||
else:
|
)
|
||||||
response = _SESSION.post(
|
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ALARM_OFF.replace(':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.replace(':trackerId', str(tracker_id)),
|
endpoint,
|
||||||
headers=headers)
|
token
|
||||||
else:
|
)
|
||||||
response = _SESSION.post(
|
|
||||||
GEORIDE_API_HOST + GEORIDE_API_ENDPOINT_TRACKER_ECO_MODE_OFF.replace(':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.replace(':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()
|
||||||
return response_data['locked']
|
if response.status_code == 200:
|
||||||
|
return response_data['locked']
|
||||||
|
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")
|
||||||
|
|||||||
51
georideapilib/objects/GeoRideAccount.py
Normal file
51
georideapilib/objects/GeoRideAccount.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideAccount:
|
||||||
|
""" Account object representation """
|
||||||
|
def __init__(self, account_id, email, is_admin, auth_token):
|
||||||
|
self._account_id = account_id
|
||||||
|
self._email = email
|
||||||
|
self._is_admin = is_admin
|
||||||
|
self._auth_token = auth_token
|
||||||
|
|
||||||
|
@property
|
||||||
|
def account_id(self):
|
||||||
|
""" account_id """
|
||||||
|
return self._account_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email(self):
|
||||||
|
""" email """
|
||||||
|
return self._email
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_admin(self):
|
||||||
|
""" is_admin """
|
||||||
|
return self._is_admin
|
||||||
|
|
||||||
|
@property
|
||||||
|
def auth_token(self):
|
||||||
|
""" auth_token """
|
||||||
|
return self._auth_token
|
||||||
|
|
||||||
|
@auth_token.setter
|
||||||
|
def auth_token(self, new_token):
|
||||||
|
""" change auth_token """
|
||||||
|
self._auth_token = new_token
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json):
|
||||||
|
"""return new object from_json"""
|
||||||
|
return GeoRideAccount(
|
||||||
|
json['id'],
|
||||||
|
json['email'],
|
||||||
|
json['isAdmin'],
|
||||||
|
json['authToken']
|
||||||
|
)
|
||||||
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']
|
||||||
|
)
|
||||||
33
georideapilib/objects/GeoRideSharedTrip.py
Normal file
33
georideapilib/objects/GeoRideSharedTrip.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideSharedTrip:
|
||||||
|
""" Shared trip object representation """
|
||||||
|
def __init__(self, url, shareId):
|
||||||
|
self._url = url
|
||||||
|
self._share_id = shareId
|
||||||
|
|
||||||
|
@property
|
||||||
|
def url(self):
|
||||||
|
""" shared trip url """
|
||||||
|
return self._url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def share_id(self):
|
||||||
|
""" shared trip id """
|
||||||
|
return self._share_id
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json):
|
||||||
|
"""return new object fromjson"""
|
||||||
|
return GeoRideSharedTrip(
|
||||||
|
json['url'],
|
||||||
|
json['shareId']
|
||||||
|
)
|
||||||
98
georideapilib/objects/GeoRideSubscription.py
Normal file
98
georideapilib/objects/GeoRideSubscription.py
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
from . import JsonMgtMetaClass, GeoRideSubscription_CardInfo
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideSubscription(metaclass=JsonMgtMetaClass):
|
||||||
|
""" Account object representation """
|
||||||
|
def __init__(self, subscription_id, subscription_type, initial_date, next_payment_date,
|
||||||
|
status, paused_since, cancel_requested, price, first_name, last_name, card_information):
|
||||||
|
self._subscription_id = subscription_id
|
||||||
|
self._subscription_type = subscription_type
|
||||||
|
self._initial_date = initial_date
|
||||||
|
self._next_payment_date = next_payment_date
|
||||||
|
self._status = status
|
||||||
|
self._paused_since = paused_since
|
||||||
|
self._cancel_requested = cancel_requested
|
||||||
|
self._price = price
|
||||||
|
self._first_name = first_name
|
||||||
|
self._last_name = last_name
|
||||||
|
self._card_information = card_information
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subscription_id(self):
|
||||||
|
"""subscription_id property"""
|
||||||
|
return self._subscription_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subscription_type(self):
|
||||||
|
"""subscription_type property"""
|
||||||
|
return self._subscription_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def initial_date(self):
|
||||||
|
"""initial_date property"""
|
||||||
|
return self._initial_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def next_payment_date(self):
|
||||||
|
"""next_payment_date property"""
|
||||||
|
return self._next_payment_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
"""status property"""
|
||||||
|
return self._status
|
||||||
|
|
||||||
|
@property
|
||||||
|
def paused_since(self):
|
||||||
|
"""paused_since property"""
|
||||||
|
return self._paused_since
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cancel_requested(self):
|
||||||
|
"""cancel_requested property"""
|
||||||
|
return self._cancel_requested
|
||||||
|
|
||||||
|
@property
|
||||||
|
def price(self):
|
||||||
|
"""price property"""
|
||||||
|
return self._price
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first_name(self):
|
||||||
|
"""first_name property"""
|
||||||
|
return self._first_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_name(self):
|
||||||
|
"""last_name property"""
|
||||||
|
return self._last_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def card_information(self):
|
||||||
|
"""card_information property"""
|
||||||
|
return self._card_information
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json):
|
||||||
|
"""return new object from_json"""
|
||||||
|
card_info = GeoRideSubscription_CardInfo.from_json(json['cardInformation']) if cls.json_field_protect(json, 'cardInformation', None) is not None else {}
|
||||||
|
return GeoRideSubscription(
|
||||||
|
cls.json_field_protect(json, 'id', -1),
|
||||||
|
json['type'],
|
||||||
|
cls.json_field_protect(json, 'initialDate'),
|
||||||
|
cls.json_field_protect(json, 'nextPaymentDate'),
|
||||||
|
cls.json_field_protect(json, 'status'),
|
||||||
|
cls.json_field_protect(json, 'pausedSince'),
|
||||||
|
cls.json_field_protect(json, 'cancelRequested'),
|
||||||
|
cls.json_field_protect(json, 'price'),
|
||||||
|
cls.json_field_protect(json, 'firstName'),
|
||||||
|
cls.json_field_protect(json, 'lastName'),
|
||||||
|
card_info
|
||||||
|
)
|
||||||
41
georideapilib/objects/GeoRideSubscription_CardInfo.py
Normal file
41
georideapilib/objects/GeoRideSubscription_CardInfo.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
from . import JsonMgtMetaClass
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideSubscription_CardInfo(metaclass=JsonMgtMetaClass):
|
||||||
|
""" Account object representation """
|
||||||
|
def __init__(self, last_digits, expiry, brand):
|
||||||
|
self._last_digits = last_digits
|
||||||
|
self._expiry = expiry
|
||||||
|
self._brand = brand
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_digits(self):
|
||||||
|
"""last_digits property"""
|
||||||
|
return self._last_digits
|
||||||
|
|
||||||
|
@property
|
||||||
|
def expiry(self):
|
||||||
|
"""expiry property"""
|
||||||
|
return self._expiry
|
||||||
|
|
||||||
|
@property
|
||||||
|
def brand(self):
|
||||||
|
"""brand property"""
|
||||||
|
return self._brand
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json):
|
||||||
|
"""return new object from_json"""
|
||||||
|
return GeoRideSubscription_CardInfo(
|
||||||
|
cls.json_field_protect(json, 'lastDigits'),
|
||||||
|
cls.json_field_protect(json, 'expiry'),
|
||||||
|
cls.json_field_protect(json, 'brand')
|
||||||
|
)
|
||||||
File diff suppressed because it is too large
Load Diff
115
georideapilib/objects/GeoRideTrackerBeacon.py
Normal file
115
georideapilib/objects/GeoRideTrackerBeacon.py
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
from . import JsonMgtMetaClass
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideTrackerBeacon:
|
||||||
|
""" GeoRideTrackerBeacon representation """
|
||||||
|
def __init__(self, beacon_id, linked_tracker_id, name, created_at, updated_at,
|
||||||
|
mac_address, battery_level, last_battery_level_update, sleep_delay,
|
||||||
|
is_updated, power):
|
||||||
|
self._beacon_id = beacon_id
|
||||||
|
self._linked_tracker_id = linked_tracker_id
|
||||||
|
self._name = name
|
||||||
|
self._created_at = created_at
|
||||||
|
self._updated_at = updated_at
|
||||||
|
self._mac_address = mac_address
|
||||||
|
self._battery_level = battery_level
|
||||||
|
self._last_battery_level_update = last_battery_level_update
|
||||||
|
self._sleep_delay = sleep_delay
|
||||||
|
self._is_updated = is_updated
|
||||||
|
self._power = power
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def linked_tracker_id(self):
|
||||||
|
""" linked_tracker_id property """
|
||||||
|
return self._linked_tracker_id
|
||||||
|
|
||||||
|
@linked_tracker_id.setter
|
||||||
|
def linked_tracker_id(self, linked_tracker_id):
|
||||||
|
""" linked_tracker_id setter """
|
||||||
|
self._linked_tracker_id = linked_tracker_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def beacon_id(self):
|
||||||
|
"""beacon_id property"""
|
||||||
|
return self._beacon_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""name property"""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def created_at(self):
|
||||||
|
"""created_at property"""
|
||||||
|
return self._created_at
|
||||||
|
|
||||||
|
@property
|
||||||
|
def updated_at(self):
|
||||||
|
"""updated_at property"""
|
||||||
|
return self._updated_at
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mac_address(self):
|
||||||
|
"""mac_address property"""
|
||||||
|
return self._mac_address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def battery_level(self):
|
||||||
|
"""battery_level property"""
|
||||||
|
return self._battery_level
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_battery_level_update(self):
|
||||||
|
"""last_battery_level_update property"""
|
||||||
|
return self._last_battery_level_update
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sleep_delay(self):
|
||||||
|
"""sleep_delay property"""
|
||||||
|
return self._sleep_delay
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_updated(self):
|
||||||
|
"""is_updated property"""
|
||||||
|
return self._is_updated
|
||||||
|
|
||||||
|
@property
|
||||||
|
def power(self):
|
||||||
|
"""power property"""
|
||||||
|
return self._power
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json):
|
||||||
|
"""return new object from_json"""
|
||||||
|
return GeoRideTrackerBeacon(
|
||||||
|
json['id'],
|
||||||
|
json['linked_tracker_id'],
|
||||||
|
json['name'],
|
||||||
|
json['createdAt'],
|
||||||
|
json['updatedAt'],
|
||||||
|
json['macAddress'],
|
||||||
|
json['batteryLevel'],
|
||||||
|
json['lastBatteryLevelUpdate'],
|
||||||
|
json['sleepDelay'],
|
||||||
|
json['isUpdated'],
|
||||||
|
json['power'])
|
||||||
|
|
||||||
|
def update_all_data(self, tracker_beacon):
|
||||||
|
"""update all data of the tracker beacon from a new object"""
|
||||||
|
self._name = tracker_beacon.name
|
||||||
|
self._created_at = tracker_beacon.created_at
|
||||||
|
self._updated_at = tracker_beacon.updated_at
|
||||||
|
self._mac_address = tracker_beacon.mac_address
|
||||||
|
self._battery_level = tracker_beacon.battery_level
|
||||||
|
self._last_battery_level_update = tracker_beacon.last_battery_level_update
|
||||||
|
self._sleep_delay = tracker_beacon.sleep_delay
|
||||||
|
self._is_updated = tracker_beacon.is_updated
|
||||||
|
self._power = tracker_beacon.power
|
||||||
60
georideapilib/objects/GeoRideTrackerPosition.py
Normal file
60
georideapilib/objects/GeoRideTrackerPosition.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideTrackerPosition:
|
||||||
|
""" Tracker position object representation """
|
||||||
|
def __init__(self, fixtime, latitude, longitude, altitude, speed, address): # pylint: disable= R0913
|
||||||
|
self._fixtime = fixtime
|
||||||
|
self._latitude = latitude
|
||||||
|
self._longitude = longitude
|
||||||
|
self._altitude = altitude
|
||||||
|
self._speed = speed
|
||||||
|
self._address = address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fixtime(self):
|
||||||
|
""" fixtime """
|
||||||
|
return self._fixtime
|
||||||
|
|
||||||
|
@property
|
||||||
|
def latitude(self):
|
||||||
|
""" latitude """
|
||||||
|
return self._latitude
|
||||||
|
|
||||||
|
@property
|
||||||
|
def longitude(self):
|
||||||
|
""" longitude """
|
||||||
|
return self._longitude
|
||||||
|
|
||||||
|
@property
|
||||||
|
def altitude(self):
|
||||||
|
""" altitude """
|
||||||
|
return self._altitude
|
||||||
|
|
||||||
|
@property
|
||||||
|
def speed(self):
|
||||||
|
""" speed (m/s) """
|
||||||
|
return self._speed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def address(self):
|
||||||
|
""" address """
|
||||||
|
return self._address
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json):
|
||||||
|
"""return new object fromjson"""
|
||||||
|
return GeoRideTrackerPosition(
|
||||||
|
json['fixtime'],
|
||||||
|
json['latitude'],
|
||||||
|
json['longitude'],
|
||||||
|
json['altitude'],
|
||||||
|
json['speed'],
|
||||||
|
json['address']
|
||||||
|
)
|
||||||
134
georideapilib/objects/GeoRideTrackerTrip.py
Normal file
134
georideapilib/objects/GeoRideTrackerTrip.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideTrackerTrip: # pylint: disable=too-many-instance-attributes
|
||||||
|
""" Trip object representation """
|
||||||
|
def __init__(self, trip_id, tracker_id, average_speed, max_speed, distance, duration, # pylint: disable=R0914, R0913
|
||||||
|
start_address, nice_start_address, start_lat, start_lon, end_address,
|
||||||
|
nice_end_address, end_lat, end_lon, start_time, end_time):
|
||||||
|
self._trip_id = trip_id
|
||||||
|
self._tracker_id = tracker_id
|
||||||
|
self._average_speed = average_speed
|
||||||
|
self._max_speed = max_speed
|
||||||
|
self._distance = distance
|
||||||
|
self._duration = duration
|
||||||
|
self._start_address = start_address
|
||||||
|
self._nice_start_address = nice_start_address
|
||||||
|
self._start_lat = start_lat
|
||||||
|
self._start_lon = start_lon
|
||||||
|
self._end_address = end_address
|
||||||
|
self._nice_end_address = nice_end_address
|
||||||
|
self._end_lat = end_lat
|
||||||
|
self._end_lon = end_lon
|
||||||
|
self._start_time = start_time
|
||||||
|
self._end_time = end_time
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def trip_id(self):
|
||||||
|
"""trip_id """
|
||||||
|
return self._trip_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tracker_id(self):
|
||||||
|
""" tracker_id """
|
||||||
|
return self._tracker_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def average_speed(self):
|
||||||
|
""" average_speed """
|
||||||
|
return self._average_speed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_speed(self):
|
||||||
|
""" max_speed """
|
||||||
|
return self._max_speed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def distance(self):
|
||||||
|
""" distance """
|
||||||
|
return self._distance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def duration(self):
|
||||||
|
""" duration """
|
||||||
|
return self._duration
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_address(self):
|
||||||
|
""" start_address """
|
||||||
|
return self._start_address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nice_start_address(self):
|
||||||
|
""" nice_start_address """
|
||||||
|
return self._nice_start_address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_lat(self):
|
||||||
|
""" start_lat """
|
||||||
|
return self._start_lat
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_lon(self):
|
||||||
|
""" start_lon """
|
||||||
|
return self._start_lon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_address(self):
|
||||||
|
""" end_address """
|
||||||
|
return self._end_address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nice_end_address(self):
|
||||||
|
""" nice_end_address """
|
||||||
|
return self._nice_end_address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_lat(self):
|
||||||
|
"""end_lat """
|
||||||
|
return self._end_lat
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_lon(self):
|
||||||
|
"""end_lon """
|
||||||
|
return self._end_lon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_time(self):
|
||||||
|
""" start_time """
|
||||||
|
return self._start_time
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_time(self):
|
||||||
|
""" end_time """
|
||||||
|
return self._end_time
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json):
|
||||||
|
"""return new object from json"""
|
||||||
|
return GeoRideTrackerTrip(
|
||||||
|
json['id'],
|
||||||
|
json['trackerId'],
|
||||||
|
json['averageSpeed'],
|
||||||
|
json['maxSpeed'],
|
||||||
|
json['distance'],
|
||||||
|
json['duration'],
|
||||||
|
json['startAddress'],
|
||||||
|
json['niceStartAddress'],
|
||||||
|
json['startLat'],
|
||||||
|
json['startLon'],
|
||||||
|
json['endAddress'],
|
||||||
|
json['niceEndAddress'],
|
||||||
|
json['endLat'],
|
||||||
|
json['endLon'],
|
||||||
|
json['startTime'],
|
||||||
|
json['endTime']
|
||||||
|
)
|
||||||
75
georideapilib/objects/GeoRideUser.py
Normal file
75
georideapilib/objects/GeoRideUser.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class GeoRideUser: # pylint: disable= R0902
|
||||||
|
""" User object representation """
|
||||||
|
def __init__(self, user_id, email, first_name, created_at, phone_number, # pylint: disable= R0913
|
||||||
|
push_user_token, legal, date_of_birth):
|
||||||
|
self._user_id = user_id
|
||||||
|
self._email = email
|
||||||
|
self._first_name = first_name
|
||||||
|
self._created_at = created_at
|
||||||
|
self._phone_number = phone_number
|
||||||
|
self._push_user_token = push_user_token
|
||||||
|
self._legal = legal
|
||||||
|
self._date_of_birth = date_of_birth
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_id(self):
|
||||||
|
""" user_id """
|
||||||
|
return self._user_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email(self):
|
||||||
|
""" email """
|
||||||
|
return self._email
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first_name(self):
|
||||||
|
""" first_name """
|
||||||
|
return self._first_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def created_at(self):
|
||||||
|
""" created_at """
|
||||||
|
return self._created_at
|
||||||
|
|
||||||
|
@property
|
||||||
|
def phone_number(self):
|
||||||
|
""" phone_number """
|
||||||
|
return self._phone_number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def push_user_token(self):
|
||||||
|
""" push_user_token """
|
||||||
|
return self._push_user_token
|
||||||
|
|
||||||
|
@property
|
||||||
|
def legal(self):
|
||||||
|
""" legal """
|
||||||
|
return self._legal
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_of_birth(self):
|
||||||
|
""" date_ofo_birth """
|
||||||
|
return self._date_of_birth
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(json):
|
||||||
|
"""return new object fromjson"""
|
||||||
|
return GeoRideUser(
|
||||||
|
json['id'],
|
||||||
|
json['email'],
|
||||||
|
json['firstName'],
|
||||||
|
json['createdAt'],
|
||||||
|
json['phoneNumber'],
|
||||||
|
json['pushUserToken'],
|
||||||
|
json['legal'],
|
||||||
|
json['dateOfBirth']
|
||||||
|
)
|
||||||
13
georideapilib/objects/JsonMgtMetaClass.py
Normal file
13
georideapilib/objects/JsonMgtMetaClass.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Georide objects implementation
|
||||||
|
@author Matthieu DUVAL <matthieu@duval-dev.fr>
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class JsonMgtMetaClass(type):
|
||||||
|
@staticmethod
|
||||||
|
def json_field_protect(json, field_name, default_value = None):
|
||||||
|
return json[field_name] if field_name in json.keys() else default_value
|
||||||
12
georideapilib/objects/__init__.py
Normal file
12
georideapilib/objects/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from .JsonMgtMetaClass import *
|
||||||
|
from .GeoRideAccount import *
|
||||||
|
from .GeoRideSharedTrip import *
|
||||||
|
from .GeoRideSubscription_CardInfo import *
|
||||||
|
from .GeoRideSubscription import *
|
||||||
|
from .GeoRideTracker import *
|
||||||
|
from .GeoRideTrackerBeacon import *
|
||||||
|
from .GeoRideTrackerPosition import *
|
||||||
|
from .GeoRideTrackerTrip 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")
|
||||||
|
|
||||||
|
|||||||
10
setup.py
10
setup.py
@@ -18,23 +18,23 @@ CURRENT_DIR = os.path.dirname(__file__)
|
|||||||
# "python setup.py register sdist upload -r pypitest"
|
# "python setup.py register sdist upload -r pypitest"
|
||||||
setup(
|
setup(
|
||||||
name='georideapilib',
|
name='georideapilib',
|
||||||
packages=['georideapilib'], # this must be the same as the name above
|
packages=['georideapilib', 'georideapilib.objects'], # this must be the same as the name above
|
||||||
version='0.8.4',
|
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"],
|
||||||
tests_require=[
|
tests_require=[
|
||||||
'pytest>=3.7',
|
'pytest>=3.7',
|
||||||
'pytest-pep8',
|
'pytest-pep8',
|
||||||
'pytest-cov',
|
'pytest-cov',
|
||||||
'python-coveralls',
|
'python-coveralls',
|
||||||
'pylint',
|
'pylint',
|
||||||
'coverage>=4.4'
|
'coverage>=4.4'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user