diff --git a/src/main/java/com/lob/protocol/response/CheckResponse.java b/src/main/java/com/lob/protocol/response/CheckResponse.java index df85aaff..373c6ab6 100644 --- a/src/main/java/com/lob/protocol/response/CheckResponse.java +++ b/src/main/java/com/lob/protocol/response/CheckResponse.java @@ -21,7 +21,9 @@ public class CheckResponse extends AbstractLobResponse { @JsonProperty private final BankAccountResponse bankAccount; @JsonProperty private final String message; @JsonProperty private final String url; - @JsonProperty private final TrackingResponse tracking; + @JsonProperty private final String carrier; + @JsonProperty private final String trackingNumber; + @JsonProperty private final List trackingEvents; @JsonProperty private final DateTime expectedDeliveryDate; @JsonProperty private final List thumbnails; @@ -36,7 +38,9 @@ public CheckResponse( @JsonProperty("bank_account") final BankAccountResponse bankAccount, @JsonProperty("message") final String message, @JsonProperty("url") final String url, - @JsonProperty("tracking") final TrackingResponse tracking, + @JsonProperty("carrier") final String carrier, + @JsonProperty("tracking_number") final String trackingNumber, + @JsonProperty("tracking_events") final List trackingEvents, @JsonProperty("description") final String description, @JsonProperty("date_created") final DateTime dateCreated, @JsonProperty("date_modified") final DateTime dateModified, @@ -54,7 +58,9 @@ public CheckResponse( this.bankAccount = bankAccount; this.message = message; this.url = url; - this.tracking = tracking; + this.carrier = carrier; + this.trackingNumber = trackingNumber; + this.trackingEvents = trackingEvents; this.expectedDeliveryDate = expectedDeliveryDate; this.thumbnails = thumbnails; } @@ -95,8 +101,16 @@ public String getUrl() { return url; } - public TrackingResponse getTracking() { - return tracking; + public String getCarrier() { + return carrier; + } + + public String getTrackingNumber() { + return trackingNumber; + } + + public List getTrackingEvents() { + return defensiveCopy(this.trackingEvents); } public DateTime getExpectedDeliveryDate() { @@ -119,7 +133,9 @@ public String toString() { ", bankAccount=" + bankAccount + ", message='" + message + '\'' + ", url='" + url + '\'' + - ", tracking=" + tracking + + ", carrier='" + carrier + '\'' + + ", trackingNumber='" + trackingNumber + '\'' + + ", trackingEvents='" + trackingEvents + '\'' + ", expectedDeliveryDate=" + expectedDeliveryDate + ", thumbnails=" + thumbnails + super.toString(); diff --git a/src/main/java/com/lob/protocol/response/LetterResponse.java b/src/main/java/com/lob/protocol/response/LetterResponse.java index 23a494cb..dc571616 100644 --- a/src/main/java/com/lob/protocol/response/LetterResponse.java +++ b/src/main/java/com/lob/protocol/response/LetterResponse.java @@ -9,6 +9,8 @@ import java.util.List; import java.util.Map; +import static com.lob.Util.defensiveCopy; + public class LetterResponse extends AbstractLobResponse { @JsonProperty private final LetterId id; @JsonProperty private final AddressResponse to; @@ -24,7 +26,9 @@ public class LetterResponse extends AbstractLobResponse { @JsonProperty private final String url; @JsonProperty private final DateTime expectedDeliveryDate; @JsonProperty private final List thumbnails; - @JsonProperty private final TrackingResponse tracking; + @JsonProperty private final String carrier; + @JsonProperty private final String trackingNumber; + @JsonProperty private final List trackingEvents; @JsonCreator public LetterResponse( @@ -42,7 +46,9 @@ public LetterResponse( @JsonProperty("url") final String url, @JsonProperty("expected_delivery_date") final DateTime expectedDeliveryDate, @JsonProperty("thumbnails") final List thumbnails, - @JsonProperty("tracking") final TrackingResponse tracking, + @JsonProperty("carrier") final String carrier, + @JsonProperty("tracking_number") final String trackingNumber, + @JsonProperty("tracking_events") final List trackingEvents, @JsonProperty("description") final String description, @JsonProperty("date_created") final DateTime dateCreated, @JsonProperty("date_modified") final DateTime dateModified, @@ -63,7 +69,9 @@ public LetterResponse( this.url = url; this.expectedDeliveryDate = expectedDeliveryDate; this.thumbnails = thumbnails; - this.tracking = tracking; + this.carrier = carrier; + this.trackingNumber = trackingNumber; + this.trackingEvents = trackingEvents; } public LetterId getId() { return id; } @@ -94,9 +102,13 @@ public LetterResponse( public DateTime getExpectedDeliveryDate() { return expectedDeliveryDate; } - public List getThumbnails() { return thumbnails; } + public List getThumbnails() { return defensiveCopy(this.thumbnails); } + + public String getCarrier() { return carrier; } + + public String getTrackingNumber() { return trackingNumber; } - public TrackingResponse getTracking() { return tracking; } + public List getTrackingEvents() { return defensiveCopy(this.trackingEvents); } @Override public String toString() { @@ -115,7 +127,9 @@ public String toString() { ", url='" + url + "'" + ", expectedDeliveryDate='" + expectedDeliveryDate + "'" + ", thumbnails='" + thumbnails + "'" + - ", tracking='" + tracking + "'" + + ", carrier='" + carrier + "'" + + ", trackingNumber='" + trackingNumber + "'" + + ", trackingEvents='" + trackingEvents + "'" + super.toString(); } diff --git a/src/main/java/com/lob/protocol/response/PostcardResponse.java b/src/main/java/com/lob/protocol/response/PostcardResponse.java index 009ca6fa..1b49c5cc 100644 --- a/src/main/java/com/lob/protocol/response/PostcardResponse.java +++ b/src/main/java/com/lob/protocol/response/PostcardResponse.java @@ -10,6 +10,8 @@ import java.util.List; import java.util.Map; +import static com.lob.Util.defensiveCopy; + public class PostcardResponse extends AbstractLobResponse { @JsonProperty private final PostcardId id; @JsonProperty private final String message; @@ -20,7 +22,8 @@ public class PostcardResponse extends AbstractLobResponse { @JsonProperty private final String url; @JsonProperty private final DateTime expectedDeliveryDate; @JsonProperty private final List thumbnails; - @JsonProperty private final TrackingResponse tracking; + @JsonProperty private final String carrier; + @JsonProperty private final List trackingEvents; @JsonCreator public PostcardResponse( @@ -33,7 +36,8 @@ public PostcardResponse( @JsonProperty("url") final String url, @JsonProperty("expected_delivery_date") final DateTime expectedDeliveryDate, @JsonProperty("thumbnails") final List thumbnails, - @JsonProperty("tracking") final TrackingResponse tracking, + @JsonProperty("carrier") final String carrier, + @JsonProperty("tracking_events") final List trackingEvents, @JsonProperty("description") final String description, @JsonProperty("date_created") final DateTime dateCreated, @JsonProperty("date_modified") final DateTime dateModified, @@ -49,7 +53,8 @@ public PostcardResponse( this.url = url; this.expectedDeliveryDate = expectedDeliveryDate; this.thumbnails = thumbnails; - this.tracking = tracking; + this.carrier = carrier; + this.trackingEvents = trackingEvents; } public PostcardId getId() { @@ -86,11 +91,15 @@ public DateTime getExpectedDeliveryDate() { } public List getThumbnails() { - return thumbnails; + return defensiveCopy(this.thumbnails); + } + + public String getCarrier() { + return carrier; } - public TrackingResponse getTracking() { - return tracking; + public List getTrackingEvents() { + return defensiveCopy(this.trackingEvents); } @Override @@ -105,7 +114,8 @@ public String toString() { ", url='" + url + '\'' + ", expectedDeliveryDate='" + expectedDeliveryDate + '\'' + ", thumbnails='" + thumbnails + '\'' + - ", tracking='" + tracking + '\'' + + ", carrier='" + carrier + '\'' + + ", trackingEvents='" + trackingEvents + '\'' + super.toString(); } } diff --git a/src/main/java/com/lob/protocol/response/TrackingEventResponse.java b/src/main/java/com/lob/protocol/response/TrackingEventResponse.java index cfb99ebc..2c85b5ce 100644 --- a/src/main/java/com/lob/protocol/response/TrackingEventResponse.java +++ b/src/main/java/com/lob/protocol/response/TrackingEventResponse.java @@ -68,4 +68,4 @@ public String toString() { ", object='" + object + '\'' + '}'; } -} \ No newline at end of file +} diff --git a/src/main/java/com/lob/protocol/response/TrackingResponse.java b/src/main/java/com/lob/protocol/response/TrackingResponse.java index 2141c316..0138ba6a 100644 --- a/src/main/java/com/lob/protocol/response/TrackingResponse.java +++ b/src/main/java/com/lob/protocol/response/TrackingResponse.java @@ -9,9 +9,9 @@ public class TrackingResponse { @JsonProperty("id") private final TrackingId id; @JsonProperty("tracking_number") private final String trackingNumber; - @JsonProperty("carrier") private final String carrier; - @JsonProperty("events") private final List events; - @JsonProperty("object") private final String object; + @JsonProperty("carrier") private final String carrier; + @JsonProperty("events") private final List events; + @JsonProperty("object") private final String object; @JsonCreator public TrackingResponse( @@ -57,4 +57,4 @@ public String toString() { ", object='" + object + '\'' + '}'; } -} \ No newline at end of file +} diff --git a/src/test/java/com/lob/client/test/CheckTest.java b/src/test/java/com/lob/client/test/CheckTest.java index a3b058e3..a8a3af5b 100644 --- a/src/test/java/com/lob/client/test/CheckTest.java +++ b/src/test/java/com/lob/client/test/CheckTest.java @@ -44,12 +44,9 @@ public void testListChecks() throws Exception { final CheckResponse response = responseList.get(0); assertTrue(response instanceof CheckResponse); - assertNotNull(response.getTracking().toString()); - assertNotNull(response.getTracking().getEvents()); - assertNotNull(response.getTracking().getId()); - assertNull(response.getTracking().getTrackingNumber()); - assertNotNull(response.getTracking().getCarrier()); - assertThat(response.getTracking().getObject(), is("tracking")); + assertNotNull(response.getTrackingEvents()); + assertNull(response.getTrackingNumber()); + assertNotNull(response.getCarrier()); assertThat(responseList.getObject(), is("list")); assertNotNull(responseList.toString()); assertNotNull(response.toString()); diff --git a/src/test/java/com/lob/client/test/JobTest.java b/src/test/java/com/lob/client/test/JobTest.java index 54ebf972..8f6c1010 100644 --- a/src/test/java/com/lob/client/test/JobTest.java +++ b/src/test/java/com/lob/client/test/JobTest.java @@ -34,6 +34,11 @@ public void testListJobs() throws Exception { assertNotNull(responseList.toString()); assertNotNull(response.toString()); assertNotNull(response.getTracking()); + assertNotNull(response.getTracking().getEvents()); + assertNotNull(response.getTracking().getId()); + assertNull(response.getTracking().getTrackingNumber()); + assertNotNull(response.getTracking().getCarrier()); + assertThat(response.getTracking().getObject(), is("tracking")); } @Test diff --git a/src/test/java/com/lob/client/test/LetterTest.java b/src/test/java/com/lob/client/test/LetterTest.java index 6511de28..f9914909 100644 --- a/src/test/java/com/lob/client/test/LetterTest.java +++ b/src/test/java/com/lob/client/test/LetterTest.java @@ -88,7 +88,9 @@ public void testCreateLetter() throws Exception { assertFalse(response.isReturnEnvelope()); assertNull(response.getPerforatedPage()); assertEquals(response.getThumbnails().size(), 1); - assertNotNull(response.getTracking()); + assertNotNull(response.getTrackingEvents()); + assertNull(response.getTrackingNumber()); + assertNotNull(response.getCarrier()); assertThat(response.getPages(), is(0)); assertTrue(response.getId() instanceof LetterId); assertNull(response.getPrice()); diff --git a/src/test/java/com/lob/client/test/PostcardTest.java b/src/test/java/com/lob/client/test/PostcardTest.java index 6ad64b16..6ce0dff8 100644 --- a/src/test/java/com/lob/client/test/PostcardTest.java +++ b/src/test/java/com/lob/client/test/PostcardTest.java @@ -180,14 +180,11 @@ public void testCreatePostcardLocalFile() throws Exception { @Test public void testTrackingEvents() throws Exception { final PostcardResponse response = client.getPostcard(PostcardId.parse("psc_d1f8830b03cde4ef")).get(); - final TrackingResponse trackings = response.getTracking(); - assertEquals(trackings.getId().toString(), "trk_b4bb17e6d0e5c3d4"); - assertNull(trackings.getTrackingNumber()); - assertEquals(trackings.getCarrier(), "USPS"); - assertEquals(trackings.getEvents().size(), 1); + assertEquals(response.getCarrier(), "USPS"); + assertEquals(response.getTrackingEvents().size(), 1); - final TrackingEventResponse event = trackings.getEvents().get(0); + final TrackingEventResponse event = response.getTrackingEvents().get(0); assertEquals(event.getName(), "Scanned"); assertEquals(event.getLocation(), "14692");