Skip to content

Commit

Permalink
added display service - parking locations and scheduled works
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-burton committed May 24, 2014
1 parent 8b8d024 commit 18e948c
Show file tree
Hide file tree
Showing 18 changed files with 427 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ I reccommend having a read through the [Retrofit docs](http://square.github.io/r

* Realtime
* GTFS
* Display (Parking Locations, Scheduled Works)

##How to use

Expand Down
44 changes: 16 additions & 28 deletions lib/src/androidTest/java/api/TATDisplays.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
package api;

import retrofit.RestAdapter;
import util.Util;
import android.test.AndroidTestCase;

import com.atapiwrapper.library.BuildConfig;
import com.atapiwrapper.library.api.AtApi;
import com.atapiwrapper.library.api.model.ServerResponse;
import com.atapiwrapper.library.api.model.realtime.vehiclelocations.VehicleLocationResponse;
import com.atapiwrapper.library.api.service.RealtimeService;
import com.atapiwrapper.library.api.model.display.ParkingLocation;
import com.atapiwrapper.library.api.model.display.ScheduledWork;
import com.atapiwrapper.library.api.service.DisplayService;

import java.util.List;

import retrofit.RestAdapter;
import util.Util;

/**
* Tests the realtime api requests and responses
*/
public class TATDisplays extends AndroidTestCase {

private RestAdapter mRestAdapter;
private RealtimeService mRealtimeService;
private DisplayService mDisplayService;

@Override protected void setUp() throws Exception {
super.setUp();

AtApi api = new AtApi(BuildConfig.API_KEY);
mRestAdapter = api.getRestAdapter(Util.getClient());
mRealtimeService = mRestAdapter.create(RealtimeService.class);
mDisplayService = mRestAdapter.create(DisplayService.class);
}

public void testVehicleLocations() {
public void testParkingLocations() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocations();
ServerResponse<List<ParkingLocation>> result = mDisplayService.parkingLocations();

//make sure we have content
assertNotNull(result);
assertNotNull(result.getStatus());
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
assertNotNull(result.getResponse());
assertNotNull(result.getResponse().getVehicleLocations());
assertTrue(result.getResponse().getVehicleLocations().size() > 0);
assertTrue(result.getResponse().size() > 0);
}
public void testVehicleLocationsByTripId() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId("2212GW582020451266647");

//make sure we have content
assertNotNull(result);
assertNotNull(result.getStatus());
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
assertNotNull(result.getResponse());
assertNotNull(result.getResponse().getVehicleLocations());
assertTrue(result.getResponse().getVehicleLocations().size() == 1);
}

public void testVehicleLocationsByVehicleId() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId(
"4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");
public void testScheduledWorks() {
ServerResponse<List<ScheduledWork>> result = mDisplayService.scheduledWorks();

//make sure we have content
assertNotNull(result);
assertNotNull(result.getStatus());
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
assertNotNull(result.getResponse());
assertNotNull(result.getResponse().getVehicleLocations());
assertTrue(result.getResponse().getVehicleLocations().size() == 1);
assertTrue(result.getResponse().size() > 0);
}

}
7 changes: 4 additions & 3 deletions lib/src/androidTest/java/api/TATRealtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TATRealtime extends AndroidTestCase {

public void testVehicleLocations() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocations();
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehicleLocations();

//make sure we have content
assertNotNull(result);
Expand All @@ -41,7 +41,7 @@ public void testVehicleLocations() {
}
public void testVehicleLocationsByTripId() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId("2212GW582020451266647");
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehicleLocationsByTripId("2212GW582020451266647");

//make sure we have content
assertNotNull(result);
Expand All @@ -54,7 +54,8 @@ public void testVehicleLocationsByTripId() {

public void testVehicleLocationsByVehicleId() {

ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId("4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehicleLocationsByTripId(
"4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");

//make sure we have content
assertNotNull(result);
Expand Down
16 changes: 13 additions & 3 deletions lib/src/main/java/com/atapiwrapper/library/api/AtApi.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.atapiwrapper.library.api;

import com.atapiwrapper.library.api.service.DisplaysService;
import com.atapiwrapper.library.api.model.geometry.Geometry;
import com.atapiwrapper.library.api.model.geometry.GeometryDeserializer;
import com.atapiwrapper.library.api.service.DisplayService;
import com.atapiwrapper.library.api.service.GtfsService;
import com.atapiwrapper.library.api.service.RealtimeService;
import com.atapiwrapper.library.core.ATConstants;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.squareup.okhttp.OkHttpClient;

import retrofit.RequestInterceptor;
Expand Down Expand Up @@ -46,6 +50,12 @@ public RestAdapter getRestAdapter() {
public RestAdapter getRestAdapter(OkHttpClient client) {
//setup mapper which uses custom deserializer
final ObjectMapper mapper = new ObjectMapper();

//setup custom deserializer module to handle geometry
SimpleModule module = new SimpleModule("GeometryDeserializerModule", new Version(1, 0, 0, null));
module.addDeserializer(Geometry.class, new GeometryDeserializer());
mapper.registerModule(module);

JacksonConverter converter = new JacksonConverter(mapper);

//request interceptor that will add an api key to every request
Expand Down Expand Up @@ -73,9 +83,9 @@ public GtfsService getGtfsService() {
return mRestAdapter.create(GtfsService.class);
}

public DisplaysService getDisplaysService() {
public DisplayService getDisplaysService() {
if (null == mRestAdapter) mRestAdapter = getRestAdapter();
return mRestAdapter.create(DisplaysService.class);
return mRestAdapter.create(DisplayService.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.atapiwrapper.library.api.model.display;

import android.os.Parcel;
import android.os.Parcelable;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ParkingLocation implements Parcelable {
@JsonProperty("id") private Integer id;
@JsonProperty("address") private String address;
@JsonProperty("mobilitySpaces") private Integer mobilitySpaces;
@JsonProperty("name") private String name;
@JsonProperty("longitude") private Double longitude;
@JsonProperty("latitude") private Double latitude;
@JsonProperty("type") private String type;

public Integer getId() {
return id;
}

public String getAddress() {
return address;
}

public Integer getMobilitySpaces() {
return mobilitySpaces;
}

public String getName() {
return name;
}

public Double getLongitude() {
return longitude;
}

public Double getLatitude() {
return latitude;
}

public String getType() {
return type;
}

@Override public int describeContents() {
return 0;
}

@Override public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(this.id);
dest.writeString(this.address);
dest.writeValue(this.mobilitySpaces);
dest.writeString(this.name);
dest.writeValue(this.longitude);
dest.writeValue(this.latitude);
dest.writeString(this.type);
}

public ParkingLocation() {}

private ParkingLocation(Parcel in) {
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
this.address = in.readString();
this.mobilitySpaces = (Integer) in.readValue(Integer.class.getClassLoader());
this.name = in.readString();
this.longitude = (Double) in.readValue(Double.class.getClassLoader());
this.latitude = (Double) in.readValue(Double.class.getClassLoader());
this.type = in.readString();
}

public static Parcelable.Creator<ParkingLocation> CREATOR = new Parcelable.Creator<ParkingLocation>() {
public ParkingLocation createFromParcel(Parcel source) {
return new ParkingLocation(source);
}

public ParkingLocation[] newArray(int size) {
return new ParkingLocation[size];
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.atapiwrapper.library.api.model.display;

import android.os.Parcel;
import android.os.Parcelable;

import com.atapiwrapper.library.api.model.geometry.Geometry;
import com.fasterxml.jackson.annotation.JsonProperty;

public class ScheduledWork implements Parcelable {
@JsonProperty("region") private String region;
@JsonProperty("startDate") private String startDate;
@JsonProperty("lastUpdated") private String lastUpdated;
@JsonProperty("endDate") private String endDate;
@JsonProperty("code") private String code;
@JsonProperty("type") private String type;
@JsonProperty("geometry") private Geometry geometry;
@JsonProperty("id") private Integer id;
@JsonProperty("contractorCompany") private String contractorCompany;
@JsonProperty("suburb") private String suburb;
@JsonProperty("address") private String address;
@JsonProperty("description") private String description;
@JsonProperty("name") private String name;
@JsonProperty("longitude") private Double longitude;
@JsonProperty("latitude") private Double latitude;

public String getRegion() {
return region;
}

public String getStartDate() {
return startDate;
}

public String getLastUpdated() {
return lastUpdated;
}

public String getEndDate() {
return endDate;
}

public String getCode() {
return code;
}

public String getType() {
return type;
}

public Geometry getGeometry() {
return geometry;
}

public Integer getId() {
return id;
}

public String getContractorCompany() {
return contractorCompany;
}

public String getSuburb() {
return suburb;
}

public String getAddress() {
return address;
}

public String getDescription() {
return description;
}

public String getName() {
return name;
}

public Double getLongitude() {
return longitude;
}

public Double getLatitude() {
return latitude;
}


@Override public int describeContents() { return 0; }

@Override public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.region);
dest.writeString(this.startDate);
dest.writeString(this.lastUpdated);
dest.writeString(this.endDate);
dest.writeString(this.code);
dest.writeString(this.type);
// dest.writeParcelable(this.geometry, flags);
dest.writeValue(this.id);
dest.writeString(this.contractorCompany);
dest.writeString(this.suburb);
dest.writeString(this.address);
dest.writeString(this.description);
dest.writeString(this.name);
dest.writeValue(this.longitude);
dest.writeValue(this.latitude);
}

public ScheduledWork() {}

private ScheduledWork(Parcel in) {
this.region = in.readString();
this.startDate = in.readString();
this.lastUpdated = in.readString();
this.endDate = in.readString();
this.code = in.readString();
this.type = in.readString();
// this.geometry = in.readParcelable(Geometry.class.getClassLoader());
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
this.contractorCompany = in.readString();
this.suburb = in.readString();
this.address = in.readString();
this.description = in.readString();
this.name = in.readString();
this.longitude = (Double) in.readValue(Double.class.getClassLoader());
this.latitude = (Double) in.readValue(Double.class.getClassLoader());
}

public static Parcelable.Creator<ScheduledWork> CREATOR = new Parcelable.Creator<ScheduledWork>() {
public ScheduledWork createFromParcel(Parcel source) {return new ScheduledWork(source);}

public ScheduledWork[] newArray(int size) {return new ScheduledWork[size];}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.atapiwrapper.library.api.model.geometry;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Geometry returned by the server can be of different types determined by the type attribute. This is handled by a custom deserializerin
* {@link com.atapiwrapper.library.api.AtApi}
*/
public abstract class Geometry {
@JsonProperty("encoded") protected boolean encoded;
@JsonProperty("type") protected String type;

public boolean isEncoded() {
return encoded;
}

public String getType() {
return type;
}
}
Loading

0 comments on commit 18e948c

Please sign in to comment.