Skip to content

Commit 18e948c

Browse files
committed
added display service - parking locations and scheduled works
1 parent 8b8d024 commit 18e948c

File tree

18 files changed

+427
-46
lines changed

18 files changed

+427
-46
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ I reccommend having a read through the [Retrofit docs](http://square.github.io/r
1313

1414
* Realtime
1515
* GTFS
16+
* Display (Parking Locations, Scheduled Works)
1617

1718
##How to use
1819

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,56 @@
11
package api;
22

3-
import retrofit.RestAdapter;
4-
import util.Util;
53
import android.test.AndroidTestCase;
64

75
import com.atapiwrapper.library.BuildConfig;
86
import com.atapiwrapper.library.api.AtApi;
97
import com.atapiwrapper.library.api.model.ServerResponse;
10-
import com.atapiwrapper.library.api.model.realtime.vehiclelocations.VehicleLocationResponse;
11-
import com.atapiwrapper.library.api.service.RealtimeService;
8+
import com.atapiwrapper.library.api.model.display.ParkingLocation;
9+
import com.atapiwrapper.library.api.model.display.ScheduledWork;
10+
import com.atapiwrapper.library.api.service.DisplayService;
11+
12+
import java.util.List;
13+
14+
import retrofit.RestAdapter;
15+
import util.Util;
1216

1317
/**
1418
* Tests the realtime api requests and responses
1519
*/
1620
public class TATDisplays extends AndroidTestCase {
1721

1822
private RestAdapter mRestAdapter;
19-
private RealtimeService mRealtimeService;
23+
private DisplayService mDisplayService;
2024

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

2428
AtApi api = new AtApi(BuildConfig.API_KEY);
2529
mRestAdapter = api.getRestAdapter(Util.getClient());
26-
mRealtimeService = mRestAdapter.create(RealtimeService.class);
30+
mDisplayService = mRestAdapter.create(DisplayService.class);
2731
}
2832

29-
public void testVehicleLocations() {
33+
public void testParkingLocations() {
3034

31-
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocations();
35+
ServerResponse<List<ParkingLocation>> result = mDisplayService.parkingLocations();
3236

3337
//make sure we have content
3438
assertNotNull(result);
3539
assertNotNull(result.getStatus());
3640
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
3741
assertNotNull(result.getResponse());
38-
assertNotNull(result.getResponse().getVehicleLocations());
39-
assertTrue(result.getResponse().getVehicleLocations().size() > 0);
42+
assertTrue(result.getResponse().size() > 0);
4043
}
41-
public void testVehicleLocationsByTripId() {
42-
43-
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId("2212GW582020451266647");
44-
45-
//make sure we have content
46-
assertNotNull(result);
47-
assertNotNull(result.getStatus());
48-
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
49-
assertNotNull(result.getResponse());
50-
assertNotNull(result.getResponse().getVehicleLocations());
51-
assertTrue(result.getResponse().getVehicleLocations().size() == 1);
52-
}
53-
54-
public void testVehicleLocationsByVehicleId() {
5544

56-
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId(
57-
"4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");
45+
public void testScheduledWorks() {
46+
ServerResponse<List<ScheduledWork>> result = mDisplayService.scheduledWorks();
5847

5948
//make sure we have content
6049
assertNotNull(result);
6150
assertNotNull(result.getStatus());
6251
assertEquals(result.getStatus(), ServerResponse.STATUS_OK);
6352
assertNotNull(result.getResponse());
64-
assertNotNull(result.getResponse().getVehicleLocations());
65-
assertTrue(result.getResponse().getVehicleLocations().size() == 1);
53+
assertTrue(result.getResponse().size() > 0);
6654
}
6755

6856
}

lib/src/androidTest/java/api/TATRealtime.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TATRealtime extends AndroidTestCase {
2929

3030
public void testVehicleLocations() {
3131

32-
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocations();
32+
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehicleLocations();
3333

3434
//make sure we have content
3535
assertNotNull(result);
@@ -41,7 +41,7 @@ public void testVehicleLocations() {
4141
}
4242
public void testVehicleLocationsByTripId() {
4343

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

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

5555
public void testVehicleLocationsByVehicleId() {
5656

57-
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehiclelocationsByTripId("4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");
57+
ServerResponse<VehicleLocationResponse> result = mRealtimeService.vehicleLocationsByTripId(
58+
"4f9abf121ddd83f8eeed3a42ac2e159615fe5b3800333d0b9ca51f38700d1678");
5859

5960
//make sure we have content
6061
assertNotNull(result);

lib/src/main/java/com/atapiwrapper/library/api/AtApi.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.atapiwrapper.library.api;
22

3-
import com.atapiwrapper.library.api.service.DisplaysService;
3+
import com.atapiwrapper.library.api.model.geometry.Geometry;
4+
import com.atapiwrapper.library.api.model.geometry.GeometryDeserializer;
5+
import com.atapiwrapper.library.api.service.DisplayService;
46
import com.atapiwrapper.library.api.service.GtfsService;
57
import com.atapiwrapper.library.api.service.RealtimeService;
68
import com.atapiwrapper.library.core.ATConstants;
9+
import com.fasterxml.jackson.core.Version;
710
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.module.SimpleModule;
812
import com.squareup.okhttp.OkHttpClient;
913

1014
import retrofit.RequestInterceptor;
@@ -46,6 +50,12 @@ public RestAdapter getRestAdapter() {
4650
public RestAdapter getRestAdapter(OkHttpClient client) {
4751
//setup mapper which uses custom deserializer
4852
final ObjectMapper mapper = new ObjectMapper();
53+
54+
//setup custom deserializer module to handle geometry
55+
SimpleModule module = new SimpleModule("GeometryDeserializerModule", new Version(1, 0, 0, null));
56+
module.addDeserializer(Geometry.class, new GeometryDeserializer());
57+
mapper.registerModule(module);
58+
4959
JacksonConverter converter = new JacksonConverter(mapper);
5060

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

76-
public DisplaysService getDisplaysService() {
86+
public DisplayService getDisplaysService() {
7787
if (null == mRestAdapter) mRestAdapter = getRestAdapter();
78-
return mRestAdapter.create(DisplaysService.class);
88+
return mRestAdapter.create(DisplayService.class);
7989
}
8090

8191
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.atapiwrapper.library.api.model.display;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
public class ParkingLocation implements Parcelable {
9+
@JsonProperty("id") private Integer id;
10+
@JsonProperty("address") private String address;
11+
@JsonProperty("mobilitySpaces") private Integer mobilitySpaces;
12+
@JsonProperty("name") private String name;
13+
@JsonProperty("longitude") private Double longitude;
14+
@JsonProperty("latitude") private Double latitude;
15+
@JsonProperty("type") private String type;
16+
17+
public Integer getId() {
18+
return id;
19+
}
20+
21+
public String getAddress() {
22+
return address;
23+
}
24+
25+
public Integer getMobilitySpaces() {
26+
return mobilitySpaces;
27+
}
28+
29+
public String getName() {
30+
return name;
31+
}
32+
33+
public Double getLongitude() {
34+
return longitude;
35+
}
36+
37+
public Double getLatitude() {
38+
return latitude;
39+
}
40+
41+
public String getType() {
42+
return type;
43+
}
44+
45+
@Override public int describeContents() {
46+
return 0;
47+
}
48+
49+
@Override public void writeToParcel(Parcel dest, int flags) {
50+
dest.writeValue(this.id);
51+
dest.writeString(this.address);
52+
dest.writeValue(this.mobilitySpaces);
53+
dest.writeString(this.name);
54+
dest.writeValue(this.longitude);
55+
dest.writeValue(this.latitude);
56+
dest.writeString(this.type);
57+
}
58+
59+
public ParkingLocation() {}
60+
61+
private ParkingLocation(Parcel in) {
62+
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
63+
this.address = in.readString();
64+
this.mobilitySpaces = (Integer) in.readValue(Integer.class.getClassLoader());
65+
this.name = in.readString();
66+
this.longitude = (Double) in.readValue(Double.class.getClassLoader());
67+
this.latitude = (Double) in.readValue(Double.class.getClassLoader());
68+
this.type = in.readString();
69+
}
70+
71+
public static Parcelable.Creator<ParkingLocation> CREATOR = new Parcelable.Creator<ParkingLocation>() {
72+
public ParkingLocation createFromParcel(Parcel source) {
73+
return new ParkingLocation(source);
74+
}
75+
76+
public ParkingLocation[] newArray(int size) {
77+
return new ParkingLocation[size];
78+
}
79+
};
80+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.atapiwrapper.library.api.model.display;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
import com.atapiwrapper.library.api.model.geometry.Geometry;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
public class ScheduledWork implements Parcelable {
10+
@JsonProperty("region") private String region;
11+
@JsonProperty("startDate") private String startDate;
12+
@JsonProperty("lastUpdated") private String lastUpdated;
13+
@JsonProperty("endDate") private String endDate;
14+
@JsonProperty("code") private String code;
15+
@JsonProperty("type") private String type;
16+
@JsonProperty("geometry") private Geometry geometry;
17+
@JsonProperty("id") private Integer id;
18+
@JsonProperty("contractorCompany") private String contractorCompany;
19+
@JsonProperty("suburb") private String suburb;
20+
@JsonProperty("address") private String address;
21+
@JsonProperty("description") private String description;
22+
@JsonProperty("name") private String name;
23+
@JsonProperty("longitude") private Double longitude;
24+
@JsonProperty("latitude") private Double latitude;
25+
26+
public String getRegion() {
27+
return region;
28+
}
29+
30+
public String getStartDate() {
31+
return startDate;
32+
}
33+
34+
public String getLastUpdated() {
35+
return lastUpdated;
36+
}
37+
38+
public String getEndDate() {
39+
return endDate;
40+
}
41+
42+
public String getCode() {
43+
return code;
44+
}
45+
46+
public String getType() {
47+
return type;
48+
}
49+
50+
public Geometry getGeometry() {
51+
return geometry;
52+
}
53+
54+
public Integer getId() {
55+
return id;
56+
}
57+
58+
public String getContractorCompany() {
59+
return contractorCompany;
60+
}
61+
62+
public String getSuburb() {
63+
return suburb;
64+
}
65+
66+
public String getAddress() {
67+
return address;
68+
}
69+
70+
public String getDescription() {
71+
return description;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
public Double getLongitude() {
79+
return longitude;
80+
}
81+
82+
public Double getLatitude() {
83+
return latitude;
84+
}
85+
86+
87+
@Override public int describeContents() { return 0; }
88+
89+
@Override public void writeToParcel(Parcel dest, int flags) {
90+
dest.writeString(this.region);
91+
dest.writeString(this.startDate);
92+
dest.writeString(this.lastUpdated);
93+
dest.writeString(this.endDate);
94+
dest.writeString(this.code);
95+
dest.writeString(this.type);
96+
// dest.writeParcelable(this.geometry, flags);
97+
dest.writeValue(this.id);
98+
dest.writeString(this.contractorCompany);
99+
dest.writeString(this.suburb);
100+
dest.writeString(this.address);
101+
dest.writeString(this.description);
102+
dest.writeString(this.name);
103+
dest.writeValue(this.longitude);
104+
dest.writeValue(this.latitude);
105+
}
106+
107+
public ScheduledWork() {}
108+
109+
private ScheduledWork(Parcel in) {
110+
this.region = in.readString();
111+
this.startDate = in.readString();
112+
this.lastUpdated = in.readString();
113+
this.endDate = in.readString();
114+
this.code = in.readString();
115+
this.type = in.readString();
116+
// this.geometry = in.readParcelable(Geometry.class.getClassLoader());
117+
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
118+
this.contractorCompany = in.readString();
119+
this.suburb = in.readString();
120+
this.address = in.readString();
121+
this.description = in.readString();
122+
this.name = in.readString();
123+
this.longitude = (Double) in.readValue(Double.class.getClassLoader());
124+
this.latitude = (Double) in.readValue(Double.class.getClassLoader());
125+
}
126+
127+
public static Parcelable.Creator<ScheduledWork> CREATOR = new Parcelable.Creator<ScheduledWork>() {
128+
public ScheduledWork createFromParcel(Parcel source) {return new ScheduledWork(source);}
129+
130+
public ScheduledWork[] newArray(int size) {return new ScheduledWork[size];}
131+
};
132+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.atapiwrapper.library.api.model.geometry;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Geometry returned by the server can be of different types determined by the type attribute. This is handled by a custom deserializerin
7+
* {@link com.atapiwrapper.library.api.AtApi}
8+
*/
9+
public abstract class Geometry {
10+
@JsonProperty("encoded") protected boolean encoded;
11+
@JsonProperty("type") protected String type;
12+
13+
public boolean isEncoded() {
14+
return encoded;
15+
}
16+
17+
public String getType() {
18+
return type;
19+
}
20+
}

0 commit comments

Comments
 (0)