-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sinch/DEVEXP-373-template-for-client-appli…
…cation DEVEXP-373: template for client application
- Loading branch information
Showing
14 changed files
with
475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Compilation | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Building | ||
run: | | ||
./compile.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# sinch-sdk-java-quickstart | ||
Sinch Java SDK Quick Start Repository | ||
|
||
This repository contains tutorials and projects's templates related to [Sinch JAVA SDK](https://github.com/sinch/sinch-sdk-java) usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
mvn clean spotless:apply | ||
|
||
(cd templates/client && mvn clean package) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.sinch.sdk.archetypes</groupId> | ||
<artifactId>sinch-java-sdk-client-quickstart</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>Sinch Java SDK Client quickstart</name> | ||
|
||
<properties> | ||
<sinch.sdk.java.version>[1.0.0,)</sinch.sdk.java.version> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<maven.compiler.version>3.8.0</maven.compiler.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<!-- code format --> | ||
<plugin> | ||
<groupId>com.diffplug.spotless</groupId> | ||
<artifactId>spotless-maven-plugin</artifactId> | ||
<version>2.40.0</version> | ||
|
||
<configuration> | ||
|
||
<java> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
|
||
<googleJavaFormat> | ||
<version>1.22.0</version> | ||
<style>AOSP</style> | ||
<reflowLongStrings>true</reflowLongStrings> | ||
</googleJavaFormat> | ||
<endWithNewline /> | ||
<removeUnusedImports /> | ||
<indent> | ||
<spaces>true</spaces> | ||
<spacesPerTab>2</spacesPerTab> | ||
</indent> | ||
<trimTrailingWhitespace /> | ||
</java> | ||
|
||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Client application based onto Sinch Java SDK | ||
|
||
This directory contains a client application based onto [Sinch SDK java](https://github.com/sinch/sinch-sdk-java) | ||
|
||
# Prerequisites | ||
|
||
- JDK 8 or later (Sinch SDK Java is requiring java 8 only but client application can use latest available version) | ||
- [Maven](https://maven.apache.org/) | ||
- [Sinch account](https://dashboard.sinch.com) | ||
|
||
## Configuration | ||
|
||
Edit [config.properties](src/main/resources/config.properties) file to set credentials to be used to configure the SinchClient. | ||
|
||
- To use Numbers or SMS, you need to fill the following settings with your Sinch account information: | ||
- `SINCH_PROJECT_ID`=Your Sinch Project ID | ||
- `SINCH_KEY_ID`=Your Sinch Key ID | ||
- `SINCH_KEY_SECRET`=Your Sinch Key Secret | ||
- To use [Verification](https://developers.sinch.com/docs/verification) or [Voice](https://developers.sinch.com/docs/voice) you will need application credentials and fill [config.properties](src/main/resources/config.properties) dedicated section. | ||
- To use [SMS](https://developers.sinch.com/docs/sms) for regions other than US/EU, you will need service plan ID credentials and fill [config.properties](src/main/resources/config.properties) dedicated section. | ||
|
||
|
||
## Usage | ||
|
||
1. Edit configuration file | ||
See above for Configuration paragraph | ||
|
||
2. Application generation | ||
|
||
Application generation command: | ||
```sh | ||
mvn package | ||
``` | ||
3. Execute application | ||
```sh | ||
java -jar target/sinch-java-sdk-client-application-1.0-SNAPSHOT-jar-with-dependencies.jar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>my.company.com</groupId> | ||
<artifactId>sinch-java-sdk-client-application</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>Sinch Java SDK Client Application</name> | ||
|
||
<properties> | ||
<sinch.sdk.java.version>[1.0.0,)</sinch.sdk.java.version> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<maven.compiler.version>3.13.0</maven.compiler.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<executions> | ||
<execution> | ||
<id>add-sources</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>src/main/java</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass> | ||
Application | ||
</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.sinch.sdk</groupId> | ||
<artifactId>sinch-sdk-java</artifactId> | ||
<version>${sinch.sdk.java.version}</version> | ||
</dependency> | ||
|
||
<!-- We don't care about logs from 3rd party dependencies for sample app: | ||
then we remove the warning about missing SLF4J logger --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-nop</artifactId> | ||
<version>2.0.9</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import com.sinch.sdk.SinchClient; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.Logger; | ||
import numbers.NumbersQuickStart; | ||
import sms.SmsQuickStart; | ||
import verification.VerificationQuickStart; | ||
import voice.VoiceQuickStart; | ||
|
||
public abstract class Application { | ||
|
||
private static final String LOGGING_PROPERTIES_FILE = "logging.properties"; | ||
private static final Logger LOGGER = initializeLogger(); | ||
|
||
public static void main(String[] args) { | ||
try { | ||
|
||
SinchClient client = SinchClientHelper.initSinchClient(); | ||
LOGGER.info("Application initiated. SinchClient ready."); | ||
|
||
// Numbers service dedicated business logic processing | ||
// (see https://developers.sinch.com/categories/numbersandconnectivity) | ||
// comment if unused | ||
if (client.getConfiguration().getUnifiedCredentials().isPresent()) { | ||
NumbersQuickStart numbers = new NumbersQuickStart(client.numbers()); | ||
} | ||
|
||
// SMS service dedicated business logic processing | ||
// (see https://developers.sinch.com/docs/sms) | ||
// comment if unused | ||
if (client.getConfiguration().getSmsServicePlanCredentials().isPresent() | ||
|| client.getConfiguration().getUnifiedCredentials().isPresent()) { | ||
SmsQuickStart sms = new SmsQuickStart(client.sms()); | ||
} | ||
|
||
// Verification service dedicated business logic processing | ||
// (see | ||
// https://developers.sinch.com/docs/verification) | ||
// comment if unused | ||
if (client.getConfiguration().getApplicationCredentials().isPresent()) { | ||
VerificationQuickStart verification = | ||
new VerificationQuickStart(client.verification()); | ||
} | ||
|
||
// Voice service dedicated business logic processing | ||
// (see | ||
// https://developers.sinch.com/docs/voice) | ||
// comment if unused | ||
if (client.getConfiguration().getApplicationCredentials().isPresent()) { | ||
VoiceQuickStart voice = new VoiceQuickStart(client.voice()); | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.severe(String.format("Application failure: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
static Logger initializeLogger() { | ||
try (InputStream logConfigInputStream = | ||
Application.class.getClassLoader().getResourceAsStream(LOGGING_PROPERTIES_FILE)) { | ||
|
||
if (logConfigInputStream != null) { | ||
LogManager.getLogManager().readConfiguration(logConfigInputStream); | ||
} else { | ||
throw new RuntimeException( | ||
String.format( | ||
"The file '%s' couldn't be loaded.", LOGGING_PROPERTIES_FILE)); | ||
} | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException(e.getMessage()); | ||
} | ||
return Logger.getLogger(Application.class.getName()); | ||
} | ||
} |
Oops, something went wrong.