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

Add missing Endpoint types for Voice #446

Merged
merged 3 commits into from
Apr 11, 2023
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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/).

# [7.2.0]
# [7.2.0] - 2023-03-08
- Updates to Messages v1:
- Added `InboundMessage` webhook class
- Fixed timestamp format deserialization for MessageStatus (now returns an Instant)
Expand Down
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ repositories {
}

dependencies {
compileOnly 'javax.servlet:javax.servlet-api:4.0.1'

implementation 'commons-codec:commons-codec:1.15'
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'
implementation 'io.openapitools.jackson.dataformat:jackson-dataformat-hal:1.0.9'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
implementation 'jakarta.servlet:jakarta.servlet-api:4.0.4'
implementation 'com.vonage:jwt:1.0.2'

testImplementation 'javax.servlet:javax.servlet-api:4.0.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.11.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/vonage/client/voice/AppEndpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2023 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
* Represents an app-to-app call type.
*
* @since 7.3.0
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class AppEndpoint implements Endpoint {
private static final String TYPE = "app";
private String user;

protected AppEndpoint() {
}

public AppEndpoint(String user) {
this.user = user;
}

/**
* The username to call.
*
* @return The app user, or {@code null} if unset.
*/
public String getUser() {
return user;
}

@Override
public String toLog() {
return user;
}

@Override
public String getType() {
return TYPE;
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/vonage/client/voice/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void setAnswerUrl(String answerUrl) {
@JsonProperty("answer_method")
public String getAnswerMethod() {
// Hide the answer method if the answer url isn't defined
return (answerUrl != null) ? answerMethod : null;
return answerUrl != null ? answerMethod : null;
}

public void setAnswerMethod(String answerMethod) {
Expand Down Expand Up @@ -158,12 +158,13 @@ public Boolean getFromRandomNumber() {
return fromRandomNumber;
}


/**
* Set to true to use random phone number as from. The number will be selected from the list of the numbers assigned to the current application. random_from_number: true cannot be used together with from.
* @param fromRandomNumber Whether to use random number.
*/
public void setFromRandomNumber(Boolean fromRandomNumber) { this.fromRandomNumber = fromRandomNumber; }
public void setFromRandomNumber(Boolean fromRandomNumber) {
this.fromRandomNumber = fromRandomNumber;
}

@JsonProperty("ncco")
public Collection<? extends Action> getNcco() {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/vonage/client/voice/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@
@JsonSubTypes({
@JsonSubTypes.Type(value = PhoneEndpoint.class, name = "phone"),
@JsonSubTypes.Type(value = SipEndpoint.class, name = "sip"),
@JsonSubTypes.Type(value = WebSocketEndpoint.class, name = "websocket")
@JsonSubTypes.Type(value = WebSocketEndpoint.class, name = "websocket"),
@JsonSubTypes.Type(value = VbcEndpoint.class, name = "vbc"),
@JsonSubTypes.Type(value = AppEndpoint.class, name = "app")
})
public interface Endpoint {

/**
* Endpoint type name.
*
* @return The type of endpoint as a string.
*/
String getType();

/**
* Description of the endpoint.
*
* @return String representation of the object.
*/
String toLog();
}
11 changes: 6 additions & 5 deletions src/main/java/com/vonage/client/voice/PhoneEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Objects;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PhoneEndpoint implements Endpoint {
private final String type = "phone";
private static final String TYPE = "phone";
private String number, dtmfAnswer;

public PhoneEndpoint() {
Expand All @@ -37,7 +39,7 @@ public PhoneEndpoint(String number, String dtmfAnswer) {

@Override
public String getType() {
return type;
return TYPE;
}

@Override
Expand Down Expand Up @@ -66,13 +68,12 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PhoneEndpoint that = (PhoneEndpoint) o;
return Objects.equals(type, that.type) &&
Objects.equals(number, that.number) &&
return Objects.equals(number, that.number) &&
Objects.equals(dtmfAnswer, that.dtmfAnswer);
}

@Override
public int hashCode() {
return Objects.hash(type, number, dtmfAnswer);
return Objects.hash(TYPE, number, dtmfAnswer);
}
}
10 changes: 8 additions & 2 deletions src/main/java/com/vonage/client/voice/SipEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SipEndpoint implements Endpoint {
private static final String TYPE = "sip";
private String uri;
private String type = "sip";

protected SipEndpoint() {
}

public SipEndpoint(String uri) {
this.uri = uri;
}

@Deprecated
public void setUri(String uri) {
this.uri = uri;
}
Expand All @@ -36,7 +42,7 @@ public String getUri() {

@Override
public String getType() {
return type;
return TYPE;
}

@Override
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/vonage/client/voice/VbcEndpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2023 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
* Represents a VBC call type.
*
* @since 7.3.0
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class VbcEndpoint implements Endpoint {
private static final String TYPE = "vbc";
private String extension;

protected VbcEndpoint() {
}

public VbcEndpoint(String extension) {
this.extension = extension;
}

/**
* The extension to call.
*
* @return The VBC extension, or {@code null} if unset.
*/
public String getExtension() {
return extension;
}

@Override
public String toLog() {
return extension;
}

@Override
public String getType() {
return TYPE;
}
}
46 changes: 39 additions & 7 deletions src/main/java/com/vonage/client/voice/WebSocketEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,43 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class WebSocketEndpoint implements Endpoint {
private String uri;
private String type = "websocket";
private String contentType;
private List<NameValuePair> headers;
private static final String TYPE = "websocket";
private String uri, contentType;
@JsonProperty("headers") private Map<String, Object> headers;

public WebSocketEndpoint(String uri, String contentType, List<NameValuePair> headers) {
protected WebSocketEndpoint() {
}

public WebSocketEndpoint(String uri, String contentType, Map<String, Object> headers) {
this.uri = uri;
this.contentType = contentType;
this.headers = headers;
}

@Deprecated
public WebSocketEndpoint(String uri, String contentType, List<NameValuePair> headers) {
this.uri = uri;
this.contentType = contentType;
setHeaders(headers);
}

@Override
public String getType() {
return type;
return TYPE;
}

@Override
Expand All @@ -52,19 +68,35 @@ public String getContentType() {
return contentType;
}

@Deprecated
@JsonIgnore
public List<NameValuePair> getHeaders() {
if (headers == null) return null;
return headers.entrySet().stream()
.map(e -> new BasicNameValuePair(e.getKey(), Objects.toString(e.getValue())))
.collect(Collectors.toList());
}

@JsonProperty("headers")
public Map<String, ?> getHeadersMap() {
return headers;
}

@Deprecated
public void setUri(String uri) {
this.uri = uri;
}

@Deprecated
public void setContentType(String contentType) {
this.contentType = contentType;
}

@JsonIgnore
@Deprecated
public void setHeaders(List<NameValuePair> headers) {
this.headers = headers;
this.headers = headers.stream().collect(Collectors.toMap(
NameValuePair::getName, NameValuePair::getValue
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private AppEndpoint(Builder builder) {
this.user = builder.user;
}

@Override
public String getType() {
return TYPE;
}
Expand Down
Loading