Skip to content

Commit

Permalink
Feat/DEVEXP-470: Voice V1 design (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier authored Oct 29, 2024
1 parent 972f108 commit 67bdad7
Show file tree
Hide file tree
Showing 393 changed files with 25,071 additions and 16,929 deletions.
21 changes: 21 additions & 0 deletions client/src/main/com/sinch/sdk/SinchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.sinch.sdk.models.VerificationContext;
import com.sinch.sdk.models.VoiceContext;
import com.sinch.sdk.models.VoiceRegion;
import com.sinch.sdk.models.adapters.DualToneMultiFrequencyMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
Expand Down Expand Up @@ -410,4 +411,24 @@ private String formatAuxiliaryFlag() {
}
return String.join(",", values);
}

static {
LocalLazyInit.init();
}

static final class LocalLazyInit {

private LocalLazyInit() {
DualToneMultiFrequencyMapper.initMapper();
}

public static LocalLazyInit init() {
return LocalLazyInit.LazyHolder.INSTANCE;
}

private static class LazyHolder {

public static final LocalLazyInit INSTANCE = new LocalLazyInit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import com.sinch.sdk.domains.voice.models.response.AssignedNumbers;
import com.sinch.sdk.models.E164PhoneNumber;

/** You can use the API to manage features of applications in your project. */
/**
* You can use the API to manage features of applications in your project.
*
* @since 1.0
*/
public interface ApplicationsService {

/**
Expand Down
9 changes: 9 additions & 0 deletions client/src/main/com/sinch/sdk/domains/voice/VoiceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
public interface VoiceService {

/**
* Voice Service V1
*
* @return V1 service instance for project
* @see <a href="https://developers.sinch.com/docs/voice">Documentation</a>
* @since 1.1
*/
com.sinch.sdk.domains.voice.api.v1.VoiceService v1();

/**
* Callouts Service instance
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,41 @@
package com.sinch.sdk.domains.voice.adapters;

import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.domains.voice.adapters.api.v1.ApplicationsApi;
import com.sinch.sdk.domains.voice.adapters.converters.ApplicationsDtoConverter;
import com.sinch.sdk.domains.voice.models.CallbackUrls;
import com.sinch.sdk.domains.voice.models.NumberInformation;
import com.sinch.sdk.domains.voice.models.requests.ApplicationsAssignNumbersRequestParameters;
import com.sinch.sdk.domains.voice.models.response.AssignedNumbers;
import com.sinch.sdk.models.E164PhoneNumber;
import com.sinch.sdk.models.VoiceContext;
import java.util.Map;

public class ApplicationsService implements com.sinch.sdk.domains.voice.ApplicationsService {

private final ApplicationsApi api;
private final com.sinch.sdk.domains.voice.api.v1.ApplicationsService v1;

public ApplicationsService(
VoiceContext context, HttpClient httpClient, Map<String, AuthManager> authManagers) {
this.api =
new ApplicationsApi(
httpClient,
context.getVoiceApplicationManagementServer(),
authManagers,
new HttpMapper());
}

protected ApplicationsApi getApi() {
return this.api;
public ApplicationsService(com.sinch.sdk.domains.voice.api.v1.ApplicationsService v1) {
this.v1 = v1;
}

public AssignedNumbers listNumbers() {

return ApplicationsDtoConverter.convert(getApi().configurationGetNumbers());
return ApplicationsDtoConverter.convert(v1.listNumbers());
}

public CallbackUrls getCallbackUrls(String applicationKey) {

return ApplicationsDtoConverter.convert(getApi().configurationGetCallbackURLs(applicationKey));
return ApplicationsDtoConverter.convert(v1.getCallbackUrls(applicationKey));
}

public void updateCallbackUrls(String applicationKey, CallbackUrls parameters) {
getApi()
.configurationUpdateCallbackURLs(
applicationKey, ApplicationsDtoConverter.convert(parameters));
v1.updateCallbackUrls(applicationKey, ApplicationsDtoConverter.convert(parameters));
}

public NumberInformation queryNumber(E164PhoneNumber number) {
return ApplicationsDtoConverter.convert(getApi().callingQueryNumber(number.stringValue()));
return ApplicationsDtoConverter.convert(v1.queryNumber(number.stringValue()));
}

public void assignNumbers(ApplicationsAssignNumbersRequestParameters parameters) {
getApi().configurationUpdateNumbers(ApplicationsDtoConverter.convert(parameters));
v1.assignNumbers(ApplicationsDtoConverter.convert(parameters));
}

public void unassignNumber(E164PhoneNumber phoneNumber, String applicationKey) {

getApi()
.configurationUnassignNumber(ApplicationsDtoConverter.convert(phoneNumber, applicationKey));
v1.unassignNumber(ApplicationsDtoConverter.convert(phoneNumber, applicationKey));
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
package com.sinch.sdk.domains.voice.adapters;

import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.domains.voice.adapters.api.v1.CalloutsApi;
import com.sinch.sdk.domains.voice.adapters.converters.CalloutsDtoConverter;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParameters;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersConference;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersCustom;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersTTS;
import com.sinch.sdk.models.VoiceContext;
import java.util.Map;
import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference;
import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestCustom;
import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestTTS;

public class CalloutsService implements com.sinch.sdk.domains.voice.CalloutsService {

private final CalloutsApi api;
private final com.sinch.sdk.domains.voice.api.v1.CalloutsService v1;

public CalloutsService(
VoiceContext context, HttpClient httpClient, Map<String, AuthManager> authManagers) {
this.api =
new CalloutsApi(httpClient, context.getVoiceServer(), authManagers, new HttpMapper());
}

protected CalloutsApi getApi() {
return this.api;
public CalloutsService(com.sinch.sdk.domains.voice.api.v1.CalloutsService v1) {
this.v1 = v1;
}

public String textToSpeech(CalloutRequestParametersTTS parameters) {

return call(parameters);
return v1.textToSpeech((CalloutRequestTTS) CalloutsDtoConverter.convert(parameters));
}

public String conference(CalloutRequestParametersConference parameters) {

return call(parameters);
return v1.conference((CalloutRequestConference) CalloutsDtoConverter.convert(parameters));
}

public String custom(CalloutRequestParametersCustom parameters) {

return call(parameters);
return v1.custom((CalloutRequestCustom) CalloutsDtoConverter.convert(parameters));
}

public String call(CalloutRequestParameters parameters) {

return CalloutsDtoConverter.convert(
getApi().callouts(CalloutsDtoConverter.convert(parameters)));
return v1.call(CalloutsDtoConverter.convert(parameters));
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
package com.sinch.sdk.domains.voice.adapters;

import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.domains.voice.adapters.api.v1.CallsApi;
import com.sinch.sdk.domains.voice.adapters.converters.CallsDtoConverter;
import com.sinch.sdk.domains.voice.adapters.converters.ControlDtoConverter;
import com.sinch.sdk.domains.voice.models.CallLegType;
import com.sinch.sdk.domains.voice.models.response.CallInformation;
import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
import com.sinch.sdk.models.VoiceContext;
import java.util.Map;
import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg;

public class CallsService implements com.sinch.sdk.domains.voice.CallsService {

private final CallsApi api;
private final com.sinch.sdk.domains.voice.api.v1.CallsService v1;

public CallsService(
VoiceContext context, HttpClient httpClient, Map<String, AuthManager> authManagers) {
this.api = new CallsApi(httpClient, context.getVoiceServer(), authManagers, new HttpMapper());
}

protected CallsApi getApi() {
return this.api;
public CallsService(com.sinch.sdk.domains.voice.api.v1.CallsService v1) {
this.v1 = v1;
}

public CallInformation get(String callId) {

return CallsDtoConverter.convert(getApi().callingGetCallResult(callId));
return CallsDtoConverter.convert(v1.get(callId));
}

public void update(String callId, SVAMLControl parameters) {
getApi().callingUpdateCall(callId, CallsDtoConverter.convert(parameters));
v1.update(callId, ControlDtoConverter.convertControl(parameters));
}

public void manageWithCallLeg(String callId, CallLegType callLeg, SVAMLControl parameters) {
getApi()
.callingManageCallWithCallLeg(
callId, callLeg.value(), CallsDtoConverter.convert(parameters));
v1.manageWithCallLeg(
callId, CallLeg.from(callLeg.value()), ControlDtoConverter.convertControl(parameters));
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
package com.sinch.sdk.domains.voice.adapters;

import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.core.http.HttpMapper;
import com.sinch.sdk.domains.voice.adapters.api.v1.ConferencesApi;
import com.sinch.sdk.domains.voice.adapters.converters.CalloutsDtoConverter;
import com.sinch.sdk.domains.voice.adapters.converters.ConferencesDtoConverter;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersConference;
import com.sinch.sdk.domains.voice.models.requests.ConferenceManageParticipantRequestParameters;
import com.sinch.sdk.domains.voice.models.response.ConferenceParticipant;
import com.sinch.sdk.models.VoiceContext;
import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference;
import java.util.Collection;
import java.util.Map;

public class ConferencesService implements com.sinch.sdk.domains.voice.ConferencesService {

private final ConferencesApi api;
private final com.sinch.sdk.domains.voice.api.v1.ConferencesService v1;

public ConferencesService(
VoiceContext context, HttpClient httpClient, Map<String, AuthManager> authManagers) {
this.api =
new ConferencesApi(httpClient, context.getVoiceServer(), authManagers, new HttpMapper());
}

protected ConferencesApi getApi() {
return this.api;
public ConferencesService(com.sinch.sdk.domains.voice.api.v1.ConferencesService v1) {
this.v1 = v1;
}

public String call(CalloutRequestParametersConference parameters) {
return CalloutsDtoConverter.convert(
getApi().callouts(CalloutsDtoConverter.convert(parameters)));
return v1.call((CalloutRequestConference) CalloutsDtoConverter.convert(parameters));
}

public Collection<ConferenceParticipant> get(String conferenceId) {
return ConferencesDtoConverter.convert(getApi().callingGetConferenceInfo(conferenceId));
return ConferencesDtoConverter.convert(v1.get(conferenceId));
}

public void kickAll(String conferenceId) {
getApi().callingKickConferenceAll(conferenceId);
v1.kickAll(conferenceId);
}

public void kickParticipant(String conferenceId, String callId) {
getApi().callingKickConferenceParticipant(callId, conferenceId);
v1.kickParticipant(conferenceId, callId);
}

public void manageParticipant(
String conferenceId, String callId, ConferenceManageParticipantRequestParameters parameters) {
getApi()
.callingManageConferenceParticipant(
callId, conferenceId, ConferencesDtoConverter.convert(parameters));
v1.manageParticipant(conferenceId, callId, ConferencesDtoConverter.convert(parameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class VoiceService implements com.sinch.sdk.domains.voice.VoiceService {
private Map<String, AuthManager> clientAuthManagers;
private Map<String, AuthManager> webhooksAuthManagers;

private final com.sinch.sdk.domains.voice.api.v1.VoiceService v1;

public VoiceService(
ApplicationCredentials credentials, VoiceContext context, HttpClient httpClient) {

Expand All @@ -52,6 +54,10 @@ public VoiceService(
this.context = context;
this.httpClient = httpClient;
setApplicationCredentials(credentials);

this.v1 =
new com.sinch.sdk.domains.voice.api.v1.adapters.VoiceService(
credentials, context, httpClient);
}

private void setApplicationCredentials(ApplicationCredentials credentials) {
Expand All @@ -75,9 +81,7 @@ private void setApplicationCredentials(ApplicationCredentials credentials) {
public CalloutsService callouts() {
if (null == this.callouts) {
checkCredentials();
this.callouts =
new com.sinch.sdk.domains.voice.adapters.CalloutsService(
context, httpClient, clientAuthManagers);
this.callouts = new com.sinch.sdk.domains.voice.adapters.CalloutsService(v1().callouts());
}
return this.callouts;
}
Expand All @@ -86,18 +90,15 @@ public ConferencesService conferences() {
if (null == this.conferences) {
checkCredentials();
this.conferences =
new com.sinch.sdk.domains.voice.adapters.ConferencesService(
context, httpClient, clientAuthManagers);
new com.sinch.sdk.domains.voice.adapters.ConferencesService(v1.conferences());
}
return this.conferences;
}

public CallsService calls() {
if (null == this.calls) {
checkCredentials();
this.calls =
new com.sinch.sdk.domains.voice.adapters.CallsService(
context, httpClient, clientAuthManagers);
this.calls = new com.sinch.sdk.domains.voice.adapters.CallsService(v1.calls());
}
return this.calls;
}
Expand All @@ -106,21 +107,23 @@ public ApplicationsService applications() {
if (null == this.applications) {
checkCredentials();
this.applications =
new com.sinch.sdk.domains.voice.adapters.ApplicationsService(
context, httpClient, clientAuthManagers);
new com.sinch.sdk.domains.voice.adapters.ApplicationsService(v1.applications());
}
return this.applications;
}

public WebHooksService webhooks() {
checkCredentials();
if (null == this.webhooks) {
this.webhooks =
new com.sinch.sdk.domains.voice.adapters.WebHooksService(webhooksAuthManagers);
this.webhooks = new com.sinch.sdk.domains.voice.adapters.WebHooksService(v1.webhooks());
}
return this.webhooks;
}

public com.sinch.sdk.domains.voice.api.v1.VoiceService v1() {
return this.v1;
}

private void checkCredentials() throws ApiAuthException {
if (null == clientAuthManagers || clientAuthManagers.isEmpty()) {
throw new ApiAuthException(
Expand Down
Loading

0 comments on commit 67bdad7

Please sign in to comment.