Skip to content

Commit 88153cc

Browse files
authored
Merge pull request #164 from messagebird/Issue_162_partnerAccount
Issue 162 Partners Account API integration #162
2 parents c7b43e2 + 89715d8 commit 88153cc

13 files changed

+515
-52
lines changed

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

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,7 @@
33
import com.messagebird.exceptions.GeneralException;
44
import com.messagebird.exceptions.NotFoundException;
55
import com.messagebird.exceptions.UnauthorizedException;
6-
import com.messagebird.objects.Balance;
7-
import com.messagebird.objects.Contact;
8-
import com.messagebird.objects.ContactList;
9-
import com.messagebird.objects.ContactRequest;
10-
import com.messagebird.objects.ErrorReport;
11-
import com.messagebird.objects.FileUploadResponse;
12-
import com.messagebird.objects.Group;
13-
import com.messagebird.objects.GroupList;
14-
import com.messagebird.objects.GroupRequest;
15-
import com.messagebird.objects.Hlr;
16-
import com.messagebird.objects.Lookup;
17-
import com.messagebird.objects.LookupHlr;
18-
import com.messagebird.objects.Message;
19-
import com.messagebird.objects.MessageList;
20-
import com.messagebird.objects.MessageResponse;
21-
import com.messagebird.objects.MsgType;
22-
import com.messagebird.objects.PagedPaging;
23-
import com.messagebird.objects.PhoneNumbersLookup;
24-
import com.messagebird.objects.PhoneNumbersResponse;
25-
import com.messagebird.objects.PurchasedNumber;
26-
import com.messagebird.objects.PurchasedNumberCreatedResponse;
27-
import com.messagebird.objects.PurchasedNumbersFilter;
28-
import com.messagebird.objects.PurchasedNumbersResponse;
29-
import com.messagebird.objects.Verify;
30-
import com.messagebird.objects.VerifyMessage;
31-
import com.messagebird.objects.VerifyRequest;
32-
import com.messagebird.objects.VoiceMessage;
33-
import com.messagebird.objects.VoiceMessageList;
34-
import com.messagebird.objects.VoiceMessageResponse;
6+
import com.messagebird.objects.*;
357
import com.messagebird.objects.conversations.Conversation;
368
import com.messagebird.objects.conversations.ConversationList;
379
import com.messagebird.objects.conversations.ConversationMessage;
@@ -107,6 +79,7 @@ public class MessageBirdClient {
10779
static final String INTEGRATIONS_BASE_URL_V2 = "https://integrations.messagebird.com/v2";
10880
static final String INTEGRATIONS_BASE_URL_V3 = "https://integrations.messagebird.com/v3";
10981
private static String[] supportedLanguages = {"de-DE", "en-AU", "en-UK", "en-US", "es-ES", "es-LA", "fr-FR", "it-IT", "nl-NL", "pt-BR"};
82+
static final String PARTNER_ACCOUNTS_BASE_URL = "https://partner-accounts.messagebird.com";
11083

11184
private static final String BALANCEPATH = "/balance";
11285
private static final String CONTACTPATH = "/contacts";
@@ -502,7 +475,7 @@ Verify getVerifyObject(String id) throws NotFoundException, GeneralException, Un
502475
}
503476

504477
/**
505-
* @param id id is for the email message part of a verify object
478+
* @param messageId is for the email message part of a verify object
506479
* @return Verify object
507480
* @throws NotFoundException if id is not found
508481
* @throws UnauthorizedException if client is unauthorized
@@ -704,8 +677,8 @@ public VoiceCallFlowResponse sendVoiceCallFlow(final VoiceCallFlowRequest voiceC
704677
* @param id String
705678
* @param voiceCallFlowRequest VoiceCallFlowRequest
706679
* @return VoiceCallFlowResponse
707-
* @throws UnauthorizedException
708-
* @throws GeneralException
680+
* @throws UnauthorizedException if client is unauthorized
681+
* @throws GeneralException general exception
709682
*/
710683
public VoiceCallFlowResponse updateVoiceCallFlow(String id, VoiceCallFlowRequest voiceCallFlowRequest)
711684
throws UnauthorizedException, GeneralException {
@@ -1919,7 +1892,7 @@ public TemplateList listWhatsAppTemplates() throws UnauthorizedException, Genera
19191892
* Retrieves the template of an existing template name.
19201893
*
19211894
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
1922-
* @return {@code List<WhatsAppTemplateResponse>} template list
1895+
* @return {@code List<TemplateResponse>} template list
19231896
* @throws UnauthorizedException if client is unauthorized
19241897
* @throws GeneralException general exception
19251898
* @throws NotFoundException if template name is not found
@@ -1946,7 +1919,7 @@ public List<TemplateResponse> getWhatsAppTemplatesBy(final String templateName)
19461919
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
19471920
* @param language A language code as returned by getWhatsAppTemplateBy in the language variable
19481921
*
1949-
* @return {@code WhatsAppTemplateResponse} template list
1922+
* @return {@code TemplateResponse} template list
19501923
* @throws UnauthorizedException if client is unauthorized
19511924
* @throws GeneralException general exception
19521925
* @throws NotFoundException if template name and language are not found
@@ -1968,7 +1941,6 @@ public TemplateResponse fetchWhatsAppTemplateBy(final String templateName, final
19681941
return messageBirdService.request(url, TemplateResponse.class);
19691942
}
19701943

1971-
19721944
/**
19731945
* Delete templates of an existing template name.
19741946
*
@@ -2018,4 +1990,89 @@ public void deleteTemplatesBy(final String templateName, final String language)
20181990
);
20191991
messageBirdService.delete(url, null);
20201992
}
2021-
}
1993+
1994+
/**
1995+
* Function to create a child account
1996+
*
1997+
* @param childAccountRequest of child account to create
1998+
* @return ChildAccountResponse created
1999+
* @throws UnauthorizedException if client is unauthorized
2000+
* @throws GeneralException general exception
2001+
*/
2002+
public ChildAccountCreateResponse createChildAccount(final ChildAccountRequest childAccountRequest) throws UnauthorizedException, GeneralException {
2003+
if (childAccountRequest.getName() == null || childAccountRequest.getName().isEmpty()) {
2004+
throw new IllegalArgumentException("Name must be specified.");
2005+
}
2006+
2007+
String url = String.format("%s%s", PARTNER_ACCOUNTS_BASE_URL, "/child-accounts");
2008+
return messageBirdService.sendPayLoad(url, childAccountRequest, ChildAccountCreateResponse.class);
2009+
}
2010+
2011+
/**
2012+
* Function to update a child account
2013+
*
2014+
* @param id of child account to update
2015+
* @return ChildAccountResponse created
2016+
* @throws UnauthorizedException if client is unauthorized
2017+
* @throws GeneralException general exception
2018+
*/
2019+
public ChildAccountResponse updateChildAccount(final String name, final String id) throws UnauthorizedException, GeneralException {
2020+
if (name == null) {
2021+
throw new IllegalArgumentException("Name must be specified.");
2022+
}
2023+
2024+
if (id == null) {
2025+
throw new IllegalArgumentException("Child account id must be specified.");
2026+
}
2027+
final ChildAccountRequest childAccountRequest = new ChildAccountRequest();
2028+
childAccountRequest.setName(name);
2029+
final String url = String.format("%s/child-accounts/%s", PARTNER_ACCOUNTS_BASE_URL, id);
2030+
return messageBirdService.sendPayLoad("PATCH", url, childAccountRequest, ChildAccountResponse.class);
2031+
}
2032+
2033+
/**
2034+
* Function to get a child account
2035+
*
2036+
* @param id of child account to update
2037+
* @return ChildAccountResponse created
2038+
* @throws UnauthorizedException if client is unauthorized
2039+
* @throws GeneralException general exception
2040+
* @throws NotFoundException if id is not found
2041+
*/
2042+
public ChildAccountDetailedResponse getChildAccountById(final String id) throws UnauthorizedException, GeneralException, NotFoundException {
2043+
if (id == null) {
2044+
throw new IllegalArgumentException("Child account id must be specified.");
2045+
}
2046+
return messageBirdService.requestByID(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", id, ChildAccountDetailedResponse.class);
2047+
}
2048+
2049+
/**
2050+
* Function to get a child account
2051+
*
2052+
* @return ChildAccountResponse created
2053+
* @throws UnauthorizedException if client is unauthorized
2054+
* @throws GeneralException general exception
2055+
*/
2056+
public List<ChildAccountResponse> getChildAccounts(final Integer offset, final Integer limit) throws UnauthorizedException, GeneralException {
2057+
verifyOffsetAndLimit(offset, limit);
2058+
return messageBirdService.requestList(PARTNER_ACCOUNTS_BASE_URL + "/child-accounts", offset, limit, List.class);
2059+
}
2060+
2061+
/**
2062+
* Function to delete a child account
2063+
*
2064+
* @param id of child account to delete
2065+
* @throws UnauthorizedException if client is unauthorized
2066+
* @throws GeneralException general exception
2067+
* @throws NotFoundException if id is not found
2068+
*/
2069+
public void deleteChildAccount(final String id) throws UnauthorizedException, GeneralException, NotFoundException {
2070+
if (id == null) {
2071+
throw new IllegalArgumentException("Child account id must be specified.");
2072+
}
2073+
2074+
String url = String.format("%s/child-accounts", PARTNER_ACCOUNTS_BASE_URL);
2075+
System.out.println("url: " + url);
2076+
messageBirdService.deleteByID(url, id);
2077+
}
2078+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.messagebird.objects;
2+
3+
public class AccessKey {
4+
private String id;
5+
private String key;
6+
private String mod;
7+
8+
public String getId() {
9+
return id;
10+
}
11+
12+
public void setId(String id) {
13+
this.id = id;
14+
}
15+
16+
public String getKey() {
17+
return key;
18+
}
19+
20+
public void setKey(String key) {
21+
this.key = key;
22+
}
23+
24+
public String getMod() {
25+
return mod;
26+
}
27+
28+
public void setMod(String mod) {
29+
this.mod = mod;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "AccessKey{" +
35+
"id='" + id + '\'' +
36+
", key='" + key + '\'' +
37+
", mod='" + mod + '\'' +
38+
'}';
39+
}
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.messagebird.objects;
2+
3+
import java.util.List;
4+
5+
public class ChildAccountCreateResponse extends ChildAccountResponse{
6+
private List<AccessKey> accessKeys;
7+
private String signingKey;
8+
private String invoiceAggregation;
9+
10+
public List<AccessKey> getAccessKeys() {
11+
return accessKeys;
12+
}
13+
14+
public void setAccessKeys(List<AccessKey> accessKeys) {
15+
this.accessKeys = accessKeys;
16+
}
17+
18+
public String getSigningKey() {
19+
return signingKey;
20+
}
21+
22+
public void setSigningKey(String signingKey) {
23+
this.signingKey = signingKey;
24+
}
25+
26+
public String getInvoiceAggregation() {
27+
return invoiceAggregation;
28+
}
29+
30+
public void setInvoiceAggregation(String invoiceAggregation) {
31+
this.invoiceAggregation = invoiceAggregation;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "ChildAccountCreateResponse{" +
37+
"id='" + getId() + '\'' +
38+
", name='" + getName() + '\'' +
39+
", accessKeys=" + accessKeys + '\'' +
40+
", signingKey='" + signingKey + '\'' +
41+
", invoiceAggregation='" + invoiceAggregation + '\'' +
42+
'}';
43+
}
44+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.messagebird.objects;
2+
3+
public class ChildAccountDetailedResponse extends ChildAccountResponse{
4+
private String invoiceAggregation;
5+
6+
public String getInvoiceAggregation() {
7+
return invoiceAggregation;
8+
}
9+
10+
public void setInvoiceAggregation(String invoiceAggregation) {
11+
this.invoiceAggregation = invoiceAggregation;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return "ChildAccountDetailedResponse{" +
17+
"id='" + getId() + '\'' +
18+
", name='" + getName() + '\'' +
19+
", invoiceAggregation='" + invoiceAggregation + '\'' +
20+
'}';
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.messagebird.objects;
2+
3+
public class ChildAccountRequest {
4+
private String name;
5+
6+
public String getName() {
7+
return name;
8+
}
9+
10+
public void setName(String name) {
11+
this.name = name;
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.messagebird.objects;
2+
3+
import java.io.Serializable;
4+
5+
public class ChildAccountResponse implements Serializable {
6+
private static final long serialVersionUID = -8605510461438669942L;
7+
8+
private String id;
9+
private String name;
10+
11+
public String getId() {
12+
return id;
13+
}
14+
15+
public void setId(String id) {
16+
this.id = id;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return "ChildAccountResponse{" +
30+
"id='" + id + '\'' +
31+
", name='" + name + '\'' +
32+
'}';
33+
}
34+
}

0 commit comments

Comments
 (0)