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

Nexmo Server SDK V5 Support #6

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
}

dependencies {
implementation 'com.nexmo:nexmo-spring-boot-starter:1.1.0'
implementation 'com.nexmo:nexmo-spring-boot-starter:2.0.0'
}
```

Expand All @@ -33,7 +33,7 @@ For Maven:
<dependency>
<groupId>com.nexmo</groupId>
<artifactId>nexmo-spring-boot-starter</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
</dependency>
```

Expand Down Expand Up @@ -132,3 +132,7 @@ Bringing in older versions of the supported Nexmo Client, may result in some unf
| v1.0.0 | v4.3.0 |
| v1.0.1 | v4.3.1 |
| v1.1.0 | v4.4.0 |

| Nexmo Spring Boot Starter | Vonage Java Client |
|---|---|
| v2.0.0 | v5.5.0 |
10 changes: 5 additions & 5 deletions nexmo-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>com.nexmo</groupId>
<artifactId>nexmo-starter</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
</parent>

<artifactId>nexmo-spring-boot-autoconfigure</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
<name>nexmo-spring-boot-autoconfigure</name>
<description>Spring Boot Auto Configuration for Nexmo</description>
<url>https://github.com/nexmo/nexmo-spring-boot-starter</url>
Expand Down Expand Up @@ -65,9 +65,9 @@
</dependency>

<dependency>
<groupId>com.nexmo</groupId>
<groupId>com.vonage</groupId>
<artifactId>client</artifactId>
<version>${nexmo.version}</version>
<version>${vonage.version}</version>
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -149,7 +149,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<version>0.8.5</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
*/
package com.nexmo.starter

import com.nexmo.client.NexmoClient
import com.nexmo.client.account.AccountClient
import com.nexmo.client.applications.ApplicationClient
import com.nexmo.client.conversion.ConversionClient
import com.nexmo.client.insight.InsightClient
import com.nexmo.client.numbers.NumbersClient
import com.nexmo.client.redact.RedactClient
import com.nexmo.client.sms.SmsClient
import com.nexmo.client.sns.SnsClient
import com.nexmo.client.verify.VerifyClient
import com.nexmo.client.voice.VoiceClient
import com.vonage.client.VonageClient
import com.vonage.client.account.AccountClient
import com.vonage.client.application.ApplicationClient
import com.vonage.client.conversion.ConversionClient
import com.vonage.client.insight.InsightClient
import com.vonage.client.numbers.NumbersClient
import com.vonage.client.redact.RedactClient
import com.vonage.client.sms.SmsClient
import com.vonage.client.sns.SnsClient
import com.vonage.client.verify.VerifyClient
import com.vonage.client.voice.VoiceClient
import org.jetbrains.annotations.NotNull
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
Expand All @@ -42,7 +42,7 @@ import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Lazy

@Configuration
@ConditionalOnClass(NexmoClient::class)
@ConditionalOnClass(VonageClient::class)
@EnableConfigurationProperties(NexmoCredentialsProperties::class)
open class NexmoAutoConfiguration(
private val nexmoProperties: NexmoCredentialsProperties
Expand All @@ -52,12 +52,12 @@ open class NexmoAutoConfiguration(
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun nexmoBuilder(): NexmoClient.Builder {
open fun vonageBuilder(): VonageClient.Builder {
if (nexmoProperties.privateKeyContents.isNotBlank() && nexmoProperties.privateKeyPath.isNotBlank()) {
throw IllegalArgumentException("Found both private key path and private key contents. Only one option can be used at a time.")
}

val builder = NexmoClient.builder()
val builder = VonageClient.builder()
.apiKey(nexmoProperties.apiKey)
.apiSecret(nexmoProperties.secret)

Expand Down Expand Up @@ -85,75 +85,75 @@ open class NexmoAutoConfiguration(
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun nexmoClient(builder: NexmoClient.Builder): NexmoClient = builder.build()
open fun vonageClient(builder: VonageClient.Builder): VonageClient = builder.build()

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun accountClient(nexmoClient: NexmoClient): AccountClient = nexmoClient.accountClient
open fun accountClient(vonageClient: VonageClient): AccountClient = vonageClient.accountClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun applicationClient(nexmoClient: NexmoClient): ApplicationClient = nexmoClient.applicationClient
open fun applicationClient(vonageClient: VonageClient): ApplicationClient = vonageClient.applicationClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun conversionClient(nexmoClient: NexmoClient): ConversionClient = nexmoClient.conversionClient
open fun conversionClient(vonageClient: VonageClient): ConversionClient = vonageClient.conversionClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun insightClient(nexmoClient: NexmoClient): InsightClient = nexmoClient.insightClient
open fun insightClient(vonageClient: VonageClient): InsightClient = vonageClient.insightClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun numbersClient(nexmoClient: NexmoClient): NumbersClient = nexmoClient.numbersClient
open fun numbersClient(vonageClient: VonageClient): NumbersClient = vonageClient.numbersClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun redactClient(nexmoClient: NexmoClient): RedactClient = nexmoClient.redactClient
open fun redactClient(vonageClient: VonageClient): RedactClient = vonageClient.redactClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun smsClient(nexmoClient: NexmoClient): SmsClient = nexmoClient.smsClient
open fun smsClient(vonageClient: VonageClient): SmsClient = vonageClient.smsClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun snsClient(nexmoClient: NexmoClient): SnsClient = nexmoClient.snsClient
open fun snsClient(vonageClient: VonageClient): SnsClient = vonageClient.snsClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret"])
@Lazy
@NotNull
open fun verifyClient(nexmoClient: NexmoClient): VerifyClient = nexmoClient.verifyClient
open fun verifyClient(vonageClient: VonageClient): VerifyClient = vonageClient.verifyClient

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "nexmo.creds", value = ["api-key", "secret", "application-id"])
@Lazy
@NotNull
open fun voiceClient(nexmoClient: NexmoClient): VoiceClient = nexmoClient.voiceClient
open fun voiceClient(vonageClient: VonageClient): VoiceClient = vonageClient.voiceClient
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
package com.nexmo.starter

import com.nexmo.client.NexmoClient
import com.vonage.client.VonageClient
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test
Expand All @@ -45,9 +45,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.api-key=api-key",
"nexmo.creds.secret=secret"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
val builder = it.getBean("nexmoBuilder")
val builder = it.getBean("vonageBuilder")
val apiKey = ReflectionTestUtils.getField(builder, "apiKey") as String
val secret = ReflectionTestUtils.getField(builder, "apiSecret") as String

Expand All @@ -63,9 +63,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.secret=secret",
"nexmo.creds.application-id=app-id"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
val builder = it.getBean("nexmoBuilder")
val builder = it.getBean("vonageBuilder")
val appId = ReflectionTestUtils.getField(builder, "applicationId") as String

assertEquals("app-id", appId)
Expand All @@ -80,9 +80,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.private-key-path=src/test/resources/testing.key",
"nexmo.creds.private-key-contents=${keyContents}"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
it.getBean("nexmoBuilder")
it.getBean("vonageBuilder")
}
}

Expand All @@ -93,9 +93,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.secret=secret",
"nexmo.creds.private-key-contents=${keyContents}"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
val builder = it.getBean("nexmoBuilder")
val builder = it.getBean("vonageBuilder")
val builderKeyContents = ReflectionTestUtils.getField(builder, "privateKeyContents") as ByteArray

assertEquals(keyContents, builderKeyContents.toString(Charset.forName("UTF-8")))
Expand All @@ -109,9 +109,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.secret=secret",
"nexmo.creds.private-key-path=src/test/resources/testing.key"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
val builder = it.getBean("nexmoBuilder")
val builder = it.getBean("vonageBuilder")
val builderKeyContents = ReflectionTestUtils.getField(builder, "privateKeyContents") as ByteArray

assertEquals(keyContents, builderKeyContents.toString(Charset.forName("UTF-8")))
Expand All @@ -125,9 +125,9 @@ class NexmoAutoConfigurationBuilderTest {
"nexmo.creds.secret=secret",
"nexmo.creds.signature=signature"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
// Since the bean is @Lazy, it needs to be requested.
val builder = it.getBean("nexmoBuilder")
val builder = it.getBean("vonageBuilder")
val signature = ReflectionTestUtils.getField(builder, "signatureSecret") as String

assertEquals("signature", signature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
*/
package com.nexmo.starter

import com.nexmo.client.HttpWrapper
import com.nexmo.client.NexmoClient
import com.nexmo.client.account.AccountClient
import com.nexmo.client.applications.ApplicationClient
import com.nexmo.client.conversion.ConversionClient
import com.nexmo.client.insight.InsightClient
import com.nexmo.client.numbers.NumbersClient
import com.nexmo.client.redact.RedactClient
import com.nexmo.client.sms.SmsClient
import com.nexmo.client.sns.SnsClient
import com.nexmo.client.verify.VerifyClient
import com.nexmo.client.voice.VoiceClient
import com.vonage.client.HttpWrapper
import com.vonage.client.VonageClient
import com.vonage.client.account.AccountClient
import com.vonage.client.application.ApplicationClient
import com.vonage.client.conversion.ConversionClient
import com.vonage.client.insight.InsightClient
import com.vonage.client.numbers.NumbersClient
import com.vonage.client.redact.RedactClient
import com.vonage.client.sms.SmsClient
import com.vonage.client.sns.SnsClient
import com.vonage.client.verify.VerifyClient
import com.vonage.client.voice.VoiceClient
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test
Expand All @@ -48,12 +48,12 @@ class NexmoAutoConfigurationConditionOnMissingBeanTest {
@Test
fun `when user defines a builder then only that builder is in the container`() {
contextRunner.withUserConfiguration(
WithNexmoClientBuilder::class.java
WithVonageClientBuilder::class.java
).withPropertyValues(
"nexmo.creds.api-key=api-key", "nexmo.creds.secret=secret"
).run {
assertThat(it).hasSingleBean(NexmoClient.Builder::class.java)
assertThat(it).doesNotHaveBean("nexmoBuilder")
assertThat(it).hasSingleBean(VonageClient.Builder::class.java)
assertThat(it).doesNotHaveBean("vonageBuilder")
assertThat(it).hasBean("testBuilder")

}
Expand All @@ -62,13 +62,13 @@ class NexmoAutoConfigurationConditionOnMissingBeanTest {
@Test
fun `when user defines a nexmo client then only that client is in the container`() {
contextRunner.withUserConfiguration(
WithNexmoClient::class.java
WithVonageClient::class.java
).withPropertyValues(
"nexmo.creds.api-key=api-key", "nexmo.creds.secret=secret"
).run {
assertThat(it).hasSingleBean(NexmoClient::class.java)
assertThat(it).doesNotHaveBean("nexmoClient")
assertThat(it).hasBean("testNexmoClient")
assertThat(it).hasSingleBean(VonageClient::class.java)
assertThat(it).doesNotHaveBean("VonageClient")
assertThat(it).hasBean("testVonageClient")

}
}
Expand Down Expand Up @@ -216,11 +216,11 @@ class NexmoAutoConfigurationConditionOnMissingBeanTest {
@Test
fun `when user defines a builder then that builder is used to build the Nexmo Client`() {
contextRunner.withUserConfiguration(
WithNexmoClientBuilderHavingCustomBaseUri::class.java
WithVonageClientBuilderHavingCustomBaseUri::class.java
).withPropertyValues(
"nexmo.creds.api-key=api-key", "nexmo.creds.secret=secret"
).run {
val client = it.getBean(NexmoClient::class.java)
val client = it.getBean(VonageClient::class.java)
val wrapper = ReflectionTestUtils.getField(client, "httpWrapper") as HttpWrapper

assertEquals("https://example.com", wrapper.httpConfig.apiBaseUri)
Expand Down
Loading