def createEntity(cls, companyName): url = Entity.urls['create'] data = {'companyName': companyName} response = httpRequest(url, data, 'POST') response = json.load(response) entity = Entity(response['id'], response['companyName']) return entity
def createRole(cls,name): url = Role.urls['create'] data = {'name':name} response = httpRequest(url, data, 'POST') response = json.load(response) role = Role(response['id'],response['name']) return role
def createDeviceType(cls,deviceType,make,model): url = DeviceType.urls['create'] data = {'type':deviceType,'make':make,'model':model} response = httpRequest(url, data, 'POST') sendGPSInfo = config['DeviceType'][deviceType] response = json.load(response) deviceType = DeviceType(response['id'],response['type'],response['make'],response['model'],sendGPSInfo) return deviceType
def createLocation(cls, name, latitude, longitude): url = Location.urls['create'] data = {'name': name, 'latitude': latitude, 'longitude': longitude} response = httpRequest(url, data, 'POST') response = json.load(response) location = Location(response['id'], response['name'], response['latitude'], response['longitude']) return location
def update(self,data): url = Trip.urls['update'] url = url.format(self.identity) response = httpRequest(url, data, 'PUT') response = json.load(response) self.startTime = response['startTime'] self.endTime = response['endTime'] self.status = response['status']
def entityById(cls, id): if Entity.entities.get(id) is None: url = Entity.urls['findById'].format(id) response = httpRequest(url) response = json.load(response) entity = Entity(response['id'], response['companyName']) Entity.entities[id] = entity return Entity.entities[id]
def deviceTypeId(cls,id): if DeviceType.deviceTypes.get(id) is None: url = DeviceType.urls['findById'].format(id) response = httpRequest(url) response = json.load(response) sendGPSInfo = config['DeviceType'][response['type']] deviceType = DeviceType(response['id'],response['type'],response['make'],response['model'],sendGPSInfo) DeviceType.deviceTypes[id] = deviceType return DeviceType.deviceTypes[id]
def allEntities(cls): url = Entity.urls['all'] response = httpRequest(url) response = json.load(response) entities = [] for item in response: entity = Entity(item['id'], item['companyName']) entities.append(entity) return entities
def locationById(cls, id): if Location.locations.get(id) is None: url = Location.urls['findById'].format(id) response = httpRequest(url) response = json.load(response) location = Location(response['id'], response['name'], response['latitude'], response['longitude']) Location.locations[id] = location return Location.locations[id]
def deviceById(cls): if Device.devices.get(id) is None: url = Device.urls['findById'].format(id) response = httpRequest(url) response = json.load(response) deviceType = DeviceType.deviceTypeId(response['deviceType']) device = Device(response['id'],deviceType,response['entity'],response['IMEI'],response['SIM'], response['UIN']) Device.devices[id] = device return Device.devices[id]
def createDevice(cls,deviceType,entity,IMEI,SIM,UIN): url = Device.urls['create'] data = {'SIM':SIM,'UIN':UIN,'IMEI':IMEI,'deviceType':deviceType.identity} if entity: data['entity'] = entity.identity response = httpRequest(url, data, 'POST') response = json.load(response) device = Device(response['id'],deviceType,response['entity'],response['IMEI'],response['SIM'], response['UIN']) return device
def allLocations(cls): url = Location.urls['all'] response = httpRequest(url) response = json.load(response) locations = [] for item in response: location = Location(item['id'], item['name'], item['latitude'], item['longitude']) locations.append(location) return locations
def allDevices(cls): url = Device.urls['all'] response = httpRequest(url) response = json.load(response) devices = [] for item in response: deviceType = DeviceType.deviceTypeId(item['deviceType']) device = Device(item['id'],deviceType,item['entity'],item['IMEI'],item['SIM'], item['UIN']) devices.append(device) return devices
def allUsers(cls): url = User.urls['all'] response = httpRequest(url) response = json.load(response) users = [] for item in response: location = Location.locationById(item['location']) if item['location'] else None entity = Entity.entityById(item['entity']) if item['entity'] else None user = User(item['id'],item['userId'],item['userName'],item['name'],item['mobileNumber'], item['emailAddress'],item['emergencyContactNumber'],item['emergencyContactName'],item['emergencyContactEmail'], item['address'],location,entity) users.append(user) return users
def createTrip(cls,assignedTime,device,driver,endLocation,endTime,entity,startTime,startLocation,status,vehicle): url = Trip.urls['create'] data = {'assignedTime':assignedTime,'device':device.identity,'driver':driver.identity,'endLocation':endLocation.identity, 'entity':entity.identity,'startLocation':startLocation.identity,'status':status,'vehicle':vehicle.identity} if startTime: data['startTime'] = startTime if endTime: data['endTime'] = endTime response = httpRequest(url, data, 'POST') response = json.load(response) trip = Trip(response['id'],response['assignedTime'],device,driver,endLocation,response['endTime'],entity,response['startTime'], startLocation,response['status'],vehicle) return trip
def allVehicles(cls): url = Vehicle.urls['all'] response = httpRequest(url) response = json.load(response) vehicles = [] for item in response: entity = Entity.entityById( item['entity']) if item['entity'] else None device = Device.deviceById( item['device']) if item['device'] else None vehicle = Vehicle(item['id'], item['capacity'], device, entity, item['make'], item['model'], item['registrationNumber']) vehicles.append(vehicle) return vehicles
def createUser(cls,userId,userName,password,name,mobileNumber,emailAddress,emergencyContactNumber,emergencyContactName, emergencyContactEmail,address,location,entity): url = User.urls['create'] data = {'userId':userId,'userName':userName,'password':password,'name':name,'mobileNumber':mobileNumber, 'emailAddress':emailAddress,'emergencyContactNumber':emergencyContactNumber,'emergencyContactNumber':emergencyContactNumber, 'emergencyContactName':emergencyContactName,'emergencyContactEmail':emergencyContactEmail,'address':address} if location: data['location'] = location.identity if entity: data['entity'] = entity.identity response = httpRequest(url, data, 'POST') response = json.load(response) user = User(response['id'],response['userId'],response['userName'],response['name'],response['mobileNumber'], response['emailAddress'],response['emergencyContactNumber'],response['emergencyContactName'],response['emergencyContactEmail'], response['address'],location,entity) return user
def createVehicle(cls, capacity, device, entity, make, model, registrationNumber): url = Vehicle.urls['create'] data = { 'capacity': capacity, 'entity': entity.identity, 'make': make, 'model': model, 'registrationNumber': registrationNumber } if device: data['device'] = device.identity response = httpRequest(url, data, 'POST') response = json.load(response) vehicle = Vehicle(response['id'], response['capacity'], device, entity, response['make'], response['model'], response['registrationNumber']) return vehicle
def adomRestApi(gpsData): url = 'http://52.64.162.195:1338/v2/GPS' httpRequest(url, data=gpsData, method='POST')