Skip to content

Commit

Permalink
refactor (Numbers/rent): 'RentAndConfig' renamed to 'Rent' for simpli…
Browse files Browse the repository at this point in the history
…fication
  • Loading branch information
JPPortier committed Jun 20, 2024
1 parent bf42f8c commit dd9b3a7
Showing 1 changed file with 2 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package numbers;

import com.sinch.sdk.domains.numbers.ActiveNumberService;
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.ActiveNumberUpdateRequestParameters;
import com.sinch.sdk.domains.numbers.models.requests.ActiveNumberUpdateVoiceConfigurationRequestParameters;
import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentRequestParameters;
import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters;
import java.util.logging.Logger;
Expand All @@ -18,13 +15,10 @@ 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
// 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";
String appId = "YOUR_app_id";

String displayName = "Updated from Sinch Java SDK";

RentSMSConfigurationRequestParameters smsConfiguration =
RentSMSConfigurationRequestParameters.builder().setServicePlanId(servicePlanId).build();
Expand All @@ -34,27 +28,8 @@ static void execute(NumbersService numbersService) {
.setSmsConfiguration(smsConfiguration)
.build();

// rent with configuration settings
ActiveNumber response = availableNumbersService.rent(phoneNumber, rentRequest);

LOGGER.info(String.format("Rented number: %s", response));

// Update rented number to edit configuration:
// - adding voice configuration
// - setting a display name
ActiveNumberService activeNumbersService = numbersService.active();

ActiveNumberUpdateVoiceConfigurationRequestParameters voiceConfiguration =
ActiveNumberUpdateVoiceConfigurationRequestParameters.builder().setAppId(appId).build();

ActiveNumberUpdateRequestParameters updateRequest =
ActiveNumberUpdateRequestParameters.builder()
.setDisplayName(displayName)
.setVoiceConfiguration(voiceConfiguration)
.build();

response = activeNumbersService.update(phoneNumber, updateRequest);

LOGGER.info(String.format("Updated number: %s", response));
}
}

0 comments on commit dd9b3a7

Please sign in to comment.