Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-462 numbers snippets #6

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions snippets/numbers/rent_and_config/Snippet.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the name of the folder, I would have expected another action to configure the rented number. For instance, you are also providing the SMS config in the rent_any snippet.
Maybe you can add a second request (update) to set the Voice config ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done; but will sync with doc.
Seems snippet become more than a simple snippet.
We could imagine something like:

  • rentAny snippet: from this PR highlighting rent and configuration for SMS with a single request
  • rent snippet: the 1st part of this snippet source to rent an available number returned by "list available"
  • update snippet: the 2nd part of this snippet source to perform an update onto an already rented number

Will check with doc (@alex-sberna )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
According to last sync:

  • rent_and_config become simply 'rent' (even if it contains configuration; the purpose of the snippet is to highlight a 'rent' action)
  • a new 'update only' snippet is added

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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();

String servicePlanId = "YOUR_service_plan_id";
String phoneNumber = "YOUR_phone_number";
asein-sinch marked this conversation as resolved.
Show resolved Hide resolved

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

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
Loading