Rename SenderIdSelector to SenderIdSupplier per code review discussion
This commit is contained in:
parent
a7968ccc3c
commit
b9b6e1818f
|
@ -12,12 +12,12 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class SenderIdSelector {
|
class SenderIdSupplier {
|
||||||
private final String defaultSenderId;
|
private final String defaultSenderId;
|
||||||
private final Map<String, String> countrySpecificSenderIds;
|
private final Map<String, String> countrySpecificSenderIds;
|
||||||
private final Set<String> countryCodesWithoutSenderId;
|
private final Set<String> countryCodesWithoutSenderId;
|
||||||
|
|
||||||
SenderIdSelector(String defaultSenderId, List<TwilioCountrySenderIdConfiguration> countrySpecificSenderIds, Set<String> countryCodesWithoutSenderId) {
|
SenderIdSupplier(String defaultSenderId, List<TwilioCountrySenderIdConfiguration> countrySpecificSenderIds, Set<String> countryCodesWithoutSenderId) {
|
||||||
this.defaultSenderId = defaultSenderId;
|
this.defaultSenderId = defaultSenderId;
|
||||||
this.countrySpecificSenderIds = countrySpecificSenderIds.stream().collect(Collectors.toMap(
|
this.countrySpecificSenderIds = countrySpecificSenderIds.stream().collect(Collectors.toMap(
|
||||||
TwilioCountrySenderIdConfiguration::getCountryCode,
|
TwilioCountrySenderIdConfiguration::getCountryCode,
|
||||||
|
@ -25,13 +25,13 @@ class SenderIdSelector {
|
||||||
this.countryCodesWithoutSenderId = countryCodesWithoutSenderId;
|
this.countryCodesWithoutSenderId = countryCodesWithoutSenderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
SenderIdSelector(TwilioSenderIdConfiguration configuration) {
|
SenderIdSupplier(TwilioSenderIdConfiguration configuration) {
|
||||||
this(configuration.getDefaultSenderId(),
|
this(configuration.getDefaultSenderId(),
|
||||||
configuration.getCountrySpecificSenderIds(),
|
configuration.getCountrySpecificSenderIds(),
|
||||||
configuration.getCountryCodesWithoutSenderId());
|
configuration.getCountryCodesWithoutSenderId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> getSenderId(@NotNull String destination) {
|
Optional<String> get(@NotNull String destination) {
|
||||||
final String countryCode = Util.getCountryCode(destination);
|
final String countryCode = Util.getCountryCode(destination);
|
||||||
if (countryCodesWithoutSenderId.contains(countryCode)) {
|
if (countryCodesWithoutSenderId.contains(countryCode)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
|
@ -65,7 +65,7 @@ public class TwilioSmsSender {
|
||||||
private final ArrayList<String> numbers;
|
private final ArrayList<String> numbers;
|
||||||
private final String messagingServicesId;
|
private final String messagingServicesId;
|
||||||
private final String localDomain;
|
private final String localDomain;
|
||||||
private final SenderIdSelector senderIdSelector;
|
private final SenderIdSupplier senderIdSupplier;
|
||||||
private final Random random;
|
private final Random random;
|
||||||
|
|
||||||
private final FaultTolerantHttpClient httpClient;
|
private final FaultTolerantHttpClient httpClient;
|
||||||
|
@ -81,7 +81,7 @@ public class TwilioSmsSender {
|
||||||
this.numbers = new ArrayList<>(twilioConfiguration.getNumbers());
|
this.numbers = new ArrayList<>(twilioConfiguration.getNumbers());
|
||||||
this.localDomain = twilioConfiguration.getLocalDomain();
|
this.localDomain = twilioConfiguration.getLocalDomain();
|
||||||
this.messagingServicesId = twilioConfiguration.getMessagingServicesId();
|
this.messagingServicesId = twilioConfiguration.getMessagingServicesId();
|
||||||
this.senderIdSelector = new SenderIdSelector(twilioConfiguration.getSenderId());
|
this.senderIdSupplier = new SenderIdSupplier(twilioConfiguration.getSenderId());
|
||||||
this.random = new Random(System.currentTimeMillis());
|
this.random = new Random(System.currentTimeMillis());
|
||||||
this.smsUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Messages.json");
|
this.smsUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Messages.json");
|
||||||
this.voxUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Calls.json" );
|
this.voxUri = URI.create(baseUri + "/2010-04-01/Accounts/" + accountId + "/Calls.json" );
|
||||||
|
@ -174,7 +174,7 @@ public class TwilioSmsSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOriginationRequestParameter(String destination, Map<String, String> requestParameters) {
|
private void setOriginationRequestParameter(String destination, Map<String, String> requestParameters) {
|
||||||
final Optional<String> senderId = senderIdSelector.getSenderId(destination);
|
final Optional<String> senderId = senderIdSupplier.get(destination);
|
||||||
if (senderId.isPresent()) {
|
if (senderId.isPresent()) {
|
||||||
requestParameters.put("From", senderId.get());
|
requestParameters.put("From", senderId.get());
|
||||||
} else if (Util.isEmpty(messagingServicesId)) {
|
} else if (Util.isEmpty(messagingServicesId)) {
|
||||||
|
|
Loading…
Reference in New Issue