All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypertrack.factory.TripFactory Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
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