Skip to content

Commit

Permalink
Add unpause method support (#261)
Browse files Browse the repository at this point in the history
* Add unpause method support
  • Loading branch information
alyona007 authored Nov 14, 2024
1 parent 0418288 commit 5a34cd2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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 unpauseTemplatesByTemplateName(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 testUnpauseTemplatesByTemplateName_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.unpauseTemplatesByTemplateName("sample_template_name");
verify(messageBirdServiceMock).sendPayLoad("POST", url, "", null);
}

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

0 comments on commit 5a34cd2

Please sign in to comment.