io.hypertrack.factory.DriverFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hypertrack-java Show documentation
Show all versions of hypertrack-java Show documentation
A Java wrapper for the HyperTrack API https://hypertrack.io
package io.hypertrack.factory;
import io.hypertrack.model.Driver;
import io.hypertrack.net.HyperTrackClient;
import io.hypertrack.net.HyperTrackException;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* Factory class for Driver model.
*/
public class DriverFactory extends HyperTrackFactory {
private static String modelUrl = "drivers/";
public DriverFactory(HyperTrackClient client) {
super(client);
}
@Override
protected Driver makeNew(Map params) {
return new Driver(params);
}
@Override
protected String getModelUrl() {
return modelUrl;
}
/**
* Patch driver instance with a photo.
*
* @param driver Driver instance to be patched
* @param photo Photo file
*/
public void patchWithPhoto(Driver driver, File photo) {
String driverId = driver.getId();
HyperTrackClient client = getClient();
try {
Map fileParam = new HashMap<>();
fileParam.put("photo", photo);
String response = client.request(getInstanceUrl(driverId), fileParam);
updateFromParams(driver, getMapFromResponse(response));
} catch (HyperTrackException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy