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 .*;
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 ;
7
33
import com .messagebird .objects .conversations .Conversation ;
8
34
import com .messagebird .objects .conversations .ConversationList ;
9
35
import com .messagebird .objects .conversations .ConversationMessage ;
@@ -68,7 +94,7 @@ public class MessageBirdClient {
68
94
private static final String BASE_URL_CONVERSATIONS_WHATSAPP_SANDBOX = "https://whatsapp-sandbox.messagebird.com/v1" ;
69
95
70
96
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 " ;
72
98
private static String [] supportedLanguages = {"de-DE" , "en-AU" , "en-UK" , "en-US" , "es-ES" , "es-LA" , "fr-FR" , "it-IT" , "nl-NL" , "pt-BR" };
73
99
74
100
private static final String BALANCEPATH = "/balance" ;
@@ -1570,18 +1596,43 @@ private void verifyOffsetAndLimit(Integer offset, Integer limit) {
1570
1596
}
1571
1597
}
1572
1598
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 );
1575
1609
return messageBirdService .requestByID (url , countryCode , PhoneNumbersResponse .class );
1576
1610
}
1577
1611
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 );
1580
1623
return messageBirdService .requestByID (url , countryCode , params .toHashMap (), PhoneNumbersResponse .class );
1581
1624
}
1582
1625
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
+ */
1583
1634
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 );
1585
1636
1586
1637
final Map <String , Object > payload = new LinkedHashMap <String , Object >();
1587
1638
payload .put ("number" , number );
@@ -1591,25 +1642,57 @@ public PurchasedNumberCreatedResponse purchaseNumber(String number, String count
1591
1642
return messageBirdService .sendPayLoad (url , payload , PurchasedNumberCreatedResponse .class );
1592
1643
}
1593
1644
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
+ */
1594
1653
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 );
1596
1655
return messageBirdService .requestByID (url , null , filter .toHashMap (), PurchasedNumbersResponse .class );
1597
1656
}
1598
1657
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
+ */
1599
1666
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 );
1601
1668
return messageBirdService .requestByID (url , number , PurchasedNumber .class );
1602
1669
}
1603
1670
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
+ */
1604
1679
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 );
1606
1681
final Map <String , List <String >> payload = new HashMap <String , List <String >>();
1607
1682
payload .put ("tags" , Arrays .asList (tags ));
1608
1683
return messageBirdService .sendPayLoad ("PATCH" , url , payload , PurchasedNumber .class );
1609
1684
}
1610
1685
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
+ */
1611
1694
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 );
1613
1696
messageBirdService .deleteByID (url , number );
1614
1697
}
1615
1698
}
0 commit comments