Skip to content

Commit 5a34cd2

Browse files
authored
Add unpause method support (#261)
* Add unpause method support
1 parent 0418288 commit 5a34cd2

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

api/src/main/java/com/messagebird/MessageBirdClient.java

+18
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class MessageBirdClient {
105105
private static final String VOICELEGS_SUFFIX_PATH = "/legs";
106106
static final String FILES_PATH = "/files";
107107
static final String TEMPLATES_PATH = "/templates";
108+
static final String UNPAUSE_TEMAPLATE_PATH = "/unpause";
108109
static final String OUTBOUND_SMS_PRICING_PATH = "/pricing/sms/outbound";
109110
static final String OUTBOUND_SMS_PRICING_SMPP_PATH = "/pricing/sms/outbound/smpp/%s";
110111

@@ -2145,6 +2146,23 @@ public void deleteTemplatesBy(final String templateName)
21452146
messageBirdService.delete(url, null);
21462147
}
21472148

2149+
public void unpauseTemplatesByTemplateName(final String templateName)
2150+
throws UnauthorizedException, GeneralException {
2151+
if (templateName == null) {
2152+
throw new IllegalArgumentException("Template name must be specified.");
2153+
}
2154+
2155+
String url = String.format(
2156+
"%s%s%s%s/%s",
2157+
INTEGRATIONS_BASE_URL_V2,
2158+
INTEGRATIONS_WHATSAPP_PATH,
2159+
TEMPLATES_PATH,
2160+
UNPAUSE_TEMAPLATE_PATH,
2161+
templateName
2162+
);
2163+
messageBirdService.sendPayLoad("POST", url, "", null);
2164+
}
2165+
21482166
/**
21492167
* Function to create a child account
21502168
*

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ <P> APIResponse doRequest(final String method, final String url, final Map<Strin
382382
inputStream = connection.getInputStream();
383383
} else {
384384
inputStream = connection.getErrorStream();
385+
if (inputStream == null) {
386+
throw new IOException("Server returned HTTP error code " + status + " with no body.");
387+
}
385388
}
386389

387390
return new APIResponse(readToEnd(inputStream), status);

api/src/test/java/com/messagebird/MessageBirdClientTest.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -1592,5 +1592,25 @@ private ConversationSendRequest createDummyConversationRequest() {
15921592
return request;
15931593
}
15941594

1595+
@Test
1596+
public void testUnpauseTemplatesByTemplateName_Success() throws UnauthorizedException, GeneralException {
1597+
final Template template = TestUtil.createWhatsAppTemplate("sample_template_name", "ko");
1598+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
1599+
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);
1600+
String url = String.format(
1601+
"%s%s%s%s/%s",
1602+
INTEGRATIONS_BASE_URL_V2,
1603+
INTEGRATIONS_WHATSAPP_PATH,
1604+
TEMPLATES_PATH,
1605+
UNPAUSE_TEMAPLATE_PATH,
1606+
"sample_template_name"
1607+
);
1608+
messageBirdClientInjectMock.unpauseTemplatesByTemplateName("sample_template_name");
1609+
verify(messageBirdServiceMock).sendPayLoad("POST", url, "", null);
1610+
}
15951611

1596-
}
1612+
@Test(expected = GeneralException.class)
1613+
public void testUnpauseTemplatesByTemplateName_NotFound() throws UnauthorizedException, GeneralException {
1614+
messageBirdClient.unpauseTemplatesByTemplateName("foo");
1615+
}
1616+
}

0 commit comments

Comments
 (0)