diff --git a/.gitignore b/.gitignore index d6bfc95..7e6ccca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /local.properties /.idea/workspace.xml .DS_Store +.idea/ +build/ diff --git a/README.md b/README.md index c1a4301..eb5878f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ I reccommend having a read through the [Retrofit docs](http://square.github.io/r ##Available endpoints * Realtime -* GTFS (except shapes) +* GTFS ##How to use diff --git a/lib/src/androidTest/java/api/TATGtfs.java b/lib/src/androidTest/java/api/TATGtfs.java index 3f289e7..c32d192 100644 --- a/lib/src/androidTest/java/api/TATGtfs.java +++ b/lib/src/androidTest/java/api/TATGtfs.java @@ -9,6 +9,7 @@ import com.atapiwrapper.library.api.model.gtfs.Calendar; import com.atapiwrapper.library.api.model.gtfs.CalendarException; import com.atapiwrapper.library.api.model.gtfs.Route; +import com.atapiwrapper.library.api.model.gtfs.ShapePoint; import com.atapiwrapper.library.api.model.gtfs.Stop; import com.atapiwrapper.library.api.model.gtfs.StopTime; import com.atapiwrapper.library.api.model.gtfs.Trip; @@ -254,4 +255,26 @@ public void testTripsByRouteId() { assertTrue(result.getResponse().size() > 0); } + public void testShapeById() { + ServerResponse> result = mGtfsService.shapeById("0002"); + + //make sure we have content + assertNotNull(result); + assertNotNull(result.getStatus()); + assertEquals(result.getStatus(), ServerResponse.STATUS_OK); + assertNotNull(result.getResponse()); + assertTrue(result.getResponse().size() > 0); + } + + public void testShapeByTripId() { + ServerResponse> result = mGtfsService.shapeByTripId("3921ML518918151425687"); + + //make sure we have content + assertNotNull(result); + assertNotNull(result.getStatus()); + assertEquals(result.getStatus(), ServerResponse.STATUS_OK); + assertNotNull(result.getResponse()); + assertTrue(result.getResponse().size() > 0); + } + } diff --git a/lib/src/main/java/com/atapiwrapper/library/api/model/gtfs/ShapePoint.java b/lib/src/main/java/com/atapiwrapper/library/api/model/gtfs/ShapePoint.java new file mode 100644 index 0000000..2517b5f --- /dev/null +++ b/lib/src/main/java/com/atapiwrapper/library/api/model/gtfs/ShapePoint.java @@ -0,0 +1,94 @@ +package com.atapiwrapper.library.api.model.gtfs; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + + +public class ShapePoint implements Serializable, Parcelable { + @JsonProperty("shape_id") private String id; + @JsonProperty("shape_pt_lat") private double lat; + @JsonProperty("shape_pt_lon") private double lon; + @JsonProperty("shape_pt_sequence") private int sequence; + @JsonProperty("shape_dist_traveled") private double distTraveled; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + + public double getLon() { + return lon; + } + + public void setLon(double lon) { + this.lon = lon; + } + + public int getSequence() { + return sequence; + } + + public void setSequence(int sequence) { + this.sequence = sequence; + } + + public double getDistTraveled() { + return distTraveled; + } + + public void setDistTraveled(double distTraveled) { + this.distTraveled = distTraveled; + } + + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.id); + dest.writeDouble(this.lat); + dest.writeDouble(this.lon); + dest.writeInt(this.sequence); + dest.writeDouble(this.distTraveled); + } + + public ShapePoint() { + } + + private ShapePoint(Parcel in) { + this.id = in.readString(); + this.lat = in.readDouble(); + this.lon = in.readDouble(); + this.sequence = in.readInt(); + this.distTraveled = in.readDouble(); + } + + public static Creator CREATOR = new Creator() { + public ShapePoint createFromParcel(Parcel source) { + return new ShapePoint(source); + } + + public ShapePoint[] newArray(int size) { + return new ShapePoint[size]; + } + }; +} + diff --git a/lib/src/main/java/com/atapiwrapper/library/api/service/GtfsService.java b/lib/src/main/java/com/atapiwrapper/library/api/service/GtfsService.java index 8164b1c..72a7b2e 100644 --- a/lib/src/main/java/com/atapiwrapper/library/api/service/GtfsService.java +++ b/lib/src/main/java/com/atapiwrapper/library/api/service/GtfsService.java @@ -5,6 +5,7 @@ import com.atapiwrapper.library.api.model.gtfs.Calendar; import com.atapiwrapper.library.api.model.gtfs.CalendarException; import com.atapiwrapper.library.api.model.gtfs.Route; +import com.atapiwrapper.library.api.model.gtfs.ShapePoint; import com.atapiwrapper.library.api.model.gtfs.Stop; import com.atapiwrapper.library.api.model.gtfs.StopTime; import com.atapiwrapper.library.api.model.gtfs.Trip; @@ -399,4 +400,44 @@ public interface GtfsService { * @param cb - callback that gets called on request complete */ @GET("/gtfs/trips/routeid/{routeid}") void tripsByRouteid(@Path("routeid") String routeid, Callback>> cb); + + //--------------------------------------- + // Shapes by id + //--------------------------------------- + + /** + * List of points in the given shape + * + * @param shapeId - the tripId of the desired shape + * @param cb - callback that gets called on request complete + */ + @GET("/gtfs/shapes/shapeId/{shapeId}") void shapeById(@Path("shapeId") String shapeId, Callback>> cb); + + /** + * List of points in the given shape + * + * @param shapeId - the tripId of the desired shape + */ + @GET("/gtfs/shapes/shapeId/{shapeId}") ServerResponse> shapeById(@Path("shapeId") String shapeId); + + //--------------------------------------- + // Shapes by trip id + //--------------------------------------- + + /** + * List of points in the shape for a given tripId + * + * @param tripId - the tripId of the desired shape + * @param cb - callback that gets called on request complete + */ + @GET("/gtfs/shapes/tripId/{tripId}") void shapeByTripId(@Path("tripId") String tripId, Callback>> cb); + + /** + * List of points in the shape for a given tripId + * + * @param tripId - the tripId of the desired shape + */ + @GET("/gtfs/shapes/tripId/{tripId}") ServerResponse> shapeByTripId(@Path("tripId") String tripId); + + }