mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 04:13:54 +08:00
@@ -1,7 +1,26 @@
|
||||
import jwt
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from selfdrive.version import version
|
||||
|
||||
class Api(object):
|
||||
def __init__(self, dongle_id, private_key):
|
||||
self.dongle_id = dongle_id
|
||||
self.private_key = private_key
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
return self.request('GET', *args, **kwargs)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
return self.request('POST', *args, **kwargs)
|
||||
|
||||
def request(self, method, endpoint, timeout=None, access_token=None, **params):
|
||||
return api_get(endpoint, method=method, timeout=timeout, access_token=access_token, **params)
|
||||
|
||||
def get_token(self):
|
||||
return jwt.encode({'identity': self.dongle_id, 'exp': datetime.utcnow() + timedelta(hours=1)}, self.private_key, algorithm='RS256')
|
||||
|
||||
def api_get(endpoint, method='GET', timeout=None, access_token=None, **params):
|
||||
backend = "https://api.commadotai.com/"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user