Skip to content
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- `pl.smsapi.exception.ClientException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead
- `pl.smsapi.exception.HostException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead
- all client and server side errors are now being translated to `pl.smsapi.exception.SmsapiErrorException` or `pl.smsapi.exception.SmsapiLegacyErrorException`
- `pl.smsapi.api.VmsFactory.actionSend` without parameters marked as deprecated
- `pl.smsapi.api.VmsFactory.actionGet` without parameters marked as deprecated
- `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated
- `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated
- `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated
- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated

### Removed
- legacy `phonebook.do` contacts API support
Expand Down
52 changes: 43 additions & 9 deletions src/main/java/pl/smsapi/api/VmsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import pl.smsapi.api.action.vms.VMSSend;
import pl.smsapi.proxy.Proxy;

import java.io.File;
import java.io.IOException;

public class VmsFactory extends ActionFactory {

/**
Expand All @@ -20,6 +23,10 @@ public VmsFactory(Client client, Proxy proxy) {
super(client, proxy);
}

/**
* @deprecated use {@link #actionSend(String, String)} or {@link #actionSend(String[], String)}
* or {@link #actionSend(String, File)} or {@link #actionSend(String[], File)} instead
*/
public VMSSend actionSend() {
VMSSend action = new VMSSend();
action.client(client);
Expand All @@ -28,18 +35,40 @@ public VMSSend actionSend() {
}

public VMSSend actionSend(String to, String tts) {
String[] tos = new String[]{to};
return actionSend(tos, tts);
VMSSend action = new VMSSend(to, tts);
action.client(client);
action.proxy(proxy);

return action;
}

public VMSSend actionSend(String[] to, String tts) {
VMSSend action = actionSend();
action.setTo(to);
action.setTts(tts);
VMSSend action = new VMSSend(to, tts);
action.client(client);
action.proxy(proxy);

return action;
}

public VMSSend actionSend(String to, File file) throws IOException {
VMSSend action = new VMSSend(to, file);
action.client(client);
action.proxy(proxy);

return action;
}

public VMSSend actionSend(String[] to, File file) throws IOException {
VMSSend action = new VMSSend(to, file);
action.client(client);
action.proxy(proxy);

return action;
}

/**
* @deprecated use {@link #actionGet(String)} instead
*/
public VMSGet actionGet() {
VMSGet action = new VMSGet();
action.client(client);
Expand All @@ -48,11 +77,15 @@ public VMSGet actionGet() {
}

public VMSGet actionGet(String id) {
VMSGet action = actionGet();
action.id(id);
VMSGet action = new VMSGet(id);
action.client(client);
action.proxy(proxy);
return action;
}

/**
* @deprecated use {@link #actionDelete(String)} instead
*/
public VMSDelete actionDelete() {
VMSDelete action = new VMSDelete();
action.client(client);
Expand All @@ -61,8 +94,9 @@ public VMSDelete actionDelete() {
}

public VMSDelete actionDelete(String id) {
VMSDelete action = actionDelete();
action.id(id);
VMSDelete action = new VMSDelete(id);
action.client(client);
action.proxy(proxy);
return action;
}
}
17 changes: 17 additions & 0 deletions src/main/java/pl/smsapi/api/action/vms/VMSDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@

public class VMSDelete extends AbstractAction<CountableResponse> {

/**
* @deprecated use {@link VMSDelete(String)} or {@link VMSDelete(String[])} instead
*/
public VMSDelete() {
setJson(true);
id("");
}

public VMSDelete(String id) {
setJson(true);
params.put("sch_del", id);
}

public VMSDelete(String[] ids) {
setJson(true);
params.put("sch_del", StringUtils.join(ids, '|'));
}

/**
* Set ID of message to delete.
* <p/>
* This id was returned after sending message.
*
* @deprecated set id while constructing action, {@link VMSDelete(String)}
*/
public VMSDelete id(String id) {
params.put("sch_del", id);
Expand All @@ -26,6 +41,8 @@ public VMSDelete id(String id) {
* Set ID of message to delete.
* <p/>
* This id was returned after sending message.
*
* @deprecated set ids while constructing action, {@link VMSDelete(String[])}
*/
public VMSDelete ids(String[] ids) {
params.put("sch_del", StringUtils.join(ids, '|'));
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/pl/smsapi/api/action/vms/VMSGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@

public class VMSGet extends AbstractAction<StatusResponse> {

/**
* @deprecated use {@link VMSGet(String)} or {@link VMSGet(String[])} instead
*/
public VMSGet() {
setJson(true);
id("");
}

public VMSGet(String id) {
setJson(true);
params.put("status", id);
}

public VMSGet(String[] ids) {
setJson(true);
params.put("status", StringUtils.join(ids, '|'));
}

/**
* Set ID of message to check.
* <p/>
* This id was returned after sending message.
*
* @deprecated set id while constructing action, {@link VMSGet(String)}
*/
public VMSGet id(String id) {
params.put("status", id);
Expand All @@ -26,6 +41,8 @@ public VMSGet id(String id) {
* Set IDs of messages to check.
* <p/>
* This id was returned after sending message.
*
* @deprecated set id while constructing action, {@link VMSGet(String[])}
*/
public VMSGet ids(String[] ids) {
params.put("status", StringUtils.join(ids, '|'));
Expand Down
52 changes: 46 additions & 6 deletions src/main/java/pl/smsapi/api/action/vms/VMSSend.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import pl.smsapi.api.action.AbstractSendAction;
import pl.smsapi.api.response.StatusResponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.*;
import java.nio.file.Files;

public class VMSSend extends AbstractSendAction<VMSSend, StatusResponse> {

public static enum Lector {
AGNIESZKA,
public enum Lector {
EWA,
JACEK,
JAN,
Expand All @@ -24,12 +21,49 @@ public String toString() {
}
}

/**
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} or {@link VMSSend(String, File)}
* or {@link VMSSend(String[], File)} instead
*/
public VMSSend() {
setJson(true);
}

public VMSSend(String to, String tts) {
setJson(true);
setTo(to);
params.put("tts", tts);
}

public VMSSend(String[] to, String tts) {
setJson(true);
setTo(to);
params.put("tts", tts);
}

public VMSSend(String to, File file) throws IOException {
setJson(true);
setTo(to);
files.put("file", Files.newInputStream(file.toPath()));
}

public VMSSend(String[] to, File file) throws IOException {
setJson(true);
setTo(to);
files.put("file", Files.newInputStream(file.toPath()));
}

public VMSSend(String[] to, InputStream file) {
setJson(true);
setTo(to);
files.put("file", file);
}

/**
* Set local audio file.
*
* @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead
*
*/
public VMSSend setFile(File file) throws FileNotFoundException {
files.put("file", new FileInputStream(file));
Expand All @@ -38,6 +72,8 @@ public VMSSend setFile(File file) throws FileNotFoundException {

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

/**
* Set local audio stream.
*
* @deprecated use {@link VMSSend(String[], InputStream)} instead
*/
public VMSSend setFile(InputStream inputStream) {
files.put("file", inputStream);
Expand All @@ -54,6 +92,8 @@ public VMSSend setFile(InputStream inputStream) {

/**
* Set text to voice synthesizer.
*
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} instead
*/
public VMSSend setTts(String tts) {
params.put("tts", tts);
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/pl/smsapi/api/action/vms/StatusJsonMother.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pl.smsapi.api.action.vms;

public class StatusJsonMother {

public static String create() {
return
"{" +
" \"count\":1," +
" \"list\":[" +
" {" +
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
" \"points\":0.21," +
" \"number\":\"48123123123\"," +
" \"date_sent\":1717500698," +
" \"submitted_number\":\"123123123\"," +
" \"status\":\"QUEUE\"," +
" \"error\":null," +
" \"idx\":null," +
" \"parts\":1" +
" }" +
" ]" +
"}";
}
}
65 changes: 65 additions & 0 deletions src/test/java/pl/smsapi/api/action/vms/VMSDeleteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package pl.smsapi.api.action.vms;

import org.junit.Test;
import pl.smsapi.exception.SmsapiException;
import pl.smsapi.test.doubles.ClientStub;
import pl.smsapi.test.doubles.ProxyRequestSpy;

import java.util.HashMap;

import static org.junit.Assert.assertEquals;

public class VMSDeleteTest {

@Test
public void executeDeleteVmsRequest() throws SmsapiException {
ProxyRequestSpy requestStub = new ProxyRequestSpy(
"{" +
"\"count\":1," +
"\"list\":[" +
"{" +
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" +
"}" +
"]" +
"}"
);
VMSDelete action = new VMSDelete("0f0f0f0f0f0f0f0f0f0f0f0f");
action.client(new ClientStub());
action.proxy(requestStub);

action.execute();

assertEquals("POST", requestStub.requestMethod);
assertEquals("vms.do", requestStub.requestEndpoint);
HashMap<String, String> expectedRequestPayload = new HashMap<>();
expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f");
expectedRequestPayload.put("format", "json");
assertEquals(expectedRequestPayload, requestStub.requestPayload);
}

@Test
public void executeDeleteMultipleVmsRequest() throws SmsapiException {
ProxyRequestSpy requestStub = new ProxyRequestSpy(
"{" +
"\"count\":1," +
"\"list\":[" +
"{" +
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" +
"}" +
"]" +
"}"
);
VMSDelete action = new VMSDelete(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"});
action.client(new ClientStub());
action.proxy(requestStub);

action.execute();

assertEquals("POST", requestStub.requestMethod);
assertEquals("vms.do", requestStub.requestEndpoint);
HashMap<String, String> expectedRequestPayload = new HashMap<>();
expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f|0f0f0f0f0f0f0f0f0f0f0f01");
expectedRequestPayload.put("format", "json");
assertEquals(expectedRequestPayload, requestStub.requestPayload);
}
}
Loading