-
Notifications
You must be signed in to change notification settings - Fork 81
Add support for fetching outbound SMS prices #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c308619
Add SMS pricing model objects
jon-signal 20a811d
Add client methods for getting outbound SMS prices
jon-signal b6a4f90
Guard against `null` `smppUsername` arguments
jon-signal 1ccb707
Add an example of fetching outbound SMS prices
jon-signal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
api/src/main/java/com/messagebird/objects/OutboundSmsPrice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.messagebird.objects; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class OutboundSmsPrice { | ||
private BigDecimal price; | ||
private String currencyCode; | ||
private String mccmnc; | ||
private String mcc; | ||
private String mnc; | ||
private String countryName; | ||
private String countryIsoCode; | ||
private String operatorName; | ||
|
||
public BigDecimal getPrice() { | ||
return price; | ||
} | ||
|
||
public String getCurrencyCode() { | ||
return currencyCode; | ||
} | ||
|
||
public String getMccmnc() { | ||
return mccmnc; | ||
} | ||
|
||
public String getMcc() { | ||
return mcc; | ||
} | ||
|
||
public String getMnc() { | ||
return mnc; | ||
} | ||
|
||
public String getCountryName() { | ||
return countryName; | ||
} | ||
|
||
public String getCountryIsoCode() { | ||
return countryIsoCode; | ||
} | ||
|
||
public String getOperatorName() { | ||
return operatorName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OutboundSmsPrice{" + | ||
"price=" + price + | ||
", currencyCode='" + currencyCode + '\'' + | ||
", mccmnc='" + mccmnc + '\'' + | ||
", mcc='" + mcc + '\'' + | ||
", mnc='" + mnc + '\'' + | ||
", countryName='" + countryName + '\'' + | ||
", countryIsoCode='" + countryIsoCode + '\'' + | ||
", operatorName='" + operatorName + '\'' + | ||
'}'; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
api/src/main/java/com/messagebird/objects/OutboundSmsPriceResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.messagebird.objects; | ||
|
||
import java.util.List; | ||
|
||
public class OutboundSmsPriceResponse { | ||
private int gateway; | ||
private String currencyCode; | ||
private int totalCount; | ||
private List<OutboundSmsPrice> prices; | ||
|
||
public int getGateway() { | ||
return gateway; | ||
} | ||
|
||
public String getCurrencyCode() { | ||
return currencyCode; | ||
} | ||
|
||
public int getTotalCount() { | ||
return totalCount; | ||
} | ||
|
||
public List<OutboundSmsPrice> getPrices() { | ||
return prices; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OutboundSmsPriceResponse{" + | ||
"gateway=" + gateway + | ||
", currencyCode='" + currencyCode + '\'' + | ||
", totalCount=" + totalCount + | ||
", prices=" + prices + | ||
'}'; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
api/src/test/java/com/messagebird/OutboundSmsPricesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.messagebird; | ||
|
||
import com.messagebird.exceptions.GeneralException; | ||
import com.messagebird.exceptions.NotFoundException; | ||
import com.messagebird.exceptions.UnauthorizedException; | ||
import com.messagebird.objects.OutboundSmsPriceResponse; | ||
import com.messagebird.util.Resources; | ||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class OutboundSmsPricesTest { | ||
|
||
@Test | ||
public void testGetOutboundSmsPrices() throws GeneralException, UnauthorizedException, NotFoundException { | ||
String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json"); | ||
|
||
MessageBirdService messageBirdService = SpyService | ||
.expects("GET", "pricing/sms/outbound") | ||
.withRestAPIBaseURL() | ||
.andReturns(new APIResponse(responseFixture, 200)); | ||
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService); | ||
|
||
assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices()); | ||
} | ||
|
||
@Test | ||
public void testGetOutboundSmsPricesSmppUsername() throws GeneralException, UnauthorizedException, NotFoundException { | ||
String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json"); | ||
|
||
MessageBirdService messageBirdService = SpyService | ||
.expects("GET", "pricing/sms/outbound/smpp/test-smpp-user") | ||
.withRestAPIBaseURL() | ||
.andReturns(new APIResponse(responseFixture, 200)); | ||
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService); | ||
|
||
assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices("test-smpp-user")); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testGetOutboundSmsPricesSmppUsernameNull() throws GeneralException, UnauthorizedException, NotFoundException { | ||
new MessageBirdClient(mock(MessageBirdService.class)).getOutboundSmsPrices(null); | ||
} | ||
|
||
private static void assertReceivedExpectedResponse(OutboundSmsPriceResponse outboundSmsPriceResponse) { | ||
assertEquals(10, outboundSmsPriceResponse.getGateway()); | ||
assertEquals("EUR", outboundSmsPriceResponse.getCurrencyCode()); | ||
assertEquals(3, outboundSmsPriceResponse.getTotalCount()); | ||
|
||
assertEquals(3, outboundSmsPriceResponse.getPrices().size()); | ||
|
||
assertEquals(new BigDecimal("0.060000"), outboundSmsPriceResponse.getPrices().get(0).getPrice()); | ||
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(0).getCurrencyCode()); | ||
assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMccmnc()); | ||
assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMcc()); | ||
assertNull(outboundSmsPriceResponse.getPrices().get(0).getMnc()); | ||
assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getCountryName()); | ||
assertEquals("XX", outboundSmsPriceResponse.getPrices().get(0).getCountryIsoCode()); | ||
assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getOperatorName()); | ||
|
||
assertEquals(new BigDecimal("0.047000"), outboundSmsPriceResponse.getPrices().get(1).getPrice()); | ||
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(1).getCurrencyCode()); | ||
assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMccmnc()); | ||
assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMcc()); | ||
assertNull(outboundSmsPriceResponse.getPrices().get(1).getMnc()); | ||
assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(1).getCountryName()); | ||
assertEquals("GR", outboundSmsPriceResponse.getPrices().get(1).getCountryIsoCode()); | ||
assertNull(outboundSmsPriceResponse.getPrices().get(1).getOperatorName()); | ||
|
||
assertEquals(new BigDecimal("0.045000"), outboundSmsPriceResponse.getPrices().get(2).getPrice()); | ||
assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(2).getCurrencyCode()); | ||
assertEquals("20205", outboundSmsPriceResponse.getPrices().get(2).getMccmnc()); | ||
assertEquals("202", outboundSmsPriceResponse.getPrices().get(2).getMcc()); | ||
assertEquals("05", outboundSmsPriceResponse.getPrices().get(2).getMnc()); | ||
assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(2).getCountryName()); | ||
assertEquals("GR", outboundSmsPriceResponse.getPrices().get(2).getCountryIsoCode()); | ||
assertEquals("Vodafone", outboundSmsPriceResponse.getPrices().get(2).getOperatorName()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"gateway": 10, | ||
"currencyCode": "EUR", | ||
"totalCount": 3, | ||
"prices": [ | ||
{ | ||
"price": "0.060000", | ||
"currencyCode": "EUR", | ||
"mccmnc": "0", | ||
"mcc": "0", | ||
"mnc": null, | ||
"countryName": "Default Rate", | ||
"countryIsoCode": "XX", | ||
"operatorName": "Default Rate" | ||
}, | ||
{ | ||
"price": "0.047000", | ||
"currencyCode": "EUR", | ||
"mccmnc": "202", | ||
"mcc": "202", | ||
"mnc": null, | ||
"countryName": "Greece", | ||
"countryIsoCode": "GR", | ||
"operatorName": null | ||
}, | ||
{ | ||
"price": "0.045000", | ||
"currencyCode": "EUR", | ||
"mccmnc": "20205", | ||
"mcc": "202", | ||
"mnc": "05", | ||
"countryName": "Greece", | ||
"countryIsoCode": "GR", | ||
"operatorName": "Vodafone" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import com.messagebird.MessageBirdClient; | ||
import com.messagebird.MessageBirdServiceImpl; | ||
import com.messagebird.exceptions.MessageBirdException; | ||
import com.messagebird.objects.OutboundSmsPriceResponse; | ||
|
||
public class ExampleGetOutboundSmsPrices { | ||
|
||
public static void main(String[] args) { | ||
if (args.length != 1 && args.length != 2) { | ||
System.out.println("Please specify your access key and (optionally) SMPP username"); | ||
return; | ||
} | ||
|
||
final MessageBirdClient messageBirdClient = new MessageBirdClient(new MessageBirdServiceImpl(args[0])); | ||
|
||
try { | ||
System.out.println("Get a list of outbound SMS prices"); | ||
|
||
final OutboundSmsPriceResponse outboundSmsPriceResponse; | ||
|
||
if (args.length == 2) { | ||
final String smppUsername = args[1]; | ||
outboundSmsPriceResponse = messageBirdClient.getOutboundSmsPrices(smppUsername); | ||
} else { | ||
outboundSmsPriceResponse = messageBirdClient.getOutboundSmsPrices(); | ||
} | ||
|
||
System.out.println("response: " + outboundSmsPriceResponse); | ||
} catch (MessageBirdException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.