3
3
import com .messagebird .exceptions .GeneralException ;
4
4
import com .messagebird .exceptions .NotFoundException ;
5
5
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 .*;
35
7
import com .messagebird .objects .conversations .Conversation ;
36
8
import com .messagebird .objects .conversations .ConversationList ;
37
9
import com .messagebird .objects .conversations .ConversationMessage ;
@@ -107,6 +79,7 @@ public class MessageBirdClient {
107
79
static final String INTEGRATIONS_BASE_URL_V2 = "https://integrations.messagebird.com/v2" ;
108
80
static final String INTEGRATIONS_BASE_URL_V3 = "https://integrations.messagebird.com/v3" ;
109
81
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" ;
110
83
111
84
private static final String BALANCEPATH = "/balance" ;
112
85
private static final String CONTACTPATH = "/contacts" ;
@@ -502,7 +475,7 @@ Verify getVerifyObject(String id) throws NotFoundException, GeneralException, Un
502
475
}
503
476
504
477
/**
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
506
479
* @return Verify object
507
480
* @throws NotFoundException if id is not found
508
481
* @throws UnauthorizedException if client is unauthorized
@@ -704,8 +677,8 @@ public VoiceCallFlowResponse sendVoiceCallFlow(final VoiceCallFlowRequest voiceC
704
677
* @param id String
705
678
* @param voiceCallFlowRequest VoiceCallFlowRequest
706
679
* @return VoiceCallFlowResponse
707
- * @throws UnauthorizedException
708
- * @throws GeneralException
680
+ * @throws UnauthorizedException if client is unauthorized
681
+ * @throws GeneralException general exception
709
682
*/
710
683
public VoiceCallFlowResponse updateVoiceCallFlow (String id , VoiceCallFlowRequest voiceCallFlowRequest )
711
684
throws UnauthorizedException , GeneralException {
@@ -1919,7 +1892,7 @@ public TemplateList listWhatsAppTemplates() throws UnauthorizedException, Genera
1919
1892
* Retrieves the template of an existing template name.
1920
1893
*
1921
1894
* @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
1923
1896
* @throws UnauthorizedException if client is unauthorized
1924
1897
* @throws GeneralException general exception
1925
1898
* @throws NotFoundException if template name is not found
@@ -1946,7 +1919,7 @@ public List<TemplateResponse> getWhatsAppTemplatesBy(final String templateName)
1946
1919
* @param templateName A name as returned by getWhatsAppTemplateBy in the name variable
1947
1920
* @param language A language code as returned by getWhatsAppTemplateBy in the language variable
1948
1921
*
1949
- * @return {@code WhatsAppTemplateResponse } template list
1922
+ * @return {@code TemplateResponse } template list
1950
1923
* @throws UnauthorizedException if client is unauthorized
1951
1924
* @throws GeneralException general exception
1952
1925
* @throws NotFoundException if template name and language are not found
@@ -1968,7 +1941,6 @@ public TemplateResponse fetchWhatsAppTemplateBy(final String templateName, final
1968
1941
return messageBirdService .request (url , TemplateResponse .class );
1969
1942
}
1970
1943
1971
-
1972
1944
/**
1973
1945
* Delete templates of an existing template name.
1974
1946
*
@@ -2018,4 +1990,89 @@ public void deleteTemplatesBy(final String templateName, final String language)
2018
1990
);
2019
1991
messageBirdService .delete (url , null );
2020
1992
}
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
+ }
0 commit comments