1
|
1 |
|
from .api_endpoints import SET_GPS_HOST, DEVICE_LOCATION_URL |
2
|
1 |
|
from .base import Base |
3
|
1 |
|
from .exceptions import ParamValueException |
4
|
|
|
|
5
|
|
|
|
6
|
1 |
|
class GPS(Base): |
7
|
|
|
""" |
8
|
|
|
Set GPS position of the device |
9
|
|
|
""" |
10
|
|
|
|
11
|
1 |
|
requirements = ('api_key', |
12
|
|
|
'format', |
13
|
|
|
'member_id', |
14
|
|
|
'route_id', |
15
|
|
|
'course', |
16
|
|
|
'speed', |
17
|
|
|
'lat', |
18
|
|
|
'lng', |
19
|
|
|
'device_type', |
20
|
|
|
'device_guid', |
21
|
|
|
) |
22
|
|
|
|
23
|
1 |
|
def __init__(self, api): |
24
|
1 |
|
self.response = None |
25
|
1 |
|
self.params = {'api_key': api.key, } |
26
|
1 |
|
Base.__init__(self, api) |
27
|
|
|
|
28
|
1 |
|
def set_gps_track(self, **kwargs): |
29
|
|
|
""" |
30
|
|
|
Set GPS position of device using GET request |
31
|
|
|
:return: Response status |
32
|
|
|
:raise: ParamValueException if any required param is not set |
33
|
|
|
""" |
34
|
1 |
|
kwargs.update({'api_key': self.params['api_key'], }) |
35
|
1 |
|
if self.check_required_params(kwargs, self.requirements): |
36
|
1 |
|
self.response = self.api._request_get(SET_GPS_HOST, |
37
|
|
|
kwargs) |
38
|
1 |
|
response = self.response.json() |
39
|
1 |
|
return response.get('status') |
40
|
|
|
else: |
41
|
|
|
raise ParamValueException('params', 'Params are not complete') |
42
|
|
|
|
43
|
1 |
|
def get_locations(self, **kwargs): |
44
|
|
|
""" |
45
|
|
|
Get GPS tracks of a vehicle using GET request |
46
|
|
|
:return: Response status |
47
|
|
|
:raise: ParamValueException if any required param is not set |
48
|
|
|
""" |
49
|
|
|
kwargs.update({'api_key': self.params['api_key'], }) |
50
|
|
|
if self.check_required_params(kwargs, [ |
51
|
|
|
'api_key', |
52
|
|
|
'format', |
53
|
|
|
'route_id', |
54
|
|
|
'member_id', |
55
|
|
|
'time_period', |
56
|
|
|
]): |
57
|
|
|
self.response = self.api._request_get(DEVICE_LOCATION_URL, |
58
|
|
|
kwargs) |
59
|
|
|
return self.response.json() |
60
|
|
|
else: |
61
|
|
|
raise ParamValueException('params', 'Params are not complete') |
62
|
|
|
|