Skip to content

Commit 805639b

Browse files
Merge pull request #10 from thewalrusisben/pr-review
PR Notes
2 parents 6bd36b6 + 3bfab36 commit 805639b

File tree

9 files changed

+106
-30
lines changed

9 files changed

+106
-30
lines changed

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

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,33 @@
33
import com.messagebird.exceptions.GeneralException;
44
import com.messagebird.exceptions.NotFoundException;
55
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;
733
import com.messagebird.objects.conversations.Conversation;
834
import com.messagebird.objects.conversations.ConversationList;
935
import 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
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ private void saveClose(final InputStream is) {
620620
/**
621621
* Encodes a key/value pair with percent encoding.
622622
*
623-
* @param String key
624-
* @param Object value
623+
* @param key the key name to be used
624+
* @param value the value to be assigned to that key
625625
* @return String
626626
*/
627627
private String encodeKeyValuePair(String key, Object value) throws UnsupportedEncodingException {

api/src/main/java/com/messagebird/objects/PurchasedNumberCreatedResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.messagebird.objects;
22

33
import java.util.Date;
4-
import java.util.EnumSet;
54

65
public class PurchasedNumberCreatedResponse extends PurchasedNumber {
76
private Date createdAt;

api/src/main/java/com/messagebird/objects/PurchasedNumbersFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.Serializable;
66
import java.lang.reflect.Field;
77
import java.util.ArrayList;
8+
import java.util.Collections;
89
import java.util.EnumSet;
910
import java.util.HashMap;
1011

@@ -39,9 +40,7 @@ public EnumSet<PhoneNumberFeature> getFeatures() {
3940
}
4041

4142
public void addFeature(PhoneNumberFeature... features) {
42-
for (PhoneNumberFeature feature: features) {
43-
this.features.add(feature);
44-
}
43+
Collections.addAll(this.features, features);
4544
}
4645

4746
public void removeFeature(PhoneNumberFeature... features) {

api/src/test/java/com/messagebird/MessageBirdClientTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ public void testDeleteWebhook() throws NotFoundException, GeneralException, Unau
775775

776776
@Test
777777
public void testListNumbersForPurchase() throws IllegalArgumentException, GeneralException, UnauthorizedException, NotFoundException {
778-
final String url = String.format("%s/v1/available-phone-numbers", NUMBERS_CALLS_BASE_URL);
778+
final String url = String.format("%s/available-phone-numbers", NUMBERS_CALLS_BASE_URL);
779779
final PhoneNumbersResponse mockedResponse = new PhoneNumbersResponse();
780780

781781
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
@@ -793,7 +793,7 @@ public void testListNumbersForPurchase() throws IllegalArgumentException, Genera
793793

794794
@Test
795795
public void testListNumbersForPurchaseWithParams() throws IllegalArgumentException, GeneralException, UnauthorizedException, NotFoundException {
796-
final String url = String.format("%s/v1/available-phone-numbers", NUMBERS_CALLS_BASE_URL);
796+
final String url = String.format("%s/available-phone-numbers", NUMBERS_CALLS_BASE_URL);
797797
final PhoneNumbersResponse mockedResponse = new PhoneNumbersResponse();
798798

799799
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
@@ -817,7 +817,7 @@ public void testListNumbersForPurchaseWithParams() throws IllegalArgumentExcepti
817817

818818
@Test
819819
public void testPurchaseNumber() throws UnauthorizedException, GeneralException {
820-
final String url = String.format("%s/v1/phone-numbers", NUMBERS_CALLS_BASE_URL);
820+
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
821821

822822
PurchasedNumberCreatedResponse purchasedNumberMockData = new PurchasedNumberCreatedResponse();
823823

@@ -839,7 +839,7 @@ public void testPurchaseNumber() throws UnauthorizedException, GeneralException
839839

840840
@Test
841841
public void testListPurchasedNumbers() throws UnauthorizedException, GeneralException, NotFoundException {
842-
final String url = String.format("%s/v1/phone-numbers", NUMBERS_CALLS_BASE_URL);
842+
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
843843

844844
PurchasedNumbersResponse purchasedNumbersMockData = new PurchasedNumbersResponse();
845845

@@ -864,7 +864,7 @@ public void testListPurchasedNumbers() throws UnauthorizedException, GeneralExce
864864

865865
@Test
866866
public void testViewPurchasedNumber() throws UnauthorizedException, GeneralException, NotFoundException {
867-
final String url = String.format("%s/v1/phone-numbers", NUMBERS_CALLS_BASE_URL);
867+
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
868868

869869
PurchasedNumber purchasedNumberMockData = new PurchasedNumber();
870870

@@ -882,15 +882,15 @@ public void testViewPurchasedNumber() throws UnauthorizedException, GeneralExce
882882
@Test
883883
public void updatePurchasedNumber() throws UnauthorizedException, GeneralException, NotFoundException {
884884
final String phoneNumber = "15625267429";
885-
final String url = String.format("%s/v1/phone-numbers/%s", NUMBERS_CALLS_BASE_URL, phoneNumber);
885+
final String url = String.format("%s/phone-numbers/%s", NUMBERS_CALLS_BASE_URL, phoneNumber);
886886

887887
PurchasedNumber updatedNumberMock = new PurchasedNumber();
888888

889889
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
890890
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
891891

892892
final Map<String, List<String>> payload = new HashMap<String, List<String>>();
893-
payload.put("tags", Arrays.asList("tag"));
893+
payload.put("tags", Collections.singletonList("tag"));
894894

895895
when(messageBirdServiceMock.sendPayLoad("PATCH", url, payload, PurchasedNumber.class))
896896
.thenReturn(updatedNumberMock);
@@ -903,7 +903,7 @@ public void updatePurchasedNumber() throws UnauthorizedException, GeneralExcept
903903
@Test
904904
public void deletePurchasedNumber() throws UnauthorizedException, GeneralException, NotFoundException {
905905
final String phoneNumber = "15625267429";
906-
final String url = String.format("%s/v1/phone-numbers", NUMBERS_CALLS_BASE_URL);
906+
final String url = String.format("%s/phone-numbers", NUMBERS_CALLS_BASE_URL);
907907

908908
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
909909
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);

api/src/test/java/com/messagebird/PurchasedNumbersFilterTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.messagebird;
22

33
import com.messagebird.exceptions.GeneralException;
4-
import com.messagebird.exceptions.UnauthorizedException;
54
import com.messagebird.objects.*;
65
import org.junit.Test;
76

8-
import java.lang.reflect.Array;
97
import java.util.*;
108

119
import static org.junit.Assert.*;

examples/src/main/java/ExampleListPurchasedNumbers.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public static void main(String[] args) {
2929

3030
try {
3131
System.out.println(messageBirdClient.listPurchasedNumbers(filter));
32-
return;
3332
} catch (UnauthorizedException | NotFoundException | GeneralException exception) {
3433
if (exception.getErrors() != null) {
3534
System.out.println(exception.getErrors().toString());

examples/src/main/java/ExamplePurchaseNumber.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static void main(String[] args) {
2121
PurchasedNumberCreatedResponse purchasedNumberCreatedResponse = messageBirdClient.purchaseNumber(args[1], args[2], Integer.parseInt(args[3]));
2222

2323
System.out.println(purchasedNumberCreatedResponse);
24-
return;
2524
} catch (UnauthorizedException | GeneralException exception) {
2625
if (exception.getErrors() != null) {
2726
System.out.println(exception.getErrors().toString());

examples/src/main/java/ExampleViewPurchasedNumber.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static void main(String[] args) {
1919

2020
try {
2121
System.out.println(messageBirdClient.viewPurchasedNumber(args[1]));
22-
return;
2322
} catch (UnauthorizedException | NotFoundException | GeneralException exception) {
2423
if (exception.getErrors() != null) {
2524
System.out.println(exception.getErrors().toString());

0 commit comments

Comments
 (0)