Skip to content

Commit 1cbcb79

Browse files
committed
Deprecates SMS send without parameters action
1 parent f6a2345 commit 1cbcb79

8 files changed

Lines changed: 101 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
3030
- `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated
3131
- `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated
3232
- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated
33+
- `pl.smsapi.api.SmsFactory.actionSend` without parameters marked as deprecated
34+
- `pl.smsapi.api.action.sms.SMSSend` without parameters marked as deprecated
3335

3436
### Removed
3537
- legacy `phonebook.do` contacts API support

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public class Example {
6363

6464
SmsFactory smsApi = new SmsFactory(client, proxy);
6565

66-
SMSSend action = smsApi.actionSend()
67-
.setTo("000000000")
68-
.setText("test");
66+
SMSSend action = smsApi.actionSend("000000000", "test message");
6967

7068
StatusResponse result = action.execute();
7169

@@ -114,9 +112,7 @@ public class Example {
114112

115113
String[] to = {"000000000", "000000001"};
116114

117-
SMSSend action = smsApi.actionSend()
118-
.setTo(to)
119-
.setText("test");
115+
SMSSend action = smsApi.actionSend(to, "test message");
120116

121117
StatusResponse result = action.execute();
122118

src/main/java/pl/smsapi/api/SmsFactory.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public SmsFactory(Client client, Proxy proxy) {
2020
super(client, proxy);
2121
}
2222

23+
/**
24+
* @deprecated use {@link #actionSend(String, String)} or {@link #actionSend(String[], String)} instead
25+
*/
26+
@Deprecated
2327
public SMSSend actionSend() {
2428
SMSSend action = new SMSSend();
2529
action.client(client);
@@ -28,15 +32,16 @@ public SMSSend actionSend() {
2832
}
2933

3034
public SMSSend actionSend(String to, String text) {
31-
String[] tos = new String[]{to};
32-
return actionSend(tos, text);
35+
SMSSend action = new SMSSend(to, text);
36+
action.client(client);
37+
action.proxy(proxy);
38+
return action;
3339
}
3440

3541
public SMSSend actionSend(String[] to, String text) {
36-
SMSSend action = actionSend();
37-
action.setTo(to);
38-
action.setText(text);
39-
42+
SMSSend action = new SMSSend(to, text);
43+
action.client(client);
44+
action.proxy(proxy);
4045
return action;
4146
}
4247

src/main/java/pl/smsapi/api/action/sms/SMSSend.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,30 @@
99

1010
public class SMSSend extends AbstractSendAction<SMSSend, SendStatusResponse> {
1111

12+
/**
13+
* @deprecated use {@link SMSSend(String, String)} or {@link SMSSend(String[], String)} instead
14+
*/
15+
@Deprecated
1216
public SMSSend() {
17+
setJson(true);
18+
params.put("encoding", "utf-8");
19+
params.put("details", "1");
20+
}
21+
22+
public SMSSend(String to, String text) {
23+
setJson(true);
24+
params.put("encoding", "utf-8");
25+
params.put("details", "1");
26+
setTo(to);
27+
setText(text);
28+
}
1329

30+
public SMSSend(String[] to, String text) {
1431
setJson(true);
1532
params.put("encoding", "utf-8");
1633
params.put("details", "1");
34+
setTo(to);
35+
setText(text);
1736
}
1837

1938
@Override
@@ -25,7 +44,10 @@ protected String endPoint() {
2544
* Set SMS text message.
2645
* <p/>
2746
* Content of one message is normally 160 characters per single SMS or 70 in case of using at least one special character
47+
*
48+
* @deprecated use {@link SMSSend(String, String)} or {@link SMSSend(String[], String)} instead
2849
*/
50+
@Deprecated
2951
public SMSSend setText(String text) {
3052
params.put("message", text);
3153
return this;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package pl.smsapi.api.action.sms;
2+
3+
public class StatusJsonMother {
4+
5+
public static String create() {
6+
return
7+
"{" +
8+
" \"count\":1," +
9+
" \"parts\":1," +
10+
" \"list\":[" +
11+
" {" +
12+
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
13+
" \"points\":0.21," +
14+
" \"number\":\"48123123123\"," +
15+
" \"date_sent\":1717500698," +
16+
" \"submitted_number\":\"123123123\"," +
17+
" \"status\":\"QUEUE\"," +
18+
" \"error\":null," +
19+
" \"idx\":null," +
20+
" \"parts\":1" +
21+
" }" +
22+
" ]" +
23+
"}";
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package pl.smsapi.api.action.sms;
2+
3+
import org.junit.Test;
4+
import pl.smsapi.exception.SmsapiException;
5+
import pl.smsapi.test.doubles.ClientStub;
6+
import pl.smsapi.test.doubles.ProxyRequestSpy;
7+
8+
import java.util.HashMap;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class SMSSendTest {
13+
14+
@Test
15+
public void executeSendSms() throws SmsapiException {
16+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
17+
SMSSend action = new SMSSend("48123123123", "test message");
18+
action.client(new ClientStub());
19+
action.proxy(requestStub);
20+
21+
action.execute();
22+
23+
assertEquals("POST", requestStub.requestMethod);
24+
assertEquals("sms.do", requestStub.requestEndpoint);
25+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
26+
expectedRequestPayload.put("message", "test message");
27+
expectedRequestPayload.put("to", "48123123123");
28+
expectedRequestPayload.put("format", "json");
29+
expectedRequestPayload.put("details", "1");
30+
expectedRequestPayload.put("encoding", "utf-8");
31+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
32+
}
33+
}

src/test/java/pl/smsapi/api/action/sms/SmsFactoryTest.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public void setUp() {
3131

3232
@Test
3333
public void sendSms() throws SmsapiException {
34-
SMSSend actionSend = apiFactory.actionSend()
35-
.setText("test message")
36-
.setTo(numberTest);
34+
SMSSend actionSend = apiFactory.actionSend(numberTest, "test message");
3735

3836
SendStatusResponse responseAdd = actionSend.execute();
3937

@@ -44,10 +42,7 @@ public void sendSms() throws SmsapiException {
4442

4543
@Test
4644
public void getSms() throws SmsapiException {
47-
SendStatusResponse responseSend = apiFactory.actionSend()
48-
.setText("test message")
49-
.setTo(numberTest)
50-
.execute();
45+
SendStatusResponse responseSend = apiFactory.actionSend(numberTest, "test message").execute();
5146

5247
Optional<MessageResponse> sendMessageResponse = responseSend.list.stream().findFirst();
5348
assertTrue(sendMessageResponse.isPresent());
@@ -62,11 +57,9 @@ public void getSms() throws SmsapiException {
6257

6358
@Test
6459
public void deleteSms() throws SmsapiException {
65-
SendStatusResponse responseSend = apiFactory.actionSend()
66-
.setText("test message")
67-
.setTo(numberTest)
68-
.setDateSent((new Date().getTime() / 1000) + 120)
69-
.execute();
60+
SendStatusResponse responseSend = apiFactory.actionSend(numberTest, "test message")
61+
.setDateSent((new Date().getTime() / 1000) + 120)
62+
.execute();
7063

7164
Optional<MessageResponse> sendMessageResponse = responseSend.list.stream().findFirst();
7265
assertTrue(sendMessageResponse.isPresent());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SendStatusResponseTest {
1717

1818
@Test
1919
public void deserialize_response() throws SmsapiException {
20-
SMSSend action = new SMSSend();
20+
SMSSend action = new SMSSend("48327201200", "test message");
2121
action.client(new ClientStub());
2222
action.proxy(new ProxyResponseStub(
2323
"{" +

0 commit comments

Comments
 (0)