Skip to content

Commit a3732ed

Browse files
committed
Adds date_sent to SMS/MMS send action responses
1 parent 9d2a890 commit a3732ed

5 files changed

Lines changed: 27 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88
- new Contacts API
99
- Subusers API
1010
- `pl.smsapi.exception.SmsapiErrorException` to handle API error responses
11+
- `date_sent` to SMS/MMS send action responses
1112

1213
### Changed
1314
- `pl.smsapi.api.UserFactory.actionAdd` marked as deprecated, use `pl.smsapi.api.action.subusers.SubusersFactory.actionAdd` instead

src/main/java/pl/smsapi/api/response/MessageResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class MessageResponse implements Response {
88
private String status;
99
private String error;
1010
private String idx;
11+
private Integer toBeSentAtTimestamp;
1112

1213
public MessageResponse(String id, String points, String number, String status, String error, String idx) {
1314
this.id = id;
@@ -18,6 +19,10 @@ public MessageResponse(String id, String points, String number, String status, S
1819
this.idx = idx;
1920
}
2021

22+
public void setToBeSentAtTimestamp(int toBeSentAtTimestamp) {
23+
this.toBeSentAtTimestamp = toBeSentAtTimestamp;
24+
}
25+
2126
public String getId() {
2227
return id;
2328
}
@@ -42,6 +47,10 @@ public String getIdx() {
4247
return idx;
4348
}
4449

50+
public Integer getToBeSentAtTimestamp() {
51+
return toBeSentAtTimestamp;
52+
}
53+
4554
public boolean isError() {
4655
if (id == null || id.length() == 0) {
4756
return true;

src/main/java/pl/smsapi/api/response/SendStatusResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pl.smsapi.api.response;
22

33
import org.json.JSONArray;
4+
import org.json.JSONObject;
45

56
public class SendStatusResponse extends StatusResponse {
67

@@ -11,6 +12,13 @@ public SendStatusResponse(int count, int parts, JSONArray jsonArray) {
1112
this.parts = parts;
1213
}
1314

15+
@Override
16+
protected MessageResponse buildItem(JSONObject jsonObject) {
17+
MessageResponse response = super.buildItem(jsonObject);
18+
response.setToBeSentAtTimestamp(jsonObject.optInt("date_sent"));
19+
return response;
20+
}
21+
1422
public int getParts() {
1523
return parts;
1624
}

src/test/java/pl/smsapi/test/unit/response/SendStatusResponseTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public void deserialize_response() throws SmsapiException {
4343

4444
SendStatusResponse response = action.execute();
4545

46-
assertFalse(response.getList().isEmpty());
47-
assertEquals(1, response.getCount());
46+
assertFalse(response.list.isEmpty());
47+
assertEquals(1, response.count);
4848

49-
Optional<MessageResponse> message1 = response.getList().stream().filter(
49+
Optional<MessageResponse> message1 = response.list.stream().filter(
5050
contactResponse -> contactResponse.getId().equals("7074294081650020450")
5151
).findFirst();
5252
assertTrue(message1.isPresent());
@@ -55,5 +55,7 @@ public void deserialize_response() throws SmsapiException {
5555
assertEquals("QUEUE", message1.get().getStatus());
5656
assertEquals("", message1.get().getError());
5757
assertEquals("example-user-provided-id-123", message1.get().getIdx());
58+
assertNotNull(message1.get().getToBeSentAtTimestamp());
59+
assertEquals(1712570310, message1.get().getToBeSentAtTimestamp().intValue());
5860
}
5961
}

src/test/java/pl/smsapi/test/unit/response/StatusResponseTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public void deserialize_response() throws SmsapiException {
3737

3838
StatusResponse response = action.execute();
3939

40-
assertFalse(response.getList().isEmpty());
41-
assertEquals(1, response.getCount());
40+
assertFalse(response.list.isEmpty());
41+
assertEquals(1, response.count);
4242

43-
Optional<MessageResponse> message1 = response.getList().stream().filter(
43+
Optional<MessageResponse> message1 = response.list.stream().filter(
4444
messageResponse -> messageResponse.getId().equals("7074294081650020450")
4545
).findFirst();
4646
assertTrue(message1.isPresent());
@@ -49,5 +49,6 @@ public void deserialize_response() throws SmsapiException {
4949
assertEquals("QUEUE", message1.get().getStatus());
5050
assertEquals("", message1.get().getError());
5151
assertEquals("example-user-provided-id-123", message1.get().getIdx());
52+
assertNull(message1.get().getToBeSentAtTimestamp());
5253
}
5354
}

0 commit comments

Comments
 (0)