Skip to content

Commit 0a7b786

Browse files
authored
Merge pull request #21 from smsapi/vms-api
Vms API
2 parents ecf209b + dcac3a1 commit 0a7b786

11 files changed

Lines changed: 497 additions & 143 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2424
- `pl.smsapi.exception.ClientException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead
2525
- `pl.smsapi.exception.HostException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead
2626
- all client and server side errors are now being translated to `pl.smsapi.exception.SmsapiErrorException` or `pl.smsapi.exception.SmsapiLegacyErrorException`
27+
- `pl.smsapi.api.VmsFactory.actionSend` without parameters marked as deprecated
28+
- `pl.smsapi.api.VmsFactory.actionGet` without parameters marked as deprecated
29+
- `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated
30+
- `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated
31+
- `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated
32+
- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated
2733

2834
### Removed
2935
- legacy `phonebook.do` contacts API support

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

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import pl.smsapi.api.action.vms.VMSSend;
77
import pl.smsapi.proxy.Proxy;
88

9+
import java.io.File;
10+
import java.io.IOException;
11+
912
public class VmsFactory extends ActionFactory {
1013

1114
/**
@@ -20,6 +23,10 @@ public VmsFactory(Client client, Proxy proxy) {
2023
super(client, proxy);
2124
}
2225

26+
/**
27+
* @deprecated use {@link #actionSend(String, String)} or {@link #actionSend(String[], String)}
28+
* or {@link #actionSend(String, File)} or {@link #actionSend(String[], File)} instead
29+
*/
2330
public VMSSend actionSend() {
2431
VMSSend action = new VMSSend();
2532
action.client(client);
@@ -28,18 +35,40 @@ public VMSSend actionSend() {
2835
}
2936

3037
public VMSSend actionSend(String to, String tts) {
31-
String[] tos = new String[]{to};
32-
return actionSend(tos, tts);
38+
VMSSend action = new VMSSend(to, tts);
39+
action.client(client);
40+
action.proxy(proxy);
41+
42+
return action;
3343
}
3444

3545
public VMSSend actionSend(String[] to, String tts) {
36-
VMSSend action = actionSend();
37-
action.setTo(to);
38-
action.setTts(tts);
46+
VMSSend action = new VMSSend(to, tts);
47+
action.client(client);
48+
action.proxy(proxy);
49+
50+
return action;
51+
}
52+
53+
public VMSSend actionSend(String to, File file) throws IOException {
54+
VMSSend action = new VMSSend(to, file);
55+
action.client(client);
56+
action.proxy(proxy);
3957

4058
return action;
4159
}
4260

61+
public VMSSend actionSend(String[] to, File file) throws IOException {
62+
VMSSend action = new VMSSend(to, file);
63+
action.client(client);
64+
action.proxy(proxy);
65+
66+
return action;
67+
}
68+
69+
/**
70+
* @deprecated use {@link #actionGet(String)} instead
71+
*/
4372
public VMSGet actionGet() {
4473
VMSGet action = new VMSGet();
4574
action.client(client);
@@ -48,11 +77,15 @@ public VMSGet actionGet() {
4877
}
4978

5079
public VMSGet actionGet(String id) {
51-
VMSGet action = actionGet();
52-
action.id(id);
80+
VMSGet action = new VMSGet(id);
81+
action.client(client);
82+
action.proxy(proxy);
5383
return action;
5484
}
5585

86+
/**
87+
* @deprecated use {@link #actionDelete(String)} instead
88+
*/
5689
public VMSDelete actionDelete() {
5790
VMSDelete action = new VMSDelete();
5891
action.client(client);
@@ -61,8 +94,9 @@ public VMSDelete actionDelete() {
6194
}
6295

6396
public VMSDelete actionDelete(String id) {
64-
VMSDelete action = actionDelete();
65-
action.id(id);
97+
VMSDelete action = new VMSDelete(id);
98+
action.client(client);
99+
action.proxy(proxy);
66100
return action;
67101
}
68102
}

src/main/java/pl/smsapi/api/action/vms/VMSDelete.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@
77

88
public class VMSDelete extends AbstractAction<CountableResponse> {
99

10+
/**
11+
* @deprecated use {@link VMSDelete(String)} or {@link VMSDelete(String[])} instead
12+
*/
1013
public VMSDelete() {
1114
setJson(true);
1215
id("");
1316
}
1417

18+
public VMSDelete(String id) {
19+
setJson(true);
20+
params.put("sch_del", id);
21+
}
22+
23+
public VMSDelete(String[] ids) {
24+
setJson(true);
25+
params.put("sch_del", StringUtils.join(ids, '|'));
26+
}
27+
1528
/**
1629
* Set ID of message to delete.
1730
* <p/>
1831
* This id was returned after sending message.
32+
*
33+
* @deprecated set id while constructing action, {@link VMSDelete(String)}
1934
*/
2035
public VMSDelete id(String id) {
2136
params.put("sch_del", id);
@@ -26,6 +41,8 @@ public VMSDelete id(String id) {
2641
* Set ID of message to delete.
2742
* <p/>
2843
* This id was returned after sending message.
44+
*
45+
* @deprecated set ids while constructing action, {@link VMSDelete(String[])}
2946
*/
3047
public VMSDelete ids(String[] ids) {
3148
params.put("sch_del", StringUtils.join(ids, '|'));

src/main/java/pl/smsapi/api/action/vms/VMSGet.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@
77

88
public class VMSGet extends AbstractAction<StatusResponse> {
99

10+
/**
11+
* @deprecated use {@link VMSGet(String)} or {@link VMSGet(String[])} instead
12+
*/
1013
public VMSGet() {
1114
setJson(true);
1215
id("");
1316
}
1417

18+
public VMSGet(String id) {
19+
setJson(true);
20+
params.put("status", id);
21+
}
22+
23+
public VMSGet(String[] ids) {
24+
setJson(true);
25+
params.put("status", StringUtils.join(ids, '|'));
26+
}
27+
1528
/**
1629
* Set ID of message to check.
1730
* <p/>
1831
* This id was returned after sending message.
32+
*
33+
* @deprecated set id while constructing action, {@link VMSGet(String)}
1934
*/
2035
public VMSGet id(String id) {
2136
params.put("status", id);
@@ -26,6 +41,8 @@ public VMSGet id(String id) {
2641
* Set IDs of messages to check.
2742
* <p/>
2843
* This id was returned after sending message.
44+
*
45+
* @deprecated set id while constructing action, {@link VMSGet(String[])}
2946
*/
3047
public VMSGet ids(String[] ids) {
3148
params.put("status", StringUtils.join(ids, '|'));

src/main/java/pl/smsapi/api/action/vms/VMSSend.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
import pl.smsapi.api.action.AbstractSendAction;
55
import pl.smsapi.api.response.StatusResponse;
66

7-
import java.io.File;
8-
import java.io.FileInputStream;
9-
import java.io.FileNotFoundException;
10-
import java.io.InputStream;
7+
import java.io.*;
8+
import java.nio.file.Files;
119

1210
public class VMSSend extends AbstractSendAction<VMSSend, StatusResponse> {
1311

14-
public static enum Lector {
15-
AGNIESZKA,
12+
public enum Lector {
1613
EWA,
1714
JACEK,
1815
JAN,
@@ -24,12 +21,49 @@ public String toString() {
2421
}
2522
}
2623

24+
/**
25+
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} or {@link VMSSend(String, File)}
26+
* or {@link VMSSend(String[], File)} instead
27+
*/
2728
public VMSSend() {
2829
setJson(true);
2930
}
3031

32+
public VMSSend(String to, String tts) {
33+
setJson(true);
34+
setTo(to);
35+
params.put("tts", tts);
36+
}
37+
38+
public VMSSend(String[] to, String tts) {
39+
setJson(true);
40+
setTo(to);
41+
params.put("tts", tts);
42+
}
43+
44+
public VMSSend(String to, File file) throws IOException {
45+
setJson(true);
46+
setTo(to);
47+
files.put("file", Files.newInputStream(file.toPath()));
48+
}
49+
50+
public VMSSend(String[] to, File file) throws IOException {
51+
setJson(true);
52+
setTo(to);
53+
files.put("file", Files.newInputStream(file.toPath()));
54+
}
55+
56+
public VMSSend(String[] to, InputStream file) {
57+
setJson(true);
58+
setTo(to);
59+
files.put("file", file);
60+
}
61+
3162
/**
3263
* Set local audio file.
64+
*
65+
* @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead
66+
*
3367
*/
3468
public VMSSend setFile(File file) throws FileNotFoundException {
3569
files.put("file", new FileInputStream(file));
@@ -38,6 +72,8 @@ public VMSSend setFile(File file) throws FileNotFoundException {
3872

3973
/**
4074
* Set local audio filename.
75+
*
76+
* @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead
4177
*/
4278
public VMSSend setFile(String pathFile) throws FileNotFoundException {
4379
files.put("file", new FileInputStream(pathFile));
@@ -46,6 +82,8 @@ public VMSSend setFile(String pathFile) throws FileNotFoundException {
4682

4783
/**
4884
* Set local audio stream.
85+
*
86+
* @deprecated use {@link VMSSend(String[], InputStream)} instead
4987
*/
5088
public VMSSend setFile(InputStream inputStream) {
5189
files.put("file", inputStream);
@@ -54,6 +92,8 @@ public VMSSend setFile(InputStream inputStream) {
5492

5593
/**
5694
* Set text to voice synthesizer.
95+
*
96+
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} instead
5797
*/
5898
public VMSSend setTts(String tts) {
5999
params.put("tts", tts);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pl.smsapi.api.action.vms;
2+
3+
public class StatusJsonMother {
4+
5+
public static String create() {
6+
return
7+
"{" +
8+
" \"count\":1," +
9+
" \"list\":[" +
10+
" {" +
11+
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
12+
" \"points\":0.21," +
13+
" \"number\":\"48123123123\"," +
14+
" \"date_sent\":1717500698," +
15+
" \"submitted_number\":\"123123123\"," +
16+
" \"status\":\"QUEUE\"," +
17+
" \"error\":null," +
18+
" \"idx\":null," +
19+
" \"parts\":1" +
20+
" }" +
21+
" ]" +
22+
"}";
23+
}
24+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package pl.smsapi.api.action.vms;
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 VMSDeleteTest {
13+
14+
@Test
15+
public void executeDeleteVmsRequest() throws SmsapiException {
16+
ProxyRequestSpy requestStub = new ProxyRequestSpy(
17+
"{" +
18+
"\"count\":1," +
19+
"\"list\":[" +
20+
"{" +
21+
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" +
22+
"}" +
23+
"]" +
24+
"}"
25+
);
26+
VMSDelete action = new VMSDelete("0f0f0f0f0f0f0f0f0f0f0f0f");
27+
action.client(new ClientStub());
28+
action.proxy(requestStub);
29+
30+
action.execute();
31+
32+
assertEquals("POST", requestStub.requestMethod);
33+
assertEquals("vms.do", requestStub.requestEndpoint);
34+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
35+
expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f");
36+
expectedRequestPayload.put("format", "json");
37+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
38+
}
39+
40+
@Test
41+
public void executeDeleteMultipleVmsRequest() throws SmsapiException {
42+
ProxyRequestSpy requestStub = new ProxyRequestSpy(
43+
"{" +
44+
"\"count\":1," +
45+
"\"list\":[" +
46+
"{" +
47+
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" +
48+
"}" +
49+
"]" +
50+
"}"
51+
);
52+
VMSDelete action = new VMSDelete(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"});
53+
action.client(new ClientStub());
54+
action.proxy(requestStub);
55+
56+
action.execute();
57+
58+
assertEquals("POST", requestStub.requestMethod);
59+
assertEquals("vms.do", requestStub.requestEndpoint);
60+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
61+
expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f|0f0f0f0f0f0f0f0f0f0f0f01");
62+
expectedRequestPayload.put("format", "json");
63+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
64+
}
65+
}

0 commit comments

Comments
 (0)