Skip to content

Commit

Permalink
feature (Numbers/RentAndConfig): Add a dedicated update request to ed…
Browse files Browse the repository at this point in the history
…it number's settings
  • Loading branch information
JPPortier committed Jun 20, 2024
1 parent 2a12786 commit bf42f8c
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions snippets/numbers/rent_and_config/Snippet.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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 @@ -15,19 +18,43 @@ 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";
String phoneNumber = "YOUR_phone_number";

ActiveNumber response =
availableNumbersService.rent(
phoneNumber,
AvailableNumberRentRequestParameters.builder()
.setSmsConfiguration(
RentSMSConfigurationRequestParameters.builder()
.setServicePlanId(servicePlanId)
.build())
.build());
String appId = "YOUR_app_id";

String displayName = "Updated from Sinch Java SDK";

RentSMSConfigurationRequestParameters smsConfiguration =
RentSMSConfigurationRequestParameters.builder().setServicePlanId(servicePlanId).build();

AvailableNumberRentRequestParameters rentRequest =
AvailableNumberRentRequestParameters.builder()
.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 bf42f8c

Please sign in to comment.