Skip to content

Commit 794a818

Browse files
authored
Merge pull request #1 from tikismoke/patch-1
Support API V4
2 parents b37ecd2 + 21d05b7 commit 794a818

8 files changed

Lines changed: 141 additions & 90 deletions

File tree

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,39 @@ from xee import Xee
1919

2020
xee = Xee(client_id="your_client_id",
2121
client_secret="your_client_secret",
22-
redirect_uri="your://redirect:uri")
22+
redirect_uri="your://redirect:uri",
23+
scope=(
24+
AuthScope.VEHICLES_READ,
25+
AuthScope.VEHICLES_READ_SIGNALS,
26+
AuthScope.VEHICLES_READ_LOCATIONS,
27+
AuthScope.VEHICLES_READ_EVENTS,
28+
AuthScope.VEHICLES_READ_ACCELEROMETERS,
29+
AuthScope.VEHICLES_READ_DEVICE_DATA,
30+
AuthScope.ACCOUNT_READ,
31+
AuthScope.VEHICLES_MANAGEMENT
32+
)
33+
)
2334
```
2435

2536
## Using the SDK
2637

2738
### Authentication
2839

29-
#### Getting the [access code url](https://github.com/xee-lab/xee-api-docs/tree/master/api/api/v3/auth/auth.md)
40+
#### Getting the [access code url](https://dev.xee.com/v4-openapi/#section/Authentication/Authorization-Code-flow)
3041

3142
```python
3243
login_url = xee.get_authentication_url()
3344
```
3445

3546
> Then show the webpage to the end user, once the process is complete, we'll redirect to `redirect_uri?code={authorization_code}`. Keep this code in mind
3647
37-
#### Getting a [token from an `authorization_code`](https://github.com/xee-lab/xee-api-docs/tree/master/api/api/v3/auth/access_token.md)
48+
#### Getting a [token from an `authorization_code`](https://dev.xee.com/v4-openapi/#section/Authentication/Authorization-Code-flow)
3849

3950
```python
4051
token, error = xee.get_token_from_code(authorization_code)
4152
```
4253

43-
#### Getting a [token from an `refresh_token`](https://github.com/xee-lab/xee-api-docs/tree/master/api/api/v3/auth/access_token.md)
54+
#### Getting a [token from an `refresh_token`](https://dev.xee.com/v4-openapi/#section/Authentication/Refresh-Token)
4455

4556
```python
4657
token, error = xee.get_token_from_refresh_token(token.refresh_token)
@@ -62,7 +73,7 @@ print(status)
6273
```
6374

6475
```python
65-
signal, error = xee.get_signals(carId, token.access_token,names=['Odometer', 'FuelLevel'])
76+
signal, error = xee.get_signals(carId, token.access_token)
6677
print(signal)
6778
```
6879

@@ -71,7 +82,6 @@ trip_duration, error = xee.get_trip_duration(tripId, token.access_token)
7182
print(trip_duration.value)
7283
```
7384

74-
See the [docs](https://github.com/quentin7b/xee-sdk-python/docs) for more about how to use it
7585

7686
## Contributing
7787

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
isodate
22
requests
3+
enum
4+
base64
5+
arrow
6+
oauthlib
7+
requests_oauthlib

xee/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@
66
"""
77

88
from .sdk import Xee
9+
10+
from enum import Enum
11+
12+
class AuthScope(Enum):
13+
"""Authorization scopes."""
14+
VEHICLES_MANAGEMENT = "vehicles.management"
15+
VEHICLES_READ = "vehicles.read"
16+
VEHICLES_READ_SIGNALS = "vehicles.signals.read"
17+
VEHICLES_READ_LOCATIONS = "vehicles.locations.read"
18+
VEHICLES_READ_EVENTS = "vehicles.events.read"
19+
VEHICLES_READ_ACCELEROMETERS = "vehicles.accelerometers.read"
20+
VEHICLES_READ_DEVICE_DATA = "vehicles.devices-data.read"
21+
ACCOUNT_READ = "account.read"

xee/entities.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@
2020
User = collections.namedtuple(
2121
'User',
2222
[
23-
'id',
24-
'last_name',
25-
'first_name',
26-
'nick_name',
23+
'createdAt',
24+
'email',
25+
'firstName',
2726
'gender',
28-
'birth_date',
29-
'licence_delivery_date',
30-
'role',
31-
'is_location_enabled'
27+
'id',
28+
'lastName',
29+
'updatedAt'
3230
])
3331
Car = collections.namedtuple(
3432
'Car',
3533
[
34+
'brand',
35+
'createdAt',
36+
'firstEntryIntoService',
37+
'fleetId',
3638
'id',
37-
'name',
38-
'make',
39+
'kType',
40+
'licensePlate',
3941
'model',
40-
'year',
41-
'number_plate',
42-
'device_id',
43-
'cardb_id'
42+
'name',
43+
'updatedAt',
44+
'userId'
4445
])
4546
Signal = collections.namedtuple(
4647
'Signal',
@@ -57,6 +58,7 @@
5758
'altitude',
5859
'satellites',
5960
'heading',
61+
'hacc',
6062
'date'
6163
])
6264
Accelerometer = collections.namedtuple(
@@ -162,23 +164,16 @@ def parse_user(user):
162164
If the dict does not contains the correct data.
163165
164166
"""
165-
birth_date = None
166-
if user['birthDate']:
167-
birth_date = isodate.parse_datetime(user['birthDate'])
168-
licence_delivery_date = None
169-
if user['licenseDeliveryDate']:
170-
licence_delivery_date = isodate.parse_datetime(user['licenseDeliveryDate'])
167+
print("user=",user)
171168
try:
172169
return User(
173-
user['id'],
174-
user['lastName'],
170+
user['createdAt'],
171+
user['email'],
175172
user['firstName'],
176-
user['nickName'],
177173
user['gender'],
178-
birth_date,
179-
licence_delivery_date,
180-
user['role'],
181-
user['isLocationEnabled']
174+
user['id'],
175+
user['lastName'],
176+
user['updatedAt']
182177
)
183178
except ValueError as err:
184179
raise xee_exceptions.ParseException(err)
@@ -207,14 +202,17 @@ def parse_car(car):
207202
"""
208203
try:
209204
return Car(
205+
car['brand'],
206+
car['createdAt'],
207+
car['firstEntryIntoService'],
208+
car['fleetId'],
210209
car['id'],
211-
car['name'],
212-
car['make'],
210+
car['kType'],
211+
car['licensePlate'],
213212
car['model'],
214-
car['year'],
215-
car['numberPlate'],
216-
car['deviceId'],
217-
car['cardbId']
213+
car['name'],
214+
car['updatedAt'],
215+
car['userId']
218216
)
219217
except ValueError as err:
220218
raise xee_exceptions.ParseException(err)
@@ -277,8 +275,9 @@ def parse_location(location):
277275
location['latitude'],
278276
location['longitude'],
279277
location['altitude'],
280-
location['satellites'],
278+
location['nbSat'],
281279
location['heading'],
280+
location['hacc'],
282281
isodate.parse_datetime(location['date'])
283282
)
284283
except ValueError as err:

xee/exceptions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ class APIException(Exception):
1818
see https://github.com/xee-lab/xee-api-docs/tree/master/api/api/v3#errors
1919
"""
2020

21-
def __init__(self, type_, message, tip):
22-
super(APIException, self).__init__(message)
23-
self.type = type_
24-
self.message = message
25-
self.tip = tip
21+
def __init__(self, error, error_description):
22+
super(APIException, self).__init__(error_description)
23+
self.error = error
24+
self.error_description = error_description
2625

2726
def __str__(self):
2827
return str(self.__dict__)

0 commit comments

Comments
 (0)