Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sinch.sdk.domains.voice.models.v1.svaml.action;

/**
* Base class related to SVAML actions available for managing ongoing, connected calls (updateCall
* and manageCallWithCallLeg).
*
* @see SvamlActionHangup
* @see SvamlActionContinue
* @see SvamlActionPark
* @since 2.1
*/
public interface ManagedCallSvamlAction {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.sinch.sdk.domains.voice.api.v1.CallsService;
import com.sinch.sdk.domains.voice.models.v1.calls.CallInformationTest;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequestTest;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControlTest;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -38,8 +38,8 @@ public class CallsServiceTest extends BaseTest {
@GivenTextResource("/domains/voice/v1/calls/GetCallInformationResponseDto.json")
String getCallInformationResponseDto;

@GivenTextResource("/domains/voice/v1/svaml/SvamlControlDto.json")
String svamlControlDto;
@GivenTextResource("/domains/voice/v1/calls/request/CallUpdateRequestDto.json")
String callUpdateRequestDto;

static final Collection<String> AUTH_NAMES = Arrays.asList("Basic", "Signed");

Expand Down Expand Up @@ -95,7 +95,7 @@ void update() throws ApiException {
"/calling/v1/calls/id/" + URLPathUtils.encodePathSegment("call/id"),
HttpMethod.PATCH,
Collections.emptyList(),
svamlControlDto,
callUpdateRequestDto,
Collections.emptyMap(),
Collections.emptyList(),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Expand All @@ -108,7 +108,7 @@ void update() throws ApiException {
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

service.update("call/id", SvamlControlTest.expectedSvamlControl);
service.update("call/id", CallUpdateRequestTest.expectedCallUpdateRequest);
}

@Test
Expand All @@ -119,7 +119,7 @@ void manageWithCallLeg() throws ApiException {
"/calling/v1/calls/id/" + URLPathUtils.encodePathSegment("call/id") + "/leg/both",
HttpMethod.PATCH,
Collections.emptyList(),
svamlControlDto,
callUpdateRequestDto,
Collections.emptyMap(),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Expand All @@ -132,6 +132,7 @@ void manageWithCallLeg() throws ApiException {
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

service.manageWithCallLeg("call/id", CallLeg.BOTH, SvamlControlTest.expectedSvamlControl);
service.manageWithCallLeg(
"call/id", CallLeg.BOTH, CallUpdateRequestTest.expectedCallUpdateRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import com.sinch.sdk.domains.voice.api.v1.CallsService;
import com.sinch.sdk.domains.voice.models.v1.Price;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequest;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation.DomainEnum;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation.ReasonEnum;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation.StatusEnum;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallResult;
import com.sinch.sdk.domains.voice.models.v1.destination.DestinationPstn;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlActionContinue;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlActionHangup;
import com.sinch.sdk.domains.voice.models.v1.svaml.instruction.SvamlInstructionPlayFiles;
Expand Down Expand Up @@ -46,8 +46,8 @@ public void getCall() {
@When("^I send a request to update a call$")
public void updateCall() {

SvamlControl request =
SvamlControl.builder()
CallUpdateRequest request =
CallUpdateRequest.builder()
.setInstructions(
Arrays.asList(
SvamlInstructionSay.builder()
Expand All @@ -63,8 +63,8 @@ public void updateCall() {
@When("^I send a request to update a call that doesn't exist$")
public void updateCallNotExits() {

SvamlControl request =
SvamlControl.builder()
CallUpdateRequest request =
CallUpdateRequest.builder()
.setInstructions(
Arrays.asList(
SvamlInstructionSay.builder()
Expand All @@ -83,8 +83,8 @@ public void updateCallNotExits() {
@When("^I send a request to manage a call with callLeg$")
public void manageCallWithCallLeg() {

SvamlControl request =
SvamlControl.builder()
CallUpdateRequest request =
CallUpdateRequest.builder()
.setInstructions(
Arrays.asList(
SvamlInstructionPlayFiles.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.voice.api.v1.CallsService;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlAction;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequest;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.ManagedCallSvamlAction;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlActionHangup;
import com.sinch.sdk.domains.voice.models.v1.svaml.instruction.SvamlInstruction;
import com.sinch.sdk.domains.voice.models.v1.svaml.instruction.SvamlInstructionSay;
Expand Down Expand Up @@ -47,16 +47,16 @@ public static void main(String[] args) {

LOGGER.info(String.format("Manage call with ID '%s'", callId));

SvamlAction action = SvamlActionHangup.SVAML_ACTION_HANGUP;
ManagedCallSvamlAction action = SvamlActionHangup.SVAML_ACTION_HANGUP;

Collection<SvamlInstruction> instructions =
Collections.singletonList(
SvamlInstructionSay.builder()
.setText("Hello, the call is over, hanging up now. Goodbye")
.build());

SvamlControl request =
SvamlControl.builder().setInstructions(instructions).setAction(action).build();
CallUpdateRequest request =
CallUpdateRequest.builder().setInstructions(instructions).setAction(action).build();

callsService.manageWithCallLeg(callId, callLeg, request);

Expand Down
10 changes: 5 additions & 5 deletions examples/snippets/src/main/java/voice/calls/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.voice.api.v1.CallsService;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlAction;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequest;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.ManagedCallSvamlAction;
import com.sinch.sdk.domains.voice.models.v1.svaml.action.SvamlActionHangup;
import com.sinch.sdk.domains.voice.models.v1.svaml.instruction.SvamlInstruction;
import com.sinch.sdk.domains.voice.models.v1.svaml.instruction.SvamlInstructionSay;
Expand All @@ -34,7 +34,7 @@ public static void main(String[] args) {
// The instruction to be performed
SvamlInstruction instruction = SvamlInstructionSay.builder().setText("Goodbye").build();
// The instruction to add to the call
SvamlAction action = SvamlActionHangup.SVAML_ACTION_HANGUP;
ManagedCallSvamlAction action = SvamlActionHangup.SVAML_ACTION_HANGUP;

Configuration configuration =
Configuration.builder()
Expand All @@ -50,8 +50,8 @@ public static void main(String[] args) {

Collection<SvamlInstruction> instructions = Collections.singletonList(instruction);

SvamlControl request =
SvamlControl.builder().setInstructions(instructions).setAction(action).build();
CallUpdateRequest request =
CallUpdateRequest.builder().setInstructions(instructions).setAction(action).build();

callsService.update(callId, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.sinch.sdk.core.exceptions.ApiException;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequest;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;

Expand Down Expand Up @@ -53,10 +54,10 @@ public interface CallsService {
* &#x60;caller&#x60;.&lt;br&gt;&lt;Warning&gt;The &#x60;callLeg&#x60; identifier is ignored
* for calls that are part of a conference and calls initiated using the Callout
* API.&lt;/Warning&gt; (required)
* @param svamlControl (optional)
* @param callUpdateRequest (optional)
* @throws ApiException if fails to make API call
*/
void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl)
void manageWithCallLeg(String callId, CallLeg callLeg, CallUpdateRequest callUpdateRequest)
throws ApiException;

/**
Expand All @@ -70,8 +71,43 @@ void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl
*
* @param callId The unique identifier of the call. This value is generated by the system.
* (required)
* @param callUpdateRequest (optional)
* @throws ApiException if fails to make API call
*/
void update(String callId, CallUpdateRequest callUpdateRequest) throws ApiException;

/**
* Manage Call with &#x60;callLeg&#x60;
*
* <p>This method is deprecated replaced by {@link #manageWithCallLeg(String, CallLeg,
* CallUpdateRequest)}
*
* @param callId The unique identifier of the call. This value is generated by the system.
* (required)
* @param callLeg Specifies which part of the call will be managed. This option is used only by
* the &#x60;PlayFiles&#x60; and &#x60;Say&#x60; instructions to indicate which channel the
* sound will be played on. Valid options are &#x60;caller&#x60;, &#x60;callee&#x60; or
* &#x60;both&#x60;. If not specified, the default value is
* &#x60;caller&#x60;.&lt;br&gt;&lt;Warning&gt;The &#x60;callLeg&#x60; identifier is ignored
* for calls that are part of a conference and calls initiated using the Callout
* API.&lt;/Warning&gt; (required)
* @param svamlControl (optional)
* @throws ApiException if fails to make API call
* @deprecated
*/
void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl)
throws ApiException;

/**
* Update a call in progress
*
* <p>This method is deprecated replaced by {@link #update(String, CallUpdateRequest)}
*
* @param callId The unique identifier of the call. This value is generated by the system.
* (required)
* @param svamlControl (optional)
* @throws ApiException if fails to make API call
* @deprecated
*/
void update(String callId, SvamlControl svamlControl) throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.sinch.sdk.core.http.URLPathUtils;
import com.sinch.sdk.core.models.ServerConfiguration;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallUpdateRequest;
import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import java.util.ArrayList;
Expand Down Expand Up @@ -108,6 +109,137 @@ private HttpRequest getRequestBuilder(String callId) throws ApiException {
localVarAuthNames);
}

@Override
public void manageWithCallLeg(String callId, CallLeg callLeg, CallUpdateRequest callUpdateRequest)
throws ApiException {

LOGGER.finest(
"[manageWithCallLeg]"
+ " "
+ "callId: "
+ callId
+ ", "
+ "callLeg: "
+ callLeg
+ ", "
+ "callUpdateRequest: "
+ callUpdateRequest);

HttpRequest httpRequest = manageWithCallLegRequestBuilder(callId, callLeg, callUpdateRequest);
HttpResponse response =
httpClient.invokeAPI(
this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

if (HttpStatus.isSuccessfulStatus(response.getCode())) {
return;
}
// fallback to default errors handling:
// all error cases definition are not required from specs: will try some "hardcoded" content
// parsing
throw ApiExceptionBuilder.build(
response.getMessage(),
response.getCode(),
mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {}));
}

private HttpRequest manageWithCallLegRequestBuilder(
String callId, CallLeg callLeg, CallUpdateRequest callUpdateRequest) throws ApiException {
// verify the required parameter 'callId' is set
if (callId == null) {
throw new ApiException(
400, "Missing the required parameter 'callId' when calling manageWithCallLeg");
}
// verify the required parameter 'callLeg' is set
if (callLeg == null) {
throw new ApiException(
400, "Missing the required parameter 'callLeg' when calling manageWithCallLeg");
}

String localVarPath =
"/calling/v1/calls/id/{callId}/leg/{callLeg}"
.replaceAll("\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString()))
.replaceAll(
"\\{" + "callLeg" + "\\}", URLPathUtils.encodePathSegment(callLeg.toString()));

List<URLParameter> localVarQueryParams = new ArrayList<>();

Map<String, String> localVarHeaderParams = new HashMap<>();

final Collection<String> localVarAccepts = Arrays.asList("application/json");

final Collection<String> localVarContentTypes = Arrays.asList("application/json");

final Collection<String> localVarAuthNames = Arrays.asList("Basic", "Signed");
final String serializedBody = mapper.serialize(localVarContentTypes, callUpdateRequest);

return new HttpRequest(
localVarPath,
HttpMethod.PATCH,
localVarQueryParams,
serializedBody,
localVarHeaderParams,
localVarAccepts,
localVarContentTypes,
localVarAuthNames);
}

@Override
public void update(String callId, CallUpdateRequest callUpdateRequest) throws ApiException {

LOGGER.finest(
"[update]" + " " + "callId: " + callId + ", " + "callUpdateRequest: " + callUpdateRequest);

HttpRequest httpRequest = updateRequestBuilder(callId, callUpdateRequest);
HttpResponse response =
httpClient.invokeAPI(
this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);

if (HttpStatus.isSuccessfulStatus(response.getCode())) {
return;
}
// fallback to default errors handling:
// all error cases definition are not required from specs: will try some "hardcoded" content
// parsing
throw ApiExceptionBuilder.build(
response.getMessage(),
response.getCode(),
mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {}));
}

private HttpRequest updateRequestBuilder(String callId, CallUpdateRequest callUpdateRequest)
throws ApiException {
// verify the required parameter 'callId' is set
if (callId == null) {
throw new ApiException(400, "Missing the required parameter 'callId' when calling update");
}

String localVarPath =
"/calling/v1/calls/id/{callId}"
.replaceAll(
"\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString()));

List<URLParameter> localVarQueryParams = new ArrayList<>();

Map<String, String> localVarHeaderParams = new HashMap<>();

final Collection<String> localVarAccepts = Arrays.asList();

final Collection<String> localVarContentTypes = Arrays.asList("application/json");

final Collection<String> localVarAuthNames = Arrays.asList("Basic", "Signed");
final String serializedBody = mapper.serialize(localVarContentTypes, callUpdateRequest);

return new HttpRequest(
localVarPath,
HttpMethod.PATCH,
localVarQueryParams,
serializedBody,
localVarHeaderParams,
localVarAccepts,
localVarContentTypes,
localVarAuthNames);
}

@Override
public void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl)
throws ApiException {
Expand Down
Loading
Loading