Skip to content

Commit

Permalink
Merge pull request #1 from robinstark/master
Browse files Browse the repository at this point in the history
Add GTFS shapes support
  • Loading branch information
josh-burton committed May 24, 2014
2 parents 8531541 + a80a9bc commit 8b8d024
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/local.properties
/.idea/workspace.xml
.DS_Store
.idea/
build/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions lib/src/androidTest/java/api/TATGtfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -254,4 +255,26 @@ public void testTripsByRouteId() {
assertTrue(result.getResponse().size() > 0);
}

public void testShapeById() {
ServerResponse<List<ShapePoint>> 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<List<ShapePoint>> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<ShapePoint> CREATOR = new Creator<ShapePoint>() {
public ShapePoint createFromParcel(Parcel source) {
return new ShapePoint(source);
}

public ShapePoint[] newArray(int size) {
return new ShapePoint[size];
}
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ServerResponse<List<Trip>>> 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<ServerResponse<List<ShapePoint>>> cb);

/**
* List of points in the given shape
*
* @param shapeId - the tripId of the desired shape
*/
@GET("/gtfs/shapes/shapeId/{shapeId}") ServerResponse<List<ShapePoint>> 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<ServerResponse<List<ShapePoint>>> 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<List<ShapePoint>> shapeByTripId(@Path("tripId") String tripId);


}

0 comments on commit 8b8d024

Please sign in to comment.