Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public class MessageBirdClient {
private static final String VOICELEGS_SUFFIX_PATH = "/legs";
static final String FILES_PATH = "/files";
static final String TEMPLATES_PATH = "/templates";
static final String UNPAUSE_TEMAPLATE_PATH = "/unpause";
static final String OUTBOUND_SMS_PRICING_PATH = "/pricing/sms/outbound";
static final String OUTBOUND_SMS_PRICING_SMPP_PATH = "/pricing/sms/outbound/smpp/%s";

Expand Down Expand Up @@ -2145,6 +2146,23 @@ public void deleteTemplatesBy(final String templateName)
messageBirdService.delete(url, null);
}

public void unpauseTemplatesBy(final String templateName)
throws UnauthorizedException, GeneralException {
if (templateName == null) {
throw new IllegalArgumentException("Template name must be specified.");
}

String url = String.format(
"%s%s%s%s/%s",
INTEGRATIONS_BASE_URL_V2,
INTEGRATIONS_WHATSAPP_PATH,
TEMPLATES_PATH,
UNPAUSE_TEMAPLATE_PATH,
templateName
);
messageBirdService.sendPayLoad("POST", url, "", null);
}

/**
* Function to create a child account
*
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ <P> APIResponse doRequest(final String method, final String url, final Map<Strin
inputStream = connection.getInputStream();
} else {
inputStream = connection.getErrorStream();
if (inputStream == null) {
throw new IOException("Server returned HTTP error code " + status + " with no body.");
}
}

return new APIResponse(readToEnd(inputStream), status);
Expand Down
22 changes: 21 additions & 1 deletion api/src/test/java/com/messagebird/MessageBirdClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1592,5 +1592,25 @@ private ConversationSendRequest createDummyConversationRequest() {
return request;
}

@Test
public void testUnpauseTemplatesBy_Success() throws UnauthorizedException, GeneralException {
final Template template = TestUtil.createWhatsAppTemplate("sample_template_name", "ko");
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
String url = String.format(
"%s%s%s%s/%s",
INTEGRATIONS_BASE_URL_V2,
INTEGRATIONS_WHATSAPP_PATH,
TEMPLATES_PATH,
UNPAUSE_TEMAPLATE_PATH,
"sample_template_name"
);
messageBirdClientInjectMock.unpauseTemplatesBy("sample_template_name");
verify(messageBirdServiceMock).sendPayLoad("POST", url, "", null);
}

}
@Test(expected = GeneralException.class)
public void testUnpauseTemplatesBy_NotFound() throws UnauthorizedException, GeneralException {
messageBirdClient.unpauseTemplatesBy("foo");
}
}