Skip to content

Commit fd48147

Browse files
committed
Add client methods for getting outbound SMS prices
1 parent c308619 commit fd48147

File tree

4 files changed

+150
-2
lines changed

4 files changed

+150
-2
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public class MessageBirdClient {
105105
private static final String VOICELEGS_SUFFIX_PATH = "/legs";
106106
static final String FILES_PATH = "/files";
107107
static final String TEMPLATES_PATH = "/templates";
108+
static final String OUTBOUND_SMS_PRICING_PATH = "/pricing/sms/outbound";
109+
static final String OUTBOUND_SMS_PRICING_SMPP_PATH = "/pricing/sms/outbound/smpp/%s";
108110

109111
static final String RECORDING_DOWNLOAD_FORMAT = ".wav";
110112

@@ -2202,4 +2204,37 @@ public void deleteChildAccount(final String id) throws UnauthorizedException, Ge
22022204
System.out.println("url: " + url);
22032205
messageBirdService.deleteByID(url, id);
22042206
}
2207+
2208+
/**
2209+
* Returns outbound pricing for the default SMS configuration for the authenticated account.
2210+
*
2211+
* @return outbound pricing for the default SMS configuration for the authenticated account
2212+
*
2213+
* @throws UnauthorizedException if client is unauthorized
2214+
* @throws GeneralException general exception
2215+
* @throws NotFoundException if pricing information could not be found
2216+
*
2217+
* @see <a href="https://developers.messagebird.com/quickstarts/pricingapi/list-outbound-sms-prices/">Pricing API</a>
2218+
*/
2219+
public OutboundSmsPriceResponse getOutboundSmsPrices() throws GeneralException, UnauthorizedException, NotFoundException {
2220+
return messageBirdService.request(OUTBOUND_SMS_PRICING_PATH, OutboundSmsPriceResponse.class);
2221+
}
2222+
2223+
/**
2224+
* Returns outbound SMS pricing for a specific SMPP username.
2225+
*
2226+
* @param smppUsername the SMPP SystemID provided by MessageBird
2227+
*
2228+
* @return outbound SMS pricing for the given SMPP username
2229+
*
2230+
* @throws UnauthorizedException if client is unauthorized
2231+
* @throws GeneralException general exception
2232+
* @throws NotFoundException if pricing information could not be found for the given SMPP username
2233+
*
2234+
* @see <a href="https://developers.messagebird.com/quickstarts/pricingapi/list-outbound-sms-prices/">Pricing API</a>
2235+
*/
2236+
public OutboundSmsPriceResponse getOutboundSmsPrices(final String smppUsername) throws GeneralException, UnauthorizedException, NotFoundException {
2237+
final String url = String.format(OUTBOUND_SMS_PRICING_SMPP_PATH, smppUsername);
2238+
return messageBirdService.request(url, OutboundSmsPriceResponse.class);
2239+
}
22052240
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.messagebird.objects.voicecalls.*;
1212
import java.util.ArrayList;
1313

14+
import com.messagebird.util.Resources;
1415
import org.jetbrains.annotations.NotNull;
1516
import org.junit.Before;
1617
import org.junit.BeforeClass;
@@ -1515,6 +1516,4 @@ private ConversationSendRequest createDummyConversationRequest() {
15151516
request.setTrackId("mycampaign");
15161517
return request;
15171518
}
1518-
1519-
15201519
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.messagebird;
2+
3+
import com.messagebird.exceptions.GeneralException;
4+
import com.messagebird.exceptions.NotFoundException;
5+
import com.messagebird.exceptions.UnauthorizedException;
6+
import com.messagebird.objects.OutboundSmsPriceResponse;
7+
import com.messagebird.util.Resources;
8+
import org.junit.Test;
9+
10+
import java.math.BigDecimal;
11+
12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertNull;
14+
15+
public class OutboundSmsPricesTest {
16+
17+
@Test
18+
public void testGetOutboundSmsPrices() throws GeneralException, UnauthorizedException, NotFoundException {
19+
String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json");
20+
21+
MessageBirdService messageBirdService = SpyService
22+
.expects("GET", "pricing/sms/outbound")
23+
.withRestAPIBaseURL()
24+
.andReturns(new APIResponse(responseFixture, 200));
25+
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);
26+
27+
assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices());
28+
}
29+
30+
@Test
31+
public void testGetOutboundSmsPricesSmppUsername() throws GeneralException, UnauthorizedException, NotFoundException {
32+
String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json");
33+
34+
MessageBirdService messageBirdService = SpyService
35+
.expects("GET", "pricing/sms/outbound/smpp/test-smpp-user")
36+
.withRestAPIBaseURL()
37+
.andReturns(new APIResponse(responseFixture, 200));
38+
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);
39+
40+
assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices("test-smpp-user"));
41+
}
42+
43+
private static void assertReceivedExpectedResponse(OutboundSmsPriceResponse outboundSmsPriceResponse) {
44+
assertEquals(10, outboundSmsPriceResponse.getGateway());
45+
assertEquals("EUR", outboundSmsPriceResponse.getCurrencyCode());
46+
assertEquals(3, outboundSmsPriceResponse.getTotalCount());
47+
48+
assertEquals(3, outboundSmsPriceResponse.getPrices().size());
49+
50+
assertEquals(new BigDecimal("0.060000"), outboundSmsPriceResponse.getPrices().get(0).getPrice());
51+
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(0).getCurrencyCode());
52+
assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMccmnc());
53+
assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMcc());
54+
assertNull(outboundSmsPriceResponse.getPrices().get(0).getMnc());
55+
assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getCountryName());
56+
assertEquals("XX", outboundSmsPriceResponse.getPrices().get(0).getCountryIsoCode());
57+
assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getOperatorName());
58+
59+
assertEquals(new BigDecimal("0.047000"), outboundSmsPriceResponse.getPrices().get(1).getPrice());
60+
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(1).getCurrencyCode());
61+
assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMccmnc());
62+
assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMcc());
63+
assertNull(outboundSmsPriceResponse.getPrices().get(1).getMnc());
64+
assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(1).getCountryName());
65+
assertEquals("GR", outboundSmsPriceResponse.getPrices().get(1).getCountryIsoCode());
66+
assertNull(outboundSmsPriceResponse.getPrices().get(1).getOperatorName());
67+
68+
assertEquals(new BigDecimal("0.045000"), outboundSmsPriceResponse.getPrices().get(2).getPrice());
69+
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(2).getCurrencyCode());
70+
assertEquals("20205", outboundSmsPriceResponse.getPrices().get(2).getMccmnc());
71+
assertEquals("202", outboundSmsPriceResponse.getPrices().get(2).getMcc());
72+
assertEquals("05", outboundSmsPriceResponse.getPrices().get(2).getMnc());
73+
assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(2).getCountryName());
74+
assertEquals("GR", outboundSmsPriceResponse.getPrices().get(2).getCountryIsoCode());
75+
assertEquals("Vodafone", outboundSmsPriceResponse.getPrices().get(2).getOperatorName());
76+
}
77+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"gateway": 10,
3+
"currencyCode": "EUR",
4+
"totalCount": 3,
5+
"prices": [
6+
{
7+
"price": "0.060000",
8+
"currencyCode": "EUR",
9+
"mccmnc": "0",
10+
"mcc": "0",
11+
"mnc": null,
12+
"countryName": "Default Rate",
13+
"countryIsoCode": "XX",
14+
"operatorName": "Default Rate"
15+
},
16+
{
17+
"price": "0.047000",
18+
"currencyCode": "EUR",
19+
"mccmnc": "202",
20+
"mcc": "202",
21+
"mnc": null,
22+
"countryName": "Greece",
23+
"countryIsoCode": "GR",
24+
"operatorName": null
25+
},
26+
{
27+
"price": "0.045000",
28+
"currencyCode": "EUR",
29+
"mccmnc": "20205",
30+
"mcc": "202",
31+
"mnc": "05",
32+
"countryName": "Greece",
33+
"countryIsoCode": "GR",
34+
"operatorName": "Vodafone"
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)