33import com .messagebird .exceptions .GeneralException ;
44import com .messagebird .exceptions .NotFoundException ;
55import com .messagebird .exceptions .UnauthorizedException ;
6- import com .messagebird .objects .*;
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 .Group ;
12+ import com .messagebird .objects .GroupList ;
13+ import com .messagebird .objects .GroupRequest ;
14+ import com .messagebird .objects .Hlr ;
15+ import com .messagebird .objects .Lookup ;
16+ import com .messagebird .objects .LookupHlr ;
17+ import com .messagebird .objects .Message ;
18+ import com .messagebird .objects .MessageList ;
19+ import com .messagebird .objects .MessageResponse ;
20+ import com .messagebird .objects .MsgType ;
21+ import com .messagebird .objects .PagedPaging ;
22+ import com .messagebird .objects .PhoneNumbersLookup ;
23+ import com .messagebird .objects .PhoneNumbersResponse ;
24+ import com .messagebird .objects .PurchasedNumber ;
25+ import com .messagebird .objects .PurchasedNumberCreatedResponse ;
26+ import com .messagebird .objects .PurchasedNumbersResponse ;
27+ import com .messagebird .objects .PurchasedNumbersFilter ;
28+ import com .messagebird .objects .Verify ;
29+ import com .messagebird .objects .VerifyRequest ;
30+ import com .messagebird .objects .VoiceMessage ;
31+ import com .messagebird .objects .VoiceMessageList ;
32+ import com .messagebird .objects .VoiceMessageResponse ;
733import com .messagebird .objects .conversations .Conversation ;
834import com .messagebird .objects .conversations .ConversationList ;
935import com .messagebird .objects .conversations .ConversationMessage ;
@@ -68,7 +94,7 @@ public class MessageBirdClient {
6894 private static final String BASE_URL_CONVERSATIONS_WHATSAPP_SANDBOX = "https://whatsapp-sandbox.messagebird.com/v1" ;
6995
7096 static final String VOICE_CALLS_BASE_URL = "https://voice.messagebird.com" ;
71- static final String NUMBERS_CALLS_BASE_URL = "https://numbers.messagebird.com" ;
97+ static final String NUMBERS_CALLS_BASE_URL = "https://numbers.messagebird.com/v1 " ;
7298 private static String [] supportedLanguages = {"de-DE" , "en-AU" , "en-UK" , "en-US" , "es-ES" , "es-LA" , "fr-FR" , "it-IT" , "nl-NL" , "pt-BR" };
7399
74100 private static final String BALANCEPATH = "/balance" ;
@@ -1570,18 +1596,43 @@ private void verifyOffsetAndLimit(Integer offset, Integer limit) {
15701596 }
15711597 }
15721598
1573- public PhoneNumbersResponse listNumbersForPurchase (String countryCode ) throws IllegalArgumentException , GeneralException , UnauthorizedException , NotFoundException {
1574- final String url = String .format ("%s/v1/available-phone-numbers" , NUMBERS_CALLS_BASE_URL );
1599+ /**
1600+ * Lists Numbers that are available to purchase in a particular country code, without any filters.
1601+ *
1602+ * @param countryCode The country code in which the Number should be purchased.
1603+ * @throws GeneralException general exception
1604+ * @throws UnauthorizedException if client is unauthorized
1605+ * @throws NotFoundException if the resource is missing
1606+ */
1607+ public PhoneNumbersResponse listNumbersForPurchase (String countryCode ) throws GeneralException , UnauthorizedException , NotFoundException {
1608+ final String url = String .format ("%s/available-phone-numbers" , NUMBERS_CALLS_BASE_URL );
15751609 return messageBirdService .requestByID (url , countryCode , PhoneNumbersResponse .class );
15761610 }
15771611
1578- public PhoneNumbersResponse listNumbersForPurchase (String countryCode , PhoneNumbersLookup params ) throws IllegalArgumentException , GeneralException , UnauthorizedException , NotFoundException {
1579- final String url = String .format ("%s/v1/available-phone-numbers" , NUMBERS_CALLS_BASE_URL );
1612+ /**
1613+ * Lists Numbers that are available to purchase in a particular country code, according to specified search criteria.
1614+ *
1615+ * @param countryCode The country code in which the Number should be purchased.
1616+ * @param params Parameters to filter the resulting phone numbers returned.
1617+ * @throws GeneralException general exception
1618+ * @throws UnauthorizedException if client is unauthorized
1619+ * @throws NotFoundException if the resource is missing
1620+ */
1621+ public PhoneNumbersResponse listNumbersForPurchase (String countryCode , PhoneNumbersLookup params ) throws GeneralException , UnauthorizedException , NotFoundException {
1622+ final String url = String .format ("%s/available-phone-numbers" , NUMBERS_CALLS_BASE_URL );
15801623 return messageBirdService .requestByID (url , countryCode , params .toHashMap (), PhoneNumbersResponse .class );
15811624 }
15821625
1626+ /**
1627+ * Purchases a phone number. To be used in conjunction with listNumbersForPurchase to identify available numbers.
1628+ *
1629+ * @param number The number to purchase.
1630+ * @param countryCode The country code in which the Number should be purchased.
1631+ * @throws GeneralException general exception
1632+ * @throws UnauthorizedException if client is unauthorized
1633+ */
15831634 public PurchasedNumberCreatedResponse purchaseNumber (String number , String countryCode , int billingIntervalMonths ) throws UnauthorizedException , GeneralException {
1584- final String url = String .format ("%s/v1/ phone-numbers" , NUMBERS_CALLS_BASE_URL );
1635+ final String url = String .format ("%s/phone-numbers" , NUMBERS_CALLS_BASE_URL );
15851636
15861637 final Map <String , Object > payload = new LinkedHashMap <String , Object >();
15871638 payload .put ("number" , number );
@@ -1591,25 +1642,57 @@ public PurchasedNumberCreatedResponse purchaseNumber(String number, String count
15911642 return messageBirdService .sendPayLoad (url , payload , PurchasedNumberCreatedResponse .class );
15921643 }
15931644
1645+ /**
1646+ * Lists Numbers that were purchased using the account credentials that the client was initialized with.
1647+ *
1648+ * @param filter Filters the list of purchased numbers according to search criteria.
1649+ * @throws UnauthorizedException if client is unauthorized
1650+ * @throws GeneralException general exception
1651+ * @throws NotFoundException if the resource is missing
1652+ */
15941653 public PurchasedNumbersResponse listPurchasedNumbers (PurchasedNumbersFilter filter ) throws UnauthorizedException , GeneralException , NotFoundException {
1595- final String url = String .format ("%s/v1/ phone-numbers" , NUMBERS_CALLS_BASE_URL );
1654+ final String url = String .format ("%s/phone-numbers" , NUMBERS_CALLS_BASE_URL );
15961655 return messageBirdService .requestByID (url , null , filter .toHashMap (), PurchasedNumbersResponse .class );
15971656 }
15981657
1658+ /**
1659+ * Returns a Number that has already been purchased on the initialized account.
1660+ *
1661+ * @param number The number whose data should be returned.
1662+ * @throws UnauthorizedException if client is unauthorized
1663+ * @throws GeneralException general exception
1664+ * @throws NotFoundException if the Number is missing
1665+ */
15991666 public PurchasedNumber viewPurchasedNumber (String number ) throws UnauthorizedException , GeneralException , NotFoundException {
1600- final String url = String .format ("%s/v1/ phone-numbers" , NUMBERS_CALLS_BASE_URL );
1667+ final String url = String .format ("%s/phone-numbers" , NUMBERS_CALLS_BASE_URL );
16011668 return messageBirdService .requestByID (url , number , PurchasedNumber .class );
16021669 }
16031670
1671+ /**
1672+ * Updates tags on a particular existing Number. Any number of parameters after the number can be given to apply multiple tags.
1673+ *
1674+ * @param number The number to update.
1675+ * @param tags A tag to apply to the number.
1676+ * @throws UnauthorizedException if client is unauthorized
1677+ * @throws GeneralException general exception
1678+ */
16041679 public PurchasedNumber updateNumber (String number , String ... tags ) throws UnauthorizedException , GeneralException {
1605- final String url = String .format ("%s/v1/ phone-numbers/%s" , NUMBERS_CALLS_BASE_URL , number );
1680+ final String url = String .format ("%s/phone-numbers/%s" , NUMBERS_CALLS_BASE_URL , number );
16061681 final Map <String , List <String >> payload = new HashMap <String , List <String >>();
16071682 payload .put ("tags" , Arrays .asList (tags ));
16081683 return messageBirdService .sendPayLoad ("PATCH" , url , payload , PurchasedNumber .class );
16091684 }
16101685
1686+ /**
1687+ * Cancels a particular number.
1688+ *
1689+ * @param nummber The number to cancel.
1690+ * @throws GeneralException general exception
1691+ * @throws UnauthorizedException if client is unauthorized
1692+ * @throws NotFoundException if the resource is missing
1693+ */
16111694 public void cancelNumber (String number ) throws UnauthorizedException , GeneralException , NotFoundException {
1612- final String url = String .format ("%s/v1/ phone-numbers" , NUMBERS_CALLS_BASE_URL );
1695+ final String url = String .format ("%s/phone-numbers" , NUMBERS_CALLS_BASE_URL );
16131696 messageBirdService .deleteByID (url , number );
16141697 }
16151698}
0 commit comments