-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature (Numbers): rent, rentAny and active number update snippets
- Loading branch information
Showing
6 changed files
with
131 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/sh | ||
|
||
(cd snippets && mvn clean spotless:apply compile) | ||
(cd snippets && mvn clean spotless:apply) | ||
(cd snippets && ./compile.sh) | ||
|
This file contains 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,14 @@ | ||
#!/bin/sh | ||
|
||
SNIPPETS=`find . -type f -regex '.*Snippet\.java$'` | ||
|
||
echo "Compiling snippets:" | ||
for snippet in $SNIPPETS | ||
do | ||
echo " - Snippet: $snippet" | ||
mvn compile -Dsnippet="$(dirname $snippet)" | ||
if [ $? -ne 0 ] | ||
then | ||
exit $? | ||
fi | ||
done |
This file contains 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,35 @@ | ||
package numbers; | ||
|
||
import com.sinch.sdk.domains.numbers.ActiveNumberService; | ||
import com.sinch.sdk.domains.numbers.NumbersService; | ||
import com.sinch.sdk.domains.numbers.models.ActiveNumber; | ||
import com.sinch.sdk.domains.numbers.models.requests.ActiveNumberUpdateRequestParameters; | ||
import com.sinch.sdk.domains.numbers.models.requests.ActiveNumberUpdateVoiceConfigurationRequestParameters; | ||
import java.util.logging.Logger; | ||
|
||
public class Snippet { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); | ||
|
||
static void execute(NumbersService numbersService) { | ||
|
||
ActiveNumberService activeNumbersService = numbersService.active(); | ||
|
||
String phoneNumber = "YOUR_phone_number_to_be_updated"; | ||
String appId = "YOUR_app_id"; | ||
String displayName = "Updated from Sinch Java SDK"; | ||
|
||
ActiveNumberUpdateVoiceConfigurationRequestParameters voiceConfiguration = | ||
ActiveNumberUpdateVoiceConfigurationRequestParameters.builder().setAppId(appId).build(); | ||
|
||
ActiveNumberUpdateRequestParameters updateRequest = | ||
ActiveNumberUpdateRequestParameters.builder() | ||
.setDisplayName(displayName) | ||
.setVoiceConfiguration(voiceConfiguration) | ||
.build(); | ||
|
||
ActiveNumber response = activeNumbersService.update(phoneNumber, updateRequest); | ||
|
||
LOGGER.info(String.format("Updated number: %s", response)); | ||
} | ||
} |
This file contains 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,35 @@ | ||
package numbers; | ||
|
||
import com.sinch.sdk.domains.numbers.AvailableNumberService; | ||
import com.sinch.sdk.domains.numbers.NumbersService; | ||
import com.sinch.sdk.domains.numbers.models.ActiveNumber; | ||
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentRequestParameters; | ||
import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters; | ||
import java.util.logging.Logger; | ||
|
||
public class Snippet { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); | ||
|
||
static void execute(NumbersService numbersService) { | ||
|
||
AvailableNumberService availableNumbersService = numbersService.available(); | ||
|
||
// Available numbers list can be retrieved by using list() function from available service, see: | ||
// https://developers.sinch.com/quickstart-getting-started-poc/docs/numbers/getting-started/java-sdk/searchavailable | ||
String phoneNumber = "available_phone_number_to_be_rented"; | ||
String servicePlanId = "YOUR_service_plan_id"; | ||
|
||
RentSMSConfigurationRequestParameters smsConfiguration = | ||
RentSMSConfigurationRequestParameters.builder().setServicePlanId(servicePlanId).build(); | ||
|
||
AvailableNumberRentRequestParameters rentRequest = | ||
AvailableNumberRentRequestParameters.builder() | ||
.setSmsConfiguration(smsConfiguration) | ||
.build(); | ||
|
||
ActiveNumber response = availableNumbersService.rent(phoneNumber, rentRequest); | ||
|
||
LOGGER.info(String.format("Rented number: %s", response)); | ||
} | ||
} |
This file contains 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,41 @@ | ||
package numbers; | ||
|
||
import com.sinch.sdk.domains.numbers.AvailableNumberService; | ||
import com.sinch.sdk.domains.numbers.NumbersService; | ||
import com.sinch.sdk.domains.numbers.models.ActiveNumber; | ||
import com.sinch.sdk.domains.numbers.models.Capability; | ||
import com.sinch.sdk.domains.numbers.models.NumberType; | ||
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentAnyRequestParameters; | ||
import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters; | ||
import java.util.Collections; | ||
import java.util.logging.Logger; | ||
|
||
public class Snippet { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); | ||
|
||
static void execute(NumbersService numbersService) { | ||
|
||
AvailableNumberService availableNumbersService = numbersService.available(); | ||
|
||
String servicePlanId = "YOUR_service_plan_id"; | ||
String regionCode = "YOUR_region_code"; | ||
|
||
Capability capability = Capability.SMS; | ||
NumberType numberType = NumberType.LOCAL; | ||
|
||
ActiveNumber response = | ||
availableNumbersService.rentAny( | ||
AvailableNumberRentAnyRequestParameters.builder() | ||
.setCapabilities(Collections.singletonList(capability)) | ||
.setType(numberType) | ||
.setRegionCode(regionCode) | ||
.setSmsConfiguration( | ||
RentSMSConfigurationRequestParameters.builder() | ||
.setServicePlanId(servicePlanId) | ||
.build()) | ||
.build()); | ||
|
||
LOGGER.info(String.format("Rented number: %s", response)); | ||
} | ||
} |
This file contains 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