Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unpause method support #261

Merged
Merged
Changes from all 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
@@ -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";

@@ -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
*
3 changes: 3 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 21 additions & 1 deletion api/src/test/java/com/messagebird/MessageBirdClientTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}