diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..4896f4c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,43 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Request/Response** +If applicable, please provide the request used and the response + +**Java Version** +- Version: + +**Kotlin Version** +- Version: + +**Kotlin SDK Version** +- Version: + +**Proxy Server Used** + * [ ] Yes + * [ ] No + +**Additional context/ Error Log** +Add any other context about the problem here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..82a1bc5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,6 @@ +_Describe your changes here_ + +## Contribution Checklist +* [ ] Unit tests! +* [ ] Updated [CHANGELOG.md](CHANGELOG.md) +* [ ] My name is in [CONTRIBUTORS.md](CONTRIBUTORS.md) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3b1013a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build Java CI +on: + push: + branches: + - main + pull_request: + +permissions: + actions: write + checks: write + contents: read + deployments: read + issues: write + discussions: read + packages: none + pages: read + pull-requests: write + security-events: write + statuses: write + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + java: [8, 17, 22] + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: ${{ matrix.java }} + cache: maven + - name: Compile with Maven + run: mvn --batch-mode verify diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9c165b5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,43 @@ +name: Publish to Central +on: + release: + types: [published] + +permissions: + actions: write + checks: write + contents: write + deployments: read + issues: write + discussions: write + packages: write + pages: write + pull-requests: write + security-events: write + statuses: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.target_commitish }} + - name: Setup Java + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' + cache: maven + server-id: nexus-releases + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.SIGNING_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + - name: Publish package + env: + MAVEN_USERNAME: ${{ secrets.OSS_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSS_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.SIGNING_PASSWORD }} + run: mvn --no-transfer-progress --batch-mode deploy -P release-sign-artifacts diff --git a/.gitignore b/.gitignore index 524f096..c06a0a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,42 @@ -# Compiled class file -*.class +.gradle +build/ +/build +/target +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ +dependency-reduced-pom.xml -# Log file -*.log +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ -# BlueJ files -*.ctxt +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar +### VS Code ### +.vscode/ -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..d66b45a --- /dev/null +++ b/.whitesource @@ -0,0 +1,3 @@ +{ + "settingsInheritedFrom": "Vonage/whitesource-config@main" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..828c4d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Change Log +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..fbf1304 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at support@nexmo.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9246728 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Getting Involved + +Thanks for your interest in the project, we'd love to have you involved! Check out the sections below to find out more about what to do next... + +## Opening an Issue + +We always welcome issues, if you've seen something that isn't quite right or you have a suggestion for a new feature, please go ahead and open an issue in this project. Include as much information as you have, it really helps. + +## Making a Code Change + +We're always open to pull requests, but these should be small and clearly described so that we can understand what you're trying to do. Feel free to open an issue first and get some discussion going. + +When you're ready to start coding, fork this repository to your own GitHub account and make your changes in a new branch. Once you're happy, open a pull request and explain what the change is and why you think we should include it in our project. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..e2248e9 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +# Contributors + +This is the vonage-java-sdk hall of fame! All contributors of source code, or +documentation, or tests are eligible to be added to this list. + +- Sina Madani ([@SMadani](https://github.com/SMadani)) \ No newline at end of file diff --git a/README.md b/README.md index aa2afbc..710f128 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# vonage-kotlin-sdk -Vonage Server SDK for Kotlin. API support for SMS, Messages, Voice, Text-to-Speech, Numbers, Verify (2FA), Video and more. +# Vonage Server SDK for Kotlin (JVM) + +[![Maven Release](https://maven-badges.herokuapp.com/maven-central/com.vonage/kotlin-server-sdk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.vonage/server-sdk) +[![Build Status](https://github.com/Vonage/vonage-java-sdk/actions/workflows/build.yml/badge.svg)](https://github.com/Vonage/vonage-java-sdk/actions/workflows/build.yml?query=workflow%3A"Build+Java+CI") +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE.txt) + +This SDK provides syntactic sugar for the [Vonage Java Server SDK](https://github.com/Vonage/vonage-java-sdk) +to improve the user experience in Kotlin. It is therefore subject to the same requirements and capabilities. + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ac87bd2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,201 @@ + + + 4.0.0 + + com.vonage + kotlin-server-sdk + 0.0.1-SNAPSHOT + + jar + Vonage Kotlin Server SDK + Java client for Vonage APIs + https://github.com/Vonage/vonage-kotlin-sdk + + Vonage + https://developer.vonage.com + + + + + The Apache License, Version 2.0 + ${project.url}/blob/main/LICENCE.txt + + + + + + devrel + Vonage DevRel + devrel@vonage.com + + + + + scm:git@github.com:Vonage/vonage-kotlin-sdk + ${scm.connection} + ${project.url} + + + GitHub + ${project.url}/issues + + + + https://oss.sonatype.org + UTF-8 + 8 + 2.0.0 + ${kotlin.version} + ${java.version} + ${java.version} + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + com.vonage + server-sdk + 8.8.1 + + + org.jetbrains.kotlin + kotlin-test-junit + ${kotlin.version} + test + + + + + + nexus-snapshots + ${nexusUrl}/content/repositories/snapshots/ + + + nexus-releases + ${nexusUrl}/service/local/staging/deploy/maven2/ + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + true + + + maven-source-plugin + 3.3.1 + + + attach-sources + + jar-no-fork + + + + + + maven-javadoc-plugin + 3.7.0 + + true + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.1 + + + + true + + + ${maven.build.timestamp} + + + + + + maven-assembly-plugin + 3.7.1 + + + package + + single + + + + jar-with-dependencies + + + + + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + + maven-gpg-plugin + 3.2.4 + + + sign-artifacts + verify + + sign + + + + + + --pinentry-mode + loopback + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.7.0 + true + + nexus-releases + ${nexusUrl} + true + + + + + + + diff --git a/src/main/kotlin/com/vonage/client/kt/Messages.kt b/src/main/kotlin/com/vonage/client/kt/Messages.kt new file mode 100644 index 0000000..c2f068c --- /dev/null +++ b/src/main/kotlin/com/vonage/client/kt/Messages.kt @@ -0,0 +1,12 @@ +package org.example.com.vonage.client.kt + +import com.vonage.client.messages.sms.SmsTextRequest +import com.vonage.client.messages.whatsapp.WhatsappTextRequest + +fun sms(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest { + return SmsTextRequest.builder().apply(init).build() +} + +fun whatsappText(init: WhatsappTextRequest.Builder.() -> Unit): WhatsappTextRequest { + return WhatsappTextRequest.builder().apply(init).build() +} \ No newline at end of file diff --git a/src/main/kotlin/com/vonage/client/kt/Verify.kt b/src/main/kotlin/com/vonage/client/kt/Verify.kt new file mode 100644 index 0000000..dcb11df --- /dev/null +++ b/src/main/kotlin/com/vonage/client/kt/Verify.kt @@ -0,0 +1,19 @@ +package org.example.com.vonage.client.kt + +import com.vonage.client.verify2.SmsWorkflow +import com.vonage.client.verify2.VerificationRequest +import com.vonage.client.verify2.Verify2Client +import com.vonage.client.verify2.VoiceWorkflow +import java.util.* + +fun Verify2Client.sendVerification(init: VerificationRequest.Builder.() -> Unit) : UUID { + return this.sendVerification(VerificationRequest.builder().apply(init).build()).requestId +} + +fun VerificationRequest.Builder.sms(number: String, init: SmsWorkflow.Builder.() -> Unit = {}) : VerificationRequest.Builder { + return this.addWorkflow(SmsWorkflow.builder(number).apply(init).build()) +} + +fun VerificationRequest.Builder.voice(number: String) : VerificationRequest.Builder { + return this.addWorkflow(VoiceWorkflow(number)) +} \ No newline at end of file diff --git a/src/main/kotlin/com/vonage/client/kt/Vonage.kt b/src/main/kotlin/com/vonage/client/kt/Vonage.kt new file mode 100644 index 0000000..6a0cec4 --- /dev/null +++ b/src/main/kotlin/com/vonage/client/kt/Vonage.kt @@ -0,0 +1,38 @@ +package org.example.com.vonage.client.kt + +import com.vonage.client.HttpConfig +import com.vonage.client.VonageClient +import com.vonage.client.messages.MessageRequest +import com.vonage.client.verify2.Verify2Client +import java.time.Instant +import java.util.* + +class Vonage constructor(init: VonageClient.Builder.() -> Unit) { + private val vonageClient : VonageClient = VonageClient.builder().apply(init).build(); + val verify: Verify2Client = vonageClient.verify2Client + + fun sendMessage(request: MessageRequest) : UUID { + return vonageClient.messagesClient.sendMessage(request).messageUuid + } + + fun simSwapDate(phoneNumber: String): Instant { + return vonageClient.simSwapClient.retrieveSimSwapDate(phoneNumber) + } +} + +fun VonageClient.Builder.authFromEnv() : VonageClient.Builder { + apiKey(env("VONAGE_API_KEY")) + apiSecret(env("VONAGE_API_SECRET")) + signatureSecret(env("VONAGE_SIGNATURE_SECRET")) + applicationId(env("VONAGE_APPLICATION_ID")) + privateKeyPath(env("VONAGE_PRIVATE_KEY_PATH")) + return this +} + +fun httpConfig(init: HttpConfig.Builder.() -> Unit): HttpConfig { + return HttpConfig.builder().apply(init).build() +} + +private fun env(variable : String) : String { + return System.getenv(variable) +} \ No newline at end of file