From 9bd054d2ce93f43167670f40cde566b85586d506 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 18 Jun 2024 15:31:18 +0200 Subject: [PATCH] feature: RentAny snippet --- snippets/numbers/rent_any/Snippet.java | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 snippets/numbers/rent_any/Snippet.java diff --git a/snippets/numbers/rent_any/Snippet.java b/snippets/numbers/rent_any/Snippet.java new file mode 100644 index 0000000..a4e28b3 --- /dev/null +++ b/snippets/numbers/rent_any/Snippet.java @@ -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)); + } +}