io.hypertrack.factory.TripFactory 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.Trip;
import io.hypertrack.net.HyperTrackClient;
import io.hypertrack.net.HyperTrackException;
import java.util.Map;
/**
* Factory class for Trip model.
*/
public class TripFactory extends HyperTrackFactory {
private static String modelUrl = "trips/";
public TripFactory(HyperTrackClient client) {
super(client);
}
@Override
protected Trip makeNew(Map params) {
return new Trip(params);
}
@Override
protected String getModelUrl() {
return modelUrl;
}
/**
* Mark trip as ended.
*
* @param trip trip object to be ended
* @param params params to be passed as POST body
*/
public void markEnded(Trip trip, Map params) {
String tripId = trip.getId();
try {
String response = getClient().request(getInstanceUrl(tripId) + "end/",
"POST", params);
Map responseMap = getMapFromResponse(response);
updateFromParams(trip, responseMap);
} catch (final HyperTrackException e) {
e.printStackTrace();
throw new IllegalArgumentException("Could not end trip", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy