Skip to content

Commit

Permalink
DEVEXP-462 numbers snippets (#6)
Browse files Browse the repository at this point in the history
* feature (Numbers): rent, rentAny and active number update snippets
  • Loading branch information
JPPortier authored Jun 24, 2024
1 parent 640e54b commit c60847f
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 16 deletions.
3 changes: 2 additions & 1 deletion compile.sh
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)

14 changes: 14 additions & 0 deletions snippets/compile.sh
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
35 changes: 35 additions & 0 deletions snippets/numbers/active_update/Snippet.java
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));
}
}
35 changes: 35 additions & 0 deletions snippets/numbers/rent/Snippet.java
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));
}
}
41 changes: 41 additions & 0 deletions snippets/numbers/rent_any/Snippet.java
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));
}
}
19 changes: 4 additions & 15 deletions snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<sources>
<source>.</source>
</sources>
<compileSourceRoots>${snippet}</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>

<!-- code format -->
Expand Down

0 comments on commit c60847f

Please sign in to comment.