Search in sources :

Example 6 with APIException

use of im.tny.segvault.disturbances.exception.APIException in project underlx by underlx.

the class API method postFeedback.

public Feedback postFeedback(Feedback request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = postRequest(endpoint.resolve("feedback"), content, true);
        return mapper.readValue(is, Feedback.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 7 with APIException

use of im.tny.segvault.disturbances.exception.APIException in project underlx by underlx.

the class API method putTrip.

public Trip putTrip(TripRequest request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = putRequest(endpoint.resolve("trips"), content, true);
        return mapper.readValue(is, Trip.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 8 with APIException

use of im.tny.segvault.disturbances.exception.APIException in project underlx by underlx.

the class API method postTrip.

public Trip postTrip(TripRequest request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = postRequest(endpoint.resolve("trips"), content, true);
        return mapper.readValue(is, Trip.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 9 with APIException

use of im.tny.segvault.disturbances.exception.APIException in project underlx by underlx.

the class MainService method dumpDebugInfo.

// DEBUG:
public String dumpDebugInfo() {
    String s = "Service created on " + creationDate.toString();
    s += (wfc.isScanning() ? String.format(". WFC scanning every %d s", wfc.getScanInterval() / 1000) : ". WFC not scanning") + "\n";
    for (Network n : getNetworks()) {
        S2LS loc;
        synchronized (lock) {
            loc = locServices.get(n.getId());
        }
        s += "Network " + n.getNames("en")[0] + "\n";
        s += "State machine: " + loc.getState().toString() + "\n";
        s += String.format("\tIn network? %b\n\tNear network? %b\n", loc.inNetwork(), loc.nearNetwork());
        if (loc.getState() instanceof InNetworkState) {
            s += "\tPossible stops:\n";
            for (Stop stop : loc.getLocation().vertexSet()) {
                s += String.format("\t\t%s (%s)\n", stop.getStation().getName(), stop.getLine().getNames("en")[0]);
            }
            s += "\tPath:\n";
            if (loc.getCurrentTrip() != null) {
                for (Connection c : loc.getCurrentTrip().getEdgeList()) {
                    s += String.format("\t\t%s -> %s\n", c.getSource().toString(), c.getTarget().toString());
                }
                if (loc.getCurrentTargetRoute() != null) {
                    s += String.format("\t\tCurrent path complies? %b\n", loc.getCurrentTargetRoute().checkPathCompliance(loc.getCurrentTrip()));
                }
            }
        }
    }
    try {
        API.AuthTest authTest = API.getInstance().getAuthTest();
        s += "API auth test result: " + authTest.result + "\n";
        s += "API key as perceived by server: " + authTest.key + "\n";
    } catch (APIException e) {
        e.printStackTrace();
        s += "Error testing API authentication\n";
    }
    synchronizer.attemptSync();
    return s;
}
Also used : S2LS(im.tny.segvault.s2ls.S2LS) APIException(im.tny.segvault.disturbances.exception.APIException) Stop(im.tny.segvault.subway.Stop) Network(im.tny.segvault.subway.Network) Connection(im.tny.segvault.subway.Connection) SpannableString(android.text.SpannableString) InNetworkState(im.tny.segvault.s2ls.InNetworkState)

Example 10 with APIException

use of im.tny.segvault.disturbances.exception.APIException in project underlx by underlx.

the class API method postRealtimeLocation.

public Feedback postRealtimeLocation(RealtimeLocationRequest request) throws APIException {
    try {
        byte[] content = mapper.writeValueAsBytes(request);
        InputStream is = postRequest(endpoint.resolve("rt"), content, true);
        return mapper.readValue(is, Feedback.class);
    } catch (JsonParseException e) {
        throw new APIException(e).addInfo("Parse exception");
    } catch (JsonMappingException e) {
        throw new APIException(e).addInfo("Mapping exception");
    } catch (IOException e) {
        throw new APIException(e).addInfo("IOException");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Aggregations

APIException (im.tny.segvault.disturbances.exception.APIException)10 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 GZIPInputStream (java.util.zip.GZIPInputStream)7 JsonParseException (com.fasterxml.jackson.core.JsonParseException)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)5 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 SharedPreferences (android.content.SharedPreferences)1 SpannableString (android.text.SpannableString)1 Trip (im.tny.segvault.disturbances.model.Trip)1 InNetworkState (im.tny.segvault.s2ls.InNetworkState)1 S2LS (im.tny.segvault.s2ls.S2LS)1 Connection (im.tny.segvault.subway.Connection)1 Network (im.tny.segvault.subway.Network)1 Stop (im.tny.segvault.subway.Stop)1 Realm (io.realm.Realm)1 RealmResults (io.realm.RealmResults)1 BufferedOutputStream (java.io.BufferedOutputStream)1