-
Notifications
You must be signed in to change notification settings - Fork 11
/
userservice.py
60 lines (45 loc) · 2 KB
/
userservice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from xml.dom import minidom
import time
import sha
from connection import Connection, AuthException
from xmlhelper import dict_to_xml
from response import *
class UserService(object):
SERVICE_PATH = '/userService'
def __init__(self, connection):
self.connection = connection
def login_and_get_status(self):
namespaces = {'ns2':'urn:com:airbiquity:smartphone.userservices:v1'}
d = {'SmartphoneLoginInfo':
{ 'UserLoginInfo':
{ 'userId': self.connection.username,
'userPassword': self.connection.password },
'DeviceToken': 'DUMMY%f' % time.time(),
'UUID': sha.sha("carwings_api:%s" % self.connection.username).hexdigest(),
'Locale': 'US',
'AppVersion': '1.40',
'SmartphoneType': 'IPHONE'},
'SmartphoneOperationType': 'SmartphoneLatestBatteryStatusRequest'}
xml = dict_to_xml(d,
'ns2:SmartphoneLoginWithAdditionalOperationRequest',
namespaces)
result = self.connection.post_xml(self.SERVICE_PATH, xml)
status = LoginStatus(result)
if status.logged_in:
self.connection.logged_in = True
else:
self.connection.logged_in = False
return status
def get_latest_status(self, vin):
if not self.connection.logged_in:
raise AuthException('Please log in before checking status')
namespaces = {'ns2':'urn:com:airbiquity:smartphone.userservices:v1'}
d = {'VehicleInfo':
{'Vin': vin},
'SmartphoneOperationType': 'SmartphoneLatestBatteryStatusRequest',
'changeVehicle': 'false'}
xml = dict_to_xml(d,
'ns2:SmartphoneGetVehicleInfoRequest',
namespaces)
result = self.connection.post_xml(self.SERVICE_PATH, xml)
return LatestBatteryStatus(result)