diff --git a/compile.sh b/compile.sh index dcab5fa..507ee01 100755 --- a/compile.sh +++ b/compile.sh @@ -1,4 +1,5 @@ #!/bin/sh -(cd snippets && mvn clean spotless:apply compile) +(cd snippets && mvn clean spotless:apply) +(cd snippets && ./compile.sh) diff --git a/snippets/compile.sh b/snippets/compile.sh new file mode 100755 index 0000000..eb921f1 --- /dev/null +++ b/snippets/compile.sh @@ -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 diff --git a/snippets/numbers/active_update/Snippet.java b/snippets/numbers/active_update/Snippet.java new file mode 100644 index 0000000..78e94d9 --- /dev/null +++ b/snippets/numbers/active_update/Snippet.java @@ -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)); + } +} diff --git a/snippets/numbers/rent/Snippet.java b/snippets/numbers/rent/Snippet.java new file mode 100644 index 0000000..bbb7da5 --- /dev/null +++ b/snippets/numbers/rent/Snippet.java @@ -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)); + } +} 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)); + } +} diff --git a/snippets/pom.xml b/snippets/pom.xml index 4cdfe3f..f517ec8 100644 --- a/snippets/pom.xml +++ b/snippets/pom.xml @@ -21,23 +21,12 @@ - org.codehaus.mojo - build-helper-maven-plugin - 3.2.0 - - - add-sources - generate-sources - - add-source - + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 - - . - + ${snippet} - -