diff --git a/MIGRATION-GUIDE.md b/MIGRATION-GUIDE.md index 5cd3343cf..3cff52eed 100644 --- a/MIGRATION-GUIDE.md +++ b/MIGRATION-GUIDE.md @@ -241,6 +241,20 @@ Use the new versioned API under `sms().v1()` to get access to [SMSService](https ### [`Voice`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/package-summary.html) +- `Applications.listNumbers()` is returning a `[OwnedNumbersListResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/application/response/OwnedNumbersListResponse.html)` instead of a list of `OwnedNumbersResponse`. The new response still contains the list of assigned numbers but support the pagination of the results by iterator. + +#### Replacement APIs + +Use the new versioned API under `voice().v1()` to get access to [VoiceService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/VoiceService.html): [`sinchClient.voice().v1()`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0./com/sinch/sdk/domains/voice/VoiceService.html#v1()) + +| Old interface | New Equivalent in `voice().v1()` | +|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------| +| applications() | [v1().applications()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.html) | +| callouts() | [v1().callouts()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/CalloutsService.html) | +| calls() | [v1().calls()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/CallsService.html) | +| conferences() | [v1().conferences()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/ConferencesService.html) | +| webhooks() | [v1().webhooks()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/WebHooksService.html) | + #### Replacement models | Old const | New const | @@ -261,17 +275,17 @@ Use the new versioned API under `sms().v1()` to get access to [SMSService](https | models/DestinationUser | [com.sinch.sdk.domains.voice.models.v1.destination.DestinationMxp](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/destination/DestinationMxp.html) | ##### Applications -| Old class | New class | -|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| models/ApplicationAssignedNumber | [com.sinch.sdk.domains.voice.models.v1.applications.response](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumberInformation.html) | -| models/response/AssignedNumbers | [com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponse.html) | -| models/CallbackUrls | [com.sinch.sdk.domains.voice.models.v1.applications.Callbacks](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/Callbacks.html) | -| models/ApplicationURL | [com.sinch.sdk.domains.voice.models.v1.applications.CallbacksUrl](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/CallbacksUrl.html) | -| models/NumberInformation | [com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberInformation](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/QueryNumberInformation.html) | -| models/response/QueryNumber | [com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/QueryNumberResponse.html) | -| models/requests/ApplicationsAssignNumbersRequestParameters | [com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/request/UpdateNumbersRequest.html) | -| models/NumberType | N/A | -| models/CapabilityType | [com.sinch.sdk.domains.voice.models.v1.applications.Capability](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/Capability.html) | +| Old class | New class | +|------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| models/ApplicationAssignedNumber | [com.sinch.sdk.domains.voice.models.v1.applications.response](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumberInformation.html) | +| models/response/AssignedNumbers | [com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersListResponse.html) | +| models/CallbackUrls | [com.sinch.sdk.domains.voice.models.v1.applications.Callbacks](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/Callbacks.html) | +| models/ApplicationURL | [com.sinch.sdk.domains.voice.models.v1.applications.CallbacksUrl](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/CallbacksUrl.html) | +| models/NumberInformation | [com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberInformation](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/QueryNumberInformation.html) | +| models/response/QueryNumber | [com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/response/QueryNumberResponse.html) | +| models/requests/ApplicationsAssignNumbersRequestParameters | [com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/request/UpdateNumbersRequest.html) | +| models/NumberType | N/A | +| models/CapabilityType | [com.sinch.sdk.domains.voice.models.v1.applications.Capability](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/applications/Capability.html) | ##### Callouts | Old class | New class | @@ -353,21 +367,22 @@ Use the new versioned API under `sms().v1()` to get access to [SMSService](https | models/webhooks/PromptInputEvent | [com.sinch.sdk.domains.voice.models.v1.webhooks.PromptInputEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/webhooks/PromptInputEvent.html) | | models/webhooks/WebhooksEvent | [com.sinch.sdk.domains.voice.models.v1.webhooks.VoiceWebhookEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/models/v1/webhooks/VoiceWebhookEvent.html) | +### [`Verification`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/package-summary.html) #### Replacement APIs -Use the new versioned API under `voice().v1()` to get access to [VoiceService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/VoiceService.html): [`sinchClient.voice().v1()`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0./com/sinch/sdk/domains/voice/VoiceService.html#v1()) - -| Old interface | New Equivalent in `voice().v1()` | -|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------| -| applications() | [v1().applications()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.html) | -| callouts() | [v1().callouts()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/CalloutsService.html) | -| calls() | [v1().calls()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/CallsService.html) | -| conferences() | [v1().conferences()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/ConferencesService.html) | -| webhooks() | [v1().webhooks()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/voice/api/v1/WebHooksService.html) | - +Use the new versioned API under `verification().v1()` to get access to [VerificationService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationService.html): [`sinchClient.verification().v1()`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/VerificationService.html#v1()) -### [`Verification`](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/package-summary.html) +| Old interface | New Equivalent in `verification().v1()` | +|---------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| verifications() `start` related APIs | [v1().verificationStart()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.html) | +| verifications() `report` related APIs | [v1().verificationReport()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html) | +| verificationStatus() | [v1().verificationStatus()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.html) | +| webhooks() | [v1().webhooks()](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/WebHooksService.html) | +| VerificationStartService | [VerificationsStartService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationsStartService.html) | +| VerificationReportService | [VerificationsReportService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationsReportService.html) | +| VerificationStatusService | [VerificationsStatusService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/VerificationsStatusService.html) | +| WebHooksService | [WebhooksService](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/2.0.0/com/sinch/sdk/domains/verification/api/v1/WebhookService.html) | #### Replacement APIs diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java deleted file mode 100644 index 356604b3b..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1; - -import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse; - -/** - * You can use the API to manage features of applications in your project. - * - * @since 1.4 - */ -public interface ApplicationsService { - - /** - * Get information about your numbers. - * - *

It returns a list of numbers that you own, as well as their capability (Voice or SMS). For - * the ones that are assigned to an app, it returns the application key of the app. - * - * @return Your numbers - * @since 1.4 - */ - OwnedNumbersResponse listNumbers(); - - /** - * Returns any callback URLs configured for the specified application - * - * @param applicationKey The unique identifying key of the application - * @return Assigned callback to application - * @since 1.4 - */ - Callbacks getCallbackUrls(String applicationKey); - - /** - * Update the configured callback URLs for the specified application. - * - * @param applicationKey The unique identifying key of the application - * @param parameters Callbacks settings - * @since 1.4 - */ - void updateCallbackUrls(String applicationKey, Callbacks parameters); - - /** - * Returns information about the requested number - * - * @param number The phone number you want to query - * @return Number information - */ - QueryNumberResponse queryNumber(String number); - - /** - * Update or assign a list of numbers to an application. - * - * @param parameters Request parameters - * @since 1.4 - */ - void assignNumbers(UpdateNumbersRequest parameters); - - /** - * Un-assign a number from an application. - * - * @param parameters Request parameters - * @since 1.4 - */ - public void unassignNumber(UnAssignNumberRequest parameters); -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java deleted file mode 100644 index 70cd10e55..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1; - -import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg; -import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation; -import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl; - -/** - * Using the Calls service, you can manage on-going calls or retrieve information about a call. - * - * @see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Calls - * @since 1.4 - */ -public interface CallsService { - - /** - * You can retrieve information about an ongoing or completed call using a call ID. You can find - * the call ID of an ongoing call by viewing the response object from a callout request. You can - * find the call ID of a completed call by looking at your call logs in your Sinch Dashboard. - * - *

Note: You can only use this method for calls that terminate to PSTN or SIP networks from an - * In-app call. - * - * @param callId The unique identifier of the call. This value is generated by the system - * @return Information about the call - * @since 1.4 - */ - CallInformation get(String callId); - - /** - * This method is used to manage ongoing, connected calls. This method uses SVAML in the request - * body to perform various tasks related to the call. For more information about SVAML, see the - * Callback API documentation. - * - *

Note: You can only use this method for calls that terminate to PSTN or SIP networks from an - * In-app call. - * - * @param callId The unique identifier of the call. This value is generated by the system - * @param parameters Tasks to be used related to this call - * @since 1.4 - */ - void update(String callId, SvamlControl parameters); - - /** - * This method is used to manage ongoing, connected calls. This method is only used when using the - * PlayFiles and Say instructions in the request body. This method uses SVAML in the request body - * to perform various tasks related to the call. For more information about SVAML, see the - * Callback API documentation. - * - *

Note: You can only use this method for calls that terminate to PSTN or SIP networks from an - * In-app call. - * - * @param callId The unique identifier of the call. This value is generated by the system - * @param parameters Tasks to be used related to this call - * @since 1.4 - */ - void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl parameters); -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java deleted file mode 100644 index 4d30b0821..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1; - -import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference; -import com.sinch.sdk.domains.voice.models.v1.conferences.request.ManageConferenceParticipantRequest; -import com.sinch.sdk.domains.voice.models.v1.conferences.response.GetConferenceInfoResponse; - -/** - * Using the Conferences endpoint, you can perform tasks like retrieving information about an - * on-going conference, muting or unmuting participants, or removing participants from a conference. - * - * @see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Conferences - * @since 1.4 - */ -public interface ConferencesService { - - /** - * Calls a phone number or a user to join a conference. When the call is answered, it's connected - * to a conference room. - * - * @param parameters Conference parameters - * @return The returned call identifier (callId) - * @since 1.4 - */ - String call(CalloutRequestConference parameters); - - /** - * Returns information about a conference that matches the provided conference ID. - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * @return The list of participants joined the conference - * @since 1.4 - */ - GetConferenceInfoResponse get(String conferenceId); - - /** - * Removes all participants from a conference - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * @since 1.4 - */ - void kickAll(String conferenceId); - - /** - * Remove a specified conference participant from a specified conference - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * @param callId The unique identifier of the call. This value is generated by the system - * @since 1.4 - */ - void kickParticipant(String conferenceId, String callId); - - /** - * Manages conference participant in a specified conference: - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * @param callId The unique identifier of the call. This value is generated by the system - * @param parameters Parameters to manage participant - * @since 1.4 - */ - void manageParticipant( - String conferenceId, String callId, ManageConferenceParticipantRequest parameters); -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsService.java deleted file mode 100644 index 13279b3d1..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsService.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1.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.api.v1.internal.ApplicationsApi; -import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse; -import com.sinch.sdk.models.VoiceContext; -import java.util.Map; - -public class ApplicationsService implements com.sinch.sdk.domains.voice.api.v1.ApplicationsService { - - private final ApplicationsApi api; - - public ApplicationsService( - VoiceContext context, HttpClient httpClient, Map authManagers) { - this.api = - new ApplicationsApi( - httpClient, - context.getVoiceApplicationManagementServer(), - authManagers, - HttpMapper.getInstance()); - } - - protected ApplicationsApi getApi() { - return this.api; - } - - public OwnedNumbersResponse listNumbers() { - return getApi().configurationGetNumbers(); - } - - public Callbacks getCallbackUrls(String applicationKey) { - return getApi().configurationGetCallbackURLs(applicationKey); - } - - public void updateCallbackUrls(String applicationKey, Callbacks parameters) { - - getApi().configurationUpdateCallbackURLs(applicationKey, parameters); - } - - public QueryNumberResponse queryNumber(String number) { - return getApi().callingQueryNumber(number); - } - - public void assignNumbers(UpdateNumbersRequest parameters) { - getApi().configurationUpdateNumbers(parameters); - } - - public void unassignNumber(UnAssignNumberRequest parameters) { - getApi().configurationUnassignNumber(parameters); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsService.java deleted file mode 100644 index 0608e6555..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsService.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1.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.api.v1.adapters.mapper.CalloutRequestCustomMapper; -import com.sinch.sdk.domains.voice.api.v1.internal.CalloutsApi; -import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequest; -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; -import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternalImpl; -import com.sinch.sdk.domains.voice.models.v1.callouts.response.CalloutResponse; -import com.sinch.sdk.models.VoiceContext; -import java.util.Map; - -public class CalloutsService implements com.sinch.sdk.domains.voice.api.v1.CalloutsService { - - private final CalloutsApi api; - - static { - LocalLazyInit.init(); - } - - public CalloutsService( - VoiceContext context, HttpClient httpClient, Map authManagers) { - this.api = - new CalloutsApi( - httpClient, context.getVoiceServer(), authManagers, HttpMapper.getInstance()); - } - - protected CalloutsApi getApi() { - return this.api; - } - - public String textToSpeech(CalloutRequestTTS parameters) { - - return call(parameters); - } - - public String conference(CalloutRequestConference parameters) { - - return call(parameters); - } - - public String custom(CalloutRequestCustom parameters) { - - return call(parameters); - } - - public String call(CalloutRequest parameters) { - - CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); - request.setActualInstance(parameters); - CalloutResponse response = getApi().callouts(request); - if (null == response) { - return null; - } - return response.getCallId(); - } - - public static final class LocalLazyInit { - - private LocalLazyInit() { - CalloutRequestCustomMapper.initMapper(); - } - - public static LocalLazyInit init() { - return LazyHolder.INSTANCE; - } - - private static class LazyHolder { - - public static final LocalLazyInit INSTANCE = new LocalLazyInit(); - } - } -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsService.java deleted file mode 100644 index 85bd56b55..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsService.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1.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.api.v1.adapters.mapper.CallInformationMapper; -import com.sinch.sdk.domains.voice.api.v1.internal.CallsApi; -import com.sinch.sdk.domains.voice.models.v1.calls.request.CallLeg; -import com.sinch.sdk.domains.voice.models.v1.calls.response.CallInformation; -import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl; -import com.sinch.sdk.models.VoiceContext; -import java.util.Map; - -public class CallsService implements com.sinch.sdk.domains.voice.api.v1.CallsService { - - private final CallsApi api; - - static { - LocalLazyInit.init(); - } - - public CallsService( - VoiceContext context, HttpClient httpClient, Map authManagers) { - this.api = - new CallsApi(httpClient, context.getVoiceServer(), authManagers, HttpMapper.getInstance()); - } - - protected CallsApi getApi() { - return this.api; - } - - public CallInformation get(String callId) { - return getApi().callingGetCallResult(callId); - } - - public void update(String callId, SvamlControl parameters) { - getApi().callingUpdateCall(callId, parameters); - } - - public void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl parameters) { - getApi().callingManageCallWithCallLeg(callId, callLeg.value(), parameters); - } - - public static final class LocalLazyInit { - - private LocalLazyInit() { - CallInformationMapper.initMapper(); - } - - public static CallsService.LocalLazyInit init() { - return CallsService.LocalLazyInit.LazyHolder.INSTANCE; - } - - private static class LazyHolder { - - public static final CallsService.LocalLazyInit INSTANCE = new LocalLazyInit(); - } - } -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesService.java deleted file mode 100644 index afd7e6dc9..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1.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.api.v1.internal.ConferencesApi; -import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference; -import com.sinch.sdk.domains.voice.models.v1.conferences.request.ManageConferenceParticipantRequest; -import com.sinch.sdk.domains.voice.models.v1.conferences.response.GetConferenceInfoResponse; -import com.sinch.sdk.models.VoiceContext; -import java.util.Map; - -public class ConferencesService implements com.sinch.sdk.domains.voice.api.v1.ConferencesService { - - private final ConferencesApi api; - private final CalloutsService calloutsService; - - public ConferencesService( - VoiceContext context, - HttpClient httpClient, - Map authManagers, - CalloutsService calloutsService) { - this.api = - new ConferencesApi( - httpClient, context.getVoiceServer(), authManagers, HttpMapper.getInstance()); - this.calloutsService = calloutsService; - } - - protected ConferencesApi getApi() { - return this.api; - } - - public String call(CalloutRequestConference parameters) { - return calloutsService.conference(parameters); - } - - public GetConferenceInfoResponse get(String conferenceId) { - return getApi().callingGetConferenceInfo(conferenceId); - } - - public void kickAll(String conferenceId) { - getApi().callingKickConferenceAll(conferenceId); - } - - public void kickParticipant(String conferenceId, String callId) { - getApi().callingKickConferenceParticipant(callId, conferenceId); - } - - public void manageParticipant( - String conferenceId, String callId, ManageConferenceParticipantRequest parameters) { - getApi().callingManageConferenceParticipant(callId, conferenceId, parameters); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/VoiceService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/VoiceService.java index e7a14c233..da53004c0 100644 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/VoiceService.java +++ b/client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/VoiceService.java @@ -4,8 +4,14 @@ import com.sinch.sdk.auth.adapters.BasicAuthManager; 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.core.utils.StringUtil; -import com.sinch.sdk.domains.voice.api.v1.adapters.CallsService.LocalLazyInit; +import com.sinch.sdk.domains.voice.api.v1.ApplicationsService; +import com.sinch.sdk.domains.voice.api.v1.CalloutsService; +import com.sinch.sdk.domains.voice.api.v1.CallsService; +import com.sinch.sdk.domains.voice.api.v1.ConferencesService; +import com.sinch.sdk.domains.voice.api.v1.adapters.mapper.CallInformationMapper; +import com.sinch.sdk.domains.voice.api.v1.adapters.mapper.CalloutRequestCustomMapper; import com.sinch.sdk.domains.voice.api.v1.adapters.mapper.DestinationMapper; import com.sinch.sdk.models.ApplicationCredentials; import com.sinch.sdk.models.VoiceContext; @@ -71,7 +77,12 @@ private void createAuthManagers(ApplicationCredentials credentials) { public CalloutsService callouts() { if (null == this.callouts) { instanceLazyInit(); - this.callouts = new CalloutsService(context, httpClientSupplier.get(), clientAuthManagers); + this.callouts = + new CalloutsServiceImpl( + httpClientSupplier.get(), + context.getVoiceServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.callouts; } @@ -80,8 +91,11 @@ public ConferencesService conferences() { if (null == this.conferences) { instanceLazyInit(); this.conferences = - new ConferencesService( - context, httpClientSupplier.get(), clientAuthManagers, this.callouts()); + new ConferencesServiceImpl( + httpClientSupplier.get(), + context.getVoiceServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.conferences; } @@ -89,7 +103,12 @@ public ConferencesService conferences() { public CallsService calls() { if (null == this.calls) { instanceLazyInit(); - this.calls = new CallsService(context, httpClientSupplier.get(), clientAuthManagers); + this.calls = + new CallsServiceImpl( + httpClientSupplier.get(), + context.getVoiceServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.calls; } @@ -98,8 +117,11 @@ public ApplicationsService applications() { if (null == this.applications) { instanceLazyInit(); this.applications = - new com.sinch.sdk.domains.voice.api.v1.adapters.ApplicationsService( - context, httpClientSupplier.get(), clientAuthManagers); + new ApplicationsServiceImpl( + httpClientSupplier.get(), + context.getVoiceApplicationManagementServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.applications; } @@ -142,7 +164,10 @@ private void instanceLazyInit() { public static final class LocalLazyInit { private LocalLazyInit() { + DestinationMapper.initMapper(); + CallInformationMapper.initMapper(); + CalloutRequestCustomMapper.initMapper(); } public static LocalLazyInit init() { diff --git a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceTest.java index 86365d09d..63caa41d1 100644 --- a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceTest.java @@ -1,74 +1,138 @@ package com.sinch.sdk.domains.voice.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.voice.api.v1.internal.ApplicationsApi; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.voice.adapters.VoiceBaseTest; +import com.sinch.sdk.domains.voice.api.v1.ApplicationsService; import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequestTest; import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateCallbackUrlsRequestTest; -import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequestTest; import com.sinch.sdk.domains.voice.models.v1.applications.response.GetCallbackUrlsResponseTest; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse; import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponseTest; -import com.sinch.sdk.models.VoiceContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; @TestWithResources -public class ApplicationsServiceTest extends BaseTest { +public class ApplicationsServiceTest extends VoiceBaseTest { - @Mock ApplicationsApi api; - @Mock VoiceContext context; - @Mock HttpClient httpClient; - @Mock Map authManagers; + @GivenTextResource("/domains/voice/v1/applications/response/OwnedNumbersResponseDto.json") + String ownedNumbersResponseDto; + + @GivenTextResource("/domains/voice/v1/applications/response/GetCallbackUrlsResponseDto.json") + String getCallbackUrlsResponseDto; + + @GivenTextResource("/domains/voice/v1/applications/request/UpdateCallbackUrlsRequestDto.json") + String updateCallbackUrlsRequestDto; + + @GivenTextResource("/domains/voice/v1/applications/request/UpdateNumbersRequestDto.json") + String updateNumbersRequestDto; - @Captor ArgumentCaptor applicationKeyCaptor; - @Captor ArgumentCaptor callbacksDtoCaptor; - @Captor ArgumentCaptor updateNumbersDtoCaptor; - @Captor ArgumentCaptor unassignNumbersDtoCaptor; + @GivenTextResource("/domains/voice/v1/applications/request/UnAssignNumberRequestDto.json") + String unAssignNumberRequestDto; - com.sinch.sdk.domains.voice.api.v1.adapters.ApplicationsService service; + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Signed"); + + @Mock ServerConfiguration serverConfiguration; + @Mock HttpClient httpClient; + @Mock Map authManagers; + ApplicationsService service; @BeforeEach public void initMocks() { - service = spy(new ApplicationsService(context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new ApplicationsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void getNumbers() throws ApiException { - when(api.configurationGetNumbers()).thenReturn(OwnedNumbersResponseTest.expected); - - OwnedNumbersResponse response = service.listNumbers(); - - TestHelpers.recursiveEquals(response, OwnedNumbersResponseTest.expected); + HttpRequest httpRequest = + new HttpRequest( + "/v1/configuration/numbers", + HttpMethod.GET, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), ownedNumbersResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + OwnedNumbersListResponse response = service.listNumbers(); + + Iterator iterator = response.iterator(); + + OwnedNumbersListResponse expectedListResponse = + new OwnedNumbersListResponse( + new Page<>(null, OwnedNumbersResponseTest.expected.getNumbers(), null)); + Iterator expectedIterator = expectedListResponse.iterator(); + + while (iterator.hasNext()) { + OwnedNumberInformation item = iterator.next(); + OwnedNumberInformation expectedItem = expectedIterator.next(); + TestHelpers.recursiveEquals(item, expectedItem); + } + Assertions.assertThat(expectedIterator.hasNext()).isEqualTo(false); } @Test void getCallbackUrls() throws ApiException { - when(api.configurationGetCallbackURLs(eq("app id"))) - .thenReturn(GetCallbackUrlsResponseTest.expected); - - Callbacks response = service.getCallbackUrls("app id"); + HttpRequest httpRequest = + new HttpRequest( + "/v1/configuration/callbacks/applications/" + URLPathUtils.encodePathSegment("app/id"), + HttpMethod.GET, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), getCallbackUrlsResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + Callbacks response = service.getCallbackUrls("app/id"); TestHelpers.recursiveEquals(response, GetCallbackUrlsResponseTest.expected); } @@ -76,38 +140,72 @@ void getCallbackUrls() throws ApiException { @Test void updateCallbackUrls() { - service.updateCallbackUrls("app key", UpdateCallbackUrlsRequestTest.expected); - - verify(api) - .configurationUpdateCallbackURLs( - applicationKeyCaptor.capture(), callbacksDtoCaptor.capture()); - - String appKey = applicationKeyCaptor.getValue(); - Assertions.assertThat(appKey).isEqualTo("app key"); - - Callbacks body = callbacksDtoCaptor.getValue(); - TestHelpers.recursiveEquals(body, UpdateCallbackUrlsRequestTest.expected); + HttpRequest httpRequest = + new HttpRequest( + "/v1/configuration/callbacks/applications/" + URLPathUtils.encodePathSegment("app/key"), + HttpMethod.POST, + Collections.emptyList(), + updateCallbackUrlsRequestDto, + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(204, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + service.updateCallbackUrls("app/key", UpdateCallbackUrlsRequestTest.expected); } @Test void updateNumbers() { - service.assignNumbers(UpdateNumbersRequestTest.updateNumbersDto); - - verify(api).configurationUpdateNumbers(updateNumbersDtoCaptor.capture()); + HttpRequest httpRequest = + new HttpRequest( + "/v1/configuration/numbers", + HttpMethod.POST, + Collections.emptyList(), + updateNumbersRequestDto, + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(204, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); - UpdateNumbersRequest body = updateNumbersDtoCaptor.getValue(); - TestHelpers.recursiveEquals(body, UpdateNumbersRequestTest.updateNumbersDto); + service.assignNumbers(UpdateNumbersRequestTest.updateNumbersDto); } @Test void unassignNumber() { - service.unassignNumber(UnAssignNumberRequestTest.unAssignNumberDto); + HttpRequest httpRequest = + new HttpRequest( + "/v1/configuration/numbers", + HttpMethod.DELETE, + Collections.emptyList(), + unAssignNumberRequestDto, + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(204, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); - verify(api).configurationUnassignNumber(unassignNumbersDtoCaptor.capture()); - - UnAssignNumberRequest body = unassignNumbersDtoCaptor.getValue(); - TestHelpers.recursiveEquals(body, UnAssignNumberRequestTest.unAssignNumberDto); + service.unassignNumber(UnAssignNumberRequestTest.unAssignNumberDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceTest.java index f94b3a37b..ae2c6ac50 100644 --- a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceTest.java @@ -1,95 +1,172 @@ package com.sinch.sdk.domains.voice.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.voice.api.v1.internal.CalloutsApi; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.voice.adapters.VoiceBaseTest; +import com.sinch.sdk.domains.voice.api.v1.CalloutsService; import com.sinch.sdk.domains.voice.models.v1.callouts.CalloutRequestDtoTest; import com.sinch.sdk.domains.voice.models.v1.callouts.CalloutResponseDtoTest; -import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternalImpl; -import com.sinch.sdk.models.VoiceContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @TestWithResources -public class CalloutsServiceTest extends BaseTest { +public class CalloutsServiceTest extends VoiceBaseTest { - @Mock CalloutsApi api; - @Mock VoiceContext context; + @GivenTextResource("/domains/voice/v1/callouts/CalloutResponseDto.json") + String calloutResponseDto; + + @GivenTextResource("/domains/voice/v1/callouts/CalloutRequestConferenceDto.json") + String calloutRequestConferenceDto; + + @GivenTextResource("/domains/voice/v1/callouts/CalloutRequestTtsDto.json") + String calloutRequestTtsDto; + + @GivenTextResource("/domains/voice/v1/callouts/CalloutRequestCustomDto.json") + String calloutRequestCustomDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Signed"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - CalloutsService service; @BeforeEach public void initMocks() { - service = spy(new CalloutsService(context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new CalloutsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void conference() throws ApiException { - CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); - request.setActualInstance(CalloutRequestDtoTest.conferenceRequestCalloutDto); - - when(api.callouts(eq(request))).thenReturn(CalloutResponseDtoTest.expectedCalloutResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/callouts", + HttpMethod.POST, + Collections.emptyList(), + calloutRequestConferenceDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), calloutResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); String response = service.conference(CalloutRequestDtoTest.conferenceRequestCalloutDto); - Assertions.assertThat(response) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); + TestHelpers.recursiveEquals( + response, CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); } @Test void textToSpeech() throws ApiException { - CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); - request.setActualInstance(CalloutRequestDtoTest.ttsRequestDto); - - when(api.callouts(eq(request))).thenReturn(CalloutResponseDtoTest.expectedCalloutResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/callouts", + HttpMethod.POST, + Collections.emptyList(), + calloutRequestTtsDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), calloutResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); String response = service.textToSpeech(CalloutRequestDtoTest.ttsRequestDto); - Assertions.assertThat(response) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); + TestHelpers.recursiveEquals( + response, CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); } @Test void custom() throws ApiException { - CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); - request.setActualInstance(CalloutRequestDtoTest.customRequestDto); - - when(api.callouts(eq(request))).thenReturn(CalloutResponseDtoTest.expectedCalloutResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/callouts", + HttpMethod.POST, + Collections.emptyList(), + calloutRequestCustomDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), calloutResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); String response = service.custom(CalloutRequestDtoTest.customRequestDto); - Assertions.assertThat(response) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); + TestHelpers.recursiveEquals( + response, CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); } @Test void call() throws ApiException { - CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); - request.setActualInstance(CalloutRequestDtoTest.customRequestDto); - - when(api.callouts(eq(request))).thenReturn(CalloutResponseDtoTest.expectedCalloutResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/callouts", + HttpMethod.POST, + Collections.emptyList(), + calloutRequestCustomDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), calloutResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); String response = service.call(CalloutRequestDtoTest.customRequestDto); - Assertions.assertThat(response) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); + TestHelpers.recursiveEquals( + response, CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceTest.java index 26789b984..3d158a320 100644 --- a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceTest.java @@ -1,56 +1,84 @@ package com.sinch.sdk.domains.voice.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.voice.api.v1.internal.CallsApi; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +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.response.CallInformation; -import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl; import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControlTest; -import com.sinch.sdk.models.VoiceContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; @TestWithResources public class CallsServiceTest extends BaseTest { - @Mock CallsApi api; - @Mock VoiceContext context; + @GivenTextResource("/domains/voice/v1/calls/GetCallInformationResponseDto.json") + String getCallInformationResponseDto; + + @GivenTextResource("/domains/voice/v1/svaml/SvamlControlDto.json") + String svamlControlDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Signed"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - - @Captor ArgumentCaptor callIdCaptor; - @Captor ArgumentCaptor callLegCaptor; - @Captor ArgumentCaptor updateParametersCaptor; CallsService service; @BeforeEach public void initMocks() { - service = spy(new CallsService(context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new CallsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void get() throws ApiException { - when(api.callingGetCallResult( - eq(CallInformationTest.expectedCallsGetInformationResponseDto.getCallId()))) - .thenReturn(CallInformationTest.expectedCallsGetInformationResponseDto); + + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/calls/id/" + + URLPathUtils.encodePathSegment( + CallInformationTest.expectedCallsGetInformationResponseDto.getCallId()), + HttpMethod.GET, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), getCallInformationResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); CallInformation response = service.get(CallInformationTest.expectedCallsGetInformationResponseDto.getCallId()); @@ -61,33 +89,49 @@ void get() throws ApiException { @Test void update() throws ApiException { - service.update("call id", SvamlControlTest.expectedSvamlControl); - - verify(api).callingUpdateCall(callIdCaptor.capture(), updateParametersCaptor.capture()); - String callId = callIdCaptor.getValue(); - Assertions.assertThat(callId).isEqualTo("call id"); - - SvamlControl body = updateParametersCaptor.getValue(); - TestHelpers.recursiveEquals(body, SvamlControlTest.expectedSvamlControl); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/calls/id/" + URLPathUtils.encodePathSegment("call/id"), + HttpMethod.PATCH, + Collections.emptyList(), + svamlControlDto, + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(204, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + service.update("call/id", SvamlControlTest.expectedSvamlControl); } @Test void manageWithCallLeg() throws ApiException { - service.manageWithCallLeg("call id", CallLeg.BOTH, SvamlControlTest.expectedSvamlControl); - - verify(api) - .callingManageCallWithCallLeg( - callIdCaptor.capture(), callLegCaptor.capture(), updateParametersCaptor.capture()); - - String callId = callIdCaptor.getValue(); - Assertions.assertThat(callId).isEqualTo("call id"); - - String legType = callLegCaptor.getValue(); - Assertions.assertThat(legType).isEqualTo("both"); - - SvamlControl body = updateParametersCaptor.getValue(); - TestHelpers.recursiveEquals(body, SvamlControlTest.expectedSvamlControl); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/calls/id/" + URLPathUtils.encodePathSegment("call/id") + "/leg/both", + HttpMethod.PATCH, + Collections.emptyList(), + svamlControlDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + service.manageWithCallLeg("call/id", CallLeg.BOTH, SvamlControlTest.expectedSvamlControl); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceTest.java index 4196b3352..326096ce0 100644 --- a/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceTest.java @@ -1,56 +1,89 @@ package com.sinch.sdk.domains.voice.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.voice.api.v1.internal.ConferencesApi; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.voice.api.v1.ConferencesService; import com.sinch.sdk.domains.voice.models.v1.callouts.CalloutRequestDtoTest; import com.sinch.sdk.domains.voice.models.v1.callouts.CalloutResponseDtoTest; import com.sinch.sdk.domains.voice.models.v1.conferences.request.ConferencesRequestDtoTest; -import com.sinch.sdk.domains.voice.models.v1.conferences.request.ManageConferenceParticipantRequest; import com.sinch.sdk.domains.voice.models.v1.conferences.response.ConferencesResponseDtoTest; import com.sinch.sdk.domains.voice.models.v1.conferences.response.GetConferenceInfoResponse; -import com.sinch.sdk.models.VoiceContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; @TestWithResources public class ConferencesServiceTest extends BaseTest { - @Mock ConferencesApi api; - @Mock VoiceContext context; + @GivenTextResource("/domains/voice/v1/callouts/CalloutResponseDto.json") + String calloutResponseDto; + + @GivenTextResource("/domains/voice/v1/callouts/CalloutRequestConferenceDto.json") + String calloutRequestConferenceDto; + + @GivenTextResource("/domains/voice/v1/conferences/response/ConferenceGetResponseDto.json") + String conferenceGetResponseDto; + + @GivenTextResource( + "/domains/voice/v1/conferences/request/ConferenceManageParticipantRequestDto.json") + String conferenceManageParticipantRequestDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Signed"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - @Mock CalloutsService calloutsService; - @Captor ArgumentCaptor conferenceIdCaptor; - @Captor ArgumentCaptor callIdCaptor; - @Captor ArgumentCaptor participantCaptor; - static ConferencesService service; + ConferencesService service; @BeforeEach public void initMocks() { - service = spy(new ConferencesService(context, httpClient, authManagers, calloutsService)); + service = + new ConferencesServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void call() throws ApiException { - when(calloutsService.conference(eq(CalloutRequestDtoTest.conferenceRequestCalloutDto))) - .thenReturn(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/callouts", + HttpMethod.POST, + Collections.emptyList(), + calloutRequestConferenceDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), calloutResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); String response = service.call(CalloutRequestDtoTest.conferenceRequestCalloutDto); @@ -60,11 +93,27 @@ void call() throws ApiException { @Test void get() throws ApiException { - doReturn(api).when(service).getApi(); - when(api.callingGetConferenceInfo( - eq(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()))) - .thenReturn(ConferencesResponseDtoTest.expectedGetConferenceInfoResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/conferences/id/" + + URLPathUtils.encodePathSegment( + CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()), + HttpMethod.GET, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), conferenceGetResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); GetConferenceInfoResponse response = service.get(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()); @@ -75,56 +124,88 @@ void get() throws ApiException { @Test void kickParticipant() throws ApiException { - doReturn(api).when(service).getApi(); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/conferences/id/" + + URLPathUtils.encodePathSegment( + CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()) + + "/" + + URLPathUtils.encodePathSegment( + CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()), + HttpMethod.DELETE, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + service.kickParticipant( CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId(), CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); - verify(api) - .callingKickConferenceParticipant(callIdCaptor.capture(), conferenceIdCaptor.capture()); - - String parameter = callIdCaptor.getValue(); - Assertions.assertThat(parameter) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); - parameter = conferenceIdCaptor.getValue(); - Assertions.assertThat(parameter) - .isEqualTo(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()); } @Test void kickAll() throws ApiException { - doReturn(api).when(service).getApi(); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/conferences/id/" + + URLPathUtils.encodePathSegment( + CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()), + HttpMethod.DELETE, + Collections.emptyList(), + (String) null, + Collections.emptyMap(), + Collections.emptyList(), + Collections.emptyList(), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(204, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); service.kickAll(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()); - verify(api).callingKickConferenceAll(conferenceIdCaptor.capture()); - - String parameter = conferenceIdCaptor.getValue(); - Assertions.assertThat(parameter) - .isEqualTo(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()); } @Test void manageParticipant() throws ApiException { - doReturn(api).when(service).getApi(); + HttpRequest httpRequest = + new HttpRequest( + "/calling/v1/conferences/id/" + + URLPathUtils.encodePathSegment( + CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()) + + "/" + + URLPathUtils.encodePathSegment( + CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()), + HttpMethod.PATCH, + Collections.emptyList(), + conferenceManageParticipantRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); service.manageParticipant( CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId(), CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId(), ConferencesRequestDtoTest.manageConferenceParticipantRequestDto); - - verify(api) - .callingManageConferenceParticipant( - callIdCaptor.capture(), conferenceIdCaptor.capture(), participantCaptor.capture()); - - String parameter = callIdCaptor.getValue(); - Assertions.assertThat(parameter) - .isEqualTo(CalloutResponseDtoTest.expectedCalloutResponseDto.getCallId()); - parameter = conferenceIdCaptor.getValue(); - Assertions.assertThat(parameter) - .isEqualTo(CalloutRequestDtoTest.conferenceRequestCalloutDto.getConferenceId()); - - ManageConferenceParticipantRequest participant = participantCaptor.getValue(); - Assertions.assertThat(participant) - .isEqualTo(ConferencesRequestDtoTest.manageConferenceParticipantRequestDto); } } diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/ApplicationsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/ApplicationsSteps.java index b5616b97b..cd01784a9 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/ApplicationsSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/ApplicationsSteps.java @@ -2,22 +2,20 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.voice.api.v1.ApplicationsService; -import com.sinch.sdk.domains.voice.models.v1.Price; import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; import com.sinch.sdk.domains.voice.models.v1.applications.CallbacksUrl; import com.sinch.sdk.domains.voice.models.v1.applications.Capability; import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberInformation; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberInformation.NumberTypeEnum; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse; import com.sinch.sdk.e2e.Config; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import org.junit.jupiter.api.Assertions; @@ -25,11 +23,10 @@ public class ApplicationsSteps { ApplicationsService service; - OwnedNumbersResponse listNumbersResponse; + OwnedNumbersListResponse listNumbersResponse; Boolean assignNumbersPassed; Boolean unassignNumberPassed; - QueryNumberResponse queryNumberResult; Callbacks getCallbackUrlsResult; Boolean updateCallbackUrlsPassed; @@ -67,12 +64,6 @@ public void unassignNumber() { unassignNumberPassed = true; } - @When("^I send a request to get information about a specific number$") - public void queryNumber() { - - queryNumberResult = service.queryNumber("+12015555555"); - } - @When("^I send a request to get the callback URLs associated to an application$") public void getCallbackUrls() { @@ -94,30 +85,29 @@ public void updateCallbackUrls() { @Then("the response contains details about the numbers that I own") public void listNumbersResult() { - OwnedNumbersResponse expected = - OwnedNumbersResponse.builder() - .setNumbers( - Arrays.asList( - OwnedNumberInformation.builder() - .setNumber("+12012222222") - .setCapability(Capability.VOICE) - .build(), - OwnedNumberInformation.builder() - .setNumber("+12013333333") - .setCapability(Capability.VOICE) - .setApplicationKey("ba5eba11-1dea-1337-babe-5a1ad00d1eaf") - .build(), - OwnedNumberInformation.builder() - .setNumber("+12014444444") - .setCapability(Capability.VOICE) - .build(), - OwnedNumberInformation.builder() - .setNumber("+12015555555") - .setCapability(Capability.VOICE) - .setApplicationKey("f00dcafe-abba-c0de-1dea-dabb1ed4caf3") - .build())) - .build(); - TestHelpers.recursiveEquals(listNumbersResponse, expected); + Collection expected = + new ArrayList<>( + Arrays.asList( + OwnedNumberInformation.builder() + .setNumber("+12012222222") + .setCapability(Capability.VOICE) + .build(), + OwnedNumberInformation.builder() + .setNumber("+12013333333") + .setCapability(Capability.VOICE) + .setApplicationKey("ba5eba11-1dea-1337-babe-5a1ad00d1eaf") + .build(), + OwnedNumberInformation.builder() + .setNumber("+12014444444") + .setCapability(Capability.VOICE) + .build(), + OwnedNumberInformation.builder() + .setNumber("+12015555555") + .setCapability(Capability.VOICE) + .setApplicationKey("f00dcafe-abba-c0de-1dea-dabb1ed4caf3") + .build())); + TestHelpers.recursiveEquals(listNumbersResponse.getContent(), expected); + Assertions.assertFalse(listNumbersResponse.hasNextPage()); } @Then("the assign numbers response contains no data") @@ -130,22 +120,6 @@ public void unassignNumberResult() { Assertions.assertTrue(unassignNumberPassed); } - @Then("the response contains details about the specific number") - public void queryNumberResult() { - QueryNumberResponse expected = - QueryNumberResponse.builder() - .setNumber( - QueryNumberInformation.builder() - .setCountryId("US") - .setNumberType(NumberTypeEnum.FIXED) - .setNormalizedNumber("+12015555555") - .setRestricted(true) - .setRate(Price.builder().setCurrencyId("USD").setAmount(0.01F).build()) - .build()) - .build(); - TestHelpers.recursiveEquals(queryNumberResult, expected); - } - @Then("the response contains callback URLs details") public void getCallbackUrlsResult() { Callbacks expected = diff --git a/examples/snippets/src/main/java/voice/applications/ListNumbers.java b/examples/snippets/src/main/java/voice/applications/ListNumbers.java index 95085ad3a..74e8d7302 100644 --- a/examples/snippets/src/main/java/voice/applications/ListNumbers.java +++ b/examples/snippets/src/main/java/voice/applications/ListNumbers.java @@ -9,7 +9,7 @@ import com.sinch.sdk.SinchClient; import com.sinch.sdk.domains.voice.api.v1.ApplicationsService; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse; import com.sinch.sdk.models.Configuration; import java.util.logging.Logger; import utils.Settings; @@ -35,10 +35,10 @@ public static void main(String[] args) { LOGGER.info("Get assigned numbers"); - OwnedNumbersResponse response = applicationsService.listNumbers(); + OwnedNumbersListResponse response = applicationsService.listNumbers(); LOGGER.info("Response: "); - response.getNumbers().forEach(f -> LOGGER.info(f.toString())); + response.iterator().forEachRemaining(f -> LOGGER.info(f.toString())); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java new file mode 100644 index 000000000..e6b6f7d5d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java @@ -0,0 +1,75 @@ +/* + * Voice API | Sinch + * + * OpenAPI document version: 1.0.1 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.voice.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; +import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; +import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse; + +/** Applications Service */ +public interface ApplicationsService { + + /** + * Update Numbers + * + *

Assign a number or a list of numbers to an application. + * + * @param updateNumbersRequest (optional) + * @throws ApiException if fails to make API call + */ + void assignNumbers(UpdateNumbersRequest updateNumbersRequest) throws ApiException; + + /** + * Get Callback URLs + * + *

Returns any callback URLs configured for the specified application. + * + * @param applicationkey The unique identifying key of the application. (required) + * @return Callbacks + * @throws ApiException if fails to make API call + */ + Callbacks getCallbackUrls(String applicationkey) throws ApiException; + + /** + * Get Numbers + * + *

Get information about your numbers. It returns a list of numbers that you own, as well as + * their capability (voice or SMS). For the ones that are assigned to an app, it returns the + * application key of the app. + * + * @return OwnedNumbersListResponse + * @throws ApiException if fails to make API call + */ + OwnedNumbersListResponse listNumbers() throws ApiException; + + /** + * Un-assign number + * + *

Un-assign a number from an application. + * + * @param unAssignNumberRequest (optional) + * @throws ApiException if fails to make API call + */ + void unassignNumber(UnAssignNumberRequest unAssignNumberRequest) throws ApiException; + + /** + * Update Callbacks + * + *

Update the configured callback URLs for the specified application. + * + * @param applicationkey The unique identifying key of the application. (required) + * @param callbacks (optional) + * @throws ApiException if fails to make API call + */ + void updateCallbackUrls(String applicationkey, Callbacks callbacks) throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java similarity index 87% rename from client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java index 12a71528f..ae6880aa9 100644 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java @@ -1,3 +1,13 @@ +/* + * Voice API | Sinch + * + * OpenAPI document version: 1.0.1 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + package com.sinch.sdk.domains.voice.api.v1; import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequest; @@ -5,13 +15,7 @@ import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestCustom; import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestTTS; -/** - * A callout is a call made to a phone number or app using the API. - * - * @see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callouts - * @since 1.4 - */ +/** Callouts Service */ public interface CalloutsService { /** diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java new file mode 100644 index 000000000..6aa50ceb5 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java @@ -0,0 +1,77 @@ +/* + * Voice API | Sinch + * + * OpenAPI document version: 1.0.1 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.voice.api.v1; + +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.response.CallInformation; +import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl; + +/** Calls Service */ +public interface CallsService { + + /** + * Get information about a call + * + *

You can retrieve information about an ongoing or completed call using a call ID. You can + * find the call ID of an ongoing call by viewing the response object from a callout request. You + * can find the call ID of a completed call by looking at your call logs in your Sinch + * [Dashboard](https://dashboard.sinch.com/voice/logs). Note: You can only use this method for + * calls that terminate to PSTN or SIP networks from an In-app call. + * + * @param callId The unique identifier of the call. This value is generated by the system. + * (required) + * @return CallInformation + * @throws ApiException if fails to make API call + */ + CallInformation get(String callId) throws ApiException; + + /** + * Manage Call with `callLeg` + * + *

This method is used to manage ongoing, connected calls. This method is only used when using + * the `PlayFiles` and `Say` instructions in the request body. This method + * uses SVAML in the request body to perform various tasks related to the call. For more + * information about SVAML, see the [Callback + * API](https://developers.sinch.com/docs/voice/api-reference/svaml/) documentation. Note: You can + * only use this method for calls that originate from or terminate to PSTN or SIP networks. + * + * @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 `PlayFiles` and `Say` instructions to indicate which channel the + * sound will be played on. Valid options are `caller`, `callee` or + * `both`. If not specified, the default value is + * `caller`.<br><Warning>The `callLeg` identifier is ignored + * for calls that are part of a conference and calls initiated using the Callout + * API.</Warning> (required) + * @param svamlControl (optional) + * @throws ApiException if fails to make API call + */ + void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl) + throws ApiException; + + /** + * Update a call in progress + * + *

This method is used to manage ongoing, connected calls. This method uses SVAML in the + * request body to perform various tasks related to the call. For more information about SVAML, + * see the [Callback API](https://developers.sinch.com/docs/voice/api-reference/svaml/) + * documentation. This method can only be used for calls that originate from or terminate to PSTN + * or SIP networks. + * + * @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 + */ + void update(String callId, SvamlControl svamlControl) throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java new file mode 100644 index 000000000..8c940b1df --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java @@ -0,0 +1,77 @@ +/* + * Voice API | Sinch + * + * OpenAPI document version: 1.0.1 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.voice.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference; +import com.sinch.sdk.domains.voice.models.v1.conferences.request.ManageConferenceParticipantRequest; +import com.sinch.sdk.domains.voice.models.v1.conferences.response.GetConferenceInfoResponse; + +/** Conferences Service */ +public interface ConferencesService { + + /** + * Get Conference Info + * + *

Returns information about a conference that matches the provided conference ID. + * + * @param conferenceId The unique identifier of the conference. The user sets this value. + * (required) + * @return GetConferenceInfoResponse + * @throws ApiException if fails to make API call + */ + GetConferenceInfoResponse get(String conferenceId) throws ApiException; + + /** + * Kick Conference All + * + *

Removes all participants from a conference. + * + * @param conferenceId The unique identifier of the conference. The user sets this value. + * (required) + * @throws ApiException if fails to make API call + */ + void kickAll(String conferenceId) throws ApiException; + + /** + * Kick Conference Participant + * + *

Remove a specified conference participant from a specified conference. + * + * @param conferenceId The unique identifier of the conference. The user sets this value. + * (required) + * @param callId The unique identifier of the call. This value is generated by the system. + * (required) + * @throws ApiException if fails to make API call + */ + void kickParticipant(String conferenceId, String callId) throws ApiException; + + /** + * Manage Conference Participant + * + *

Manages conference participant in a specified conference: * mute / unmute * put on hold / + * resume. + * + * @param conferenceId The unique identifier of the conference. The user sets this value. + * (required) + * @param callId The unique identifier of the call. This value is generated by the system. + * (required) + * @param manageConferenceParticipantRequest (optional) + * @throws ApiException if fails to make API call + */ + void manageParticipant( + String conferenceId, + String callId, + ManageConferenceParticipantRequest manageConferenceParticipantRequest) + throws ApiException; + + String call(CalloutRequestConference parameters); +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ApplicationsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceImpl.java similarity index 58% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ApplicationsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceImpl.java index f4857d39e..deb9b5c78 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ApplicationsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.voice.api.v1.internal; +package com.sinch.sdk.domains.voice.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -23,11 +23,12 @@ import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks; import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest; import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest; -import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponse; -import com.sinch.sdk.domains.voice.models.v1.applications.response.QueryNumberResponse; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse; +import com.sinch.sdk.domains.voice.models.v1.applications.response.internal.OwnedNumbersListResponseInternal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -36,15 +37,16 @@ import java.util.Map; import java.util.logging.Logger; -public class ApplicationsApi { +public class ApplicationsServiceImpl + implements com.sinch.sdk.domains.voice.api.v1.ApplicationsService { - private static final Logger LOGGER = Logger.getLogger(ApplicationsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(ApplicationsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public ApplicationsApi( + public ApplicationsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -55,28 +57,18 @@ public ApplicationsApi( this.mapper = mapper; } - /** - * Query number Returns information about the requested number. - * - * @param number The phone number you want to query. (required) - * @return QueryNumberResponse - * @throws ApiException if fails to make API call - * @deprecated - */ - @Deprecated - public QueryNumberResponse callingQueryNumber(String number) throws ApiException { + @Override + public void assignNumbers(UpdateNumbersRequest updateNumbersRequest) throws ApiException { - LOGGER.finest("[callingQueryNumber]" + " " + "number: " + number); + LOGGER.finest("[assignNumbers]" + " " + "updateNumbersRequest: " + updateNumbersRequest); - HttpRequest httpRequest = callingQueryNumberRequestBuilder(number); + HttpRequest httpRequest = assignNumbersRequestBuilder(updateNumbersRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return; } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -87,32 +79,25 @@ public QueryNumberResponse callingQueryNumber(String number) throws ApiException mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingQueryNumberRequestBuilder(String number) throws ApiException { - // verify the required parameter 'number' is set - if (number == null) { - throw new ApiException( - 400, "Missing the required parameter 'number' when calling callingQueryNumber"); - } + private HttpRequest assignNumbersRequestBuilder(UpdateNumbersRequest updateNumbersRequest) + throws ApiException { - String localVarPath = - "/v1/calling/query/number/{number}" - .replaceAll( - "\\{" + "number" + "\\}", URLPathUtils.encodePathSegment(number.toString())); + String localVarPath = "/v1/configuration/numbers"; List localVarQueryParams = new ArrayList<>(); Map localVarHeaderParams = new HashMap<>(); - final Collection localVarAccepts = Arrays.asList("application/json"); + final Collection localVarAccepts = Arrays.asList(); - final Collection localVarContentTypes = Arrays.asList(); + final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "Signed"); - final String serializedBody = null; + final String serializedBody = mapper.serialize(localVarContentTypes, updateNumbersRequest); return new HttpRequest( localVarPath, - HttpMethod.GET, + HttpMethod.POST, localVarQueryParams, serializedBody, localVarHeaderParams, @@ -121,25 +106,18 @@ private HttpRequest callingQueryNumberRequestBuilder(String number) throws ApiEx localVarAuthNames); } - /** - * Get Callback URLs Returns any callback URLs configured for the specified application. - * - * @param applicationkey The unique identifying key of the application. (required) - * @return Callbacks - * @throws ApiException if fails to make API call - */ - public Callbacks configurationGetCallbackURLs(String applicationkey) throws ApiException { + @Override + public Callbacks getCallbackUrls(String applicationkey) throws ApiException { - LOGGER.finest("[configurationGetCallbackURLs]" + " " + "applicationkey: " + applicationkey); + LOGGER.finest("[getCallbackUrls]" + " " + "applicationkey: " + applicationkey); - HttpRequest httpRequest = configurationGetCallbackURLsRequestBuilder(applicationkey); + HttpRequest httpRequest = getCallbackUrlsRequestBuilder(applicationkey); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -150,14 +128,11 @@ public Callbacks configurationGetCallbackURLs(String applicationkey) throws ApiE mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest configurationGetCallbackURLsRequestBuilder(String applicationkey) - throws ApiException { + private HttpRequest getCallbackUrlsRequestBuilder(String applicationkey) throws ApiException { // verify the required parameter 'applicationkey' is set if (applicationkey == null) { throw new ApiException( - 400, - "Missing the required parameter 'applicationkey' when calling" - + " configurationGetCallbackURLs"); + 400, "Missing the required parameter 'applicationkey' when calling getCallbackUrls"); } String localVarPath = @@ -188,27 +163,22 @@ private HttpRequest configurationGetCallbackURLsRequestBuilder(String applicatio localVarAuthNames); } - /** - * Get Numbers Get information about your numbers. It returns a list of numbers that you own, as - * well as their capability (voice or SMS). For the ones that are assigned to an app, it returns - * the application key of the app. - * - * @return OwnedNumbersResponse - * @throws ApiException if fails to make API call - */ - public OwnedNumbersResponse configurationGetNumbers() throws ApiException { + @Override + public OwnedNumbersListResponse listNumbers() throws ApiException { - LOGGER.finest("[configurationGetNumbers]"); + LOGGER.finest("[listNumbers]"); - HttpRequest httpRequest = configurationGetNumbersRequestBuilder(); + HttpRequest httpRequest = listNumbersRequestBuilder(); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + + OwnedNumbersListResponseInternal deserialized = + mapper.deserialize(response, new TypeReference() {}); + + return new OwnedNumbersListResponse(new Page<>(null, deserialized.getNumbers(), null)); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -219,7 +189,7 @@ public OwnedNumbersResponse configurationGetNumbers() throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest configurationGetNumbersRequestBuilder() throws ApiException { + private HttpRequest listNumbersRequestBuilder() throws ApiException { String localVarPath = "/v1/configuration/numbers"; @@ -245,19 +215,12 @@ private HttpRequest configurationGetNumbersRequestBuilder() throws ApiException localVarAuthNames); } - /** - * Un-assign number Un-assign a number from an application. - * - * @param unAssignNumberRequest (optional) - * @throws ApiException if fails to make API call - */ - public void configurationUnassignNumber(UnAssignNumberRequest unAssignNumberRequest) - throws ApiException { + @Override + public void unassignNumber(UnAssignNumberRequest unAssignNumberRequest) throws ApiException { - LOGGER.finest( - "[configurationUnassignNumber]" + " " + "unAssignNumberRequest: " + unAssignNumberRequest); + LOGGER.finest("[unassignNumber]" + " " + "unAssignNumberRequest: " + unAssignNumberRequest); - HttpRequest httpRequest = configurationUnassignNumberRequestBuilder(unAssignNumberRequest); + HttpRequest httpRequest = unassignNumberRequestBuilder(unAssignNumberRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -274,8 +237,8 @@ public void configurationUnassignNumber(UnAssignNumberRequest unAssignNumberRequ mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest configurationUnassignNumberRequestBuilder( - UnAssignNumberRequest unAssignNumberRequest) throws ApiException { + private HttpRequest unassignNumberRequestBuilder(UnAssignNumberRequest unAssignNumberRequest) + throws ApiException { String localVarPath = "/v1/configuration/numbers"; @@ -301,18 +264,11 @@ private HttpRequest configurationUnassignNumberRequestBuilder( localVarAuthNames); } - /** - * Update Callbacks Update the configured callback URLs for the specified application. - * - * @param applicationkey The unique identifying key of the application. (required) - * @param callbacks (optional) - * @throws ApiException if fails to make API call - */ - public void configurationUpdateCallbackURLs(String applicationkey, Callbacks callbacks) - throws ApiException { + @Override + public void updateCallbackUrls(String applicationkey, Callbacks callbacks) throws ApiException { LOGGER.finest( - "[configurationUpdateCallbackURLs]" + "[updateCallbackUrls]" + " " + "applicationkey: " + applicationkey @@ -320,8 +276,7 @@ public void configurationUpdateCallbackURLs(String applicationkey, Callbacks cal + "callbacks: " + callbacks); - HttpRequest httpRequest = - configurationUpdateCallbackURLsRequestBuilder(applicationkey, callbacks); + HttpRequest httpRequest = updateCallbackUrlsRequestBuilder(applicationkey, callbacks); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -338,14 +293,12 @@ public void configurationUpdateCallbackURLs(String applicationkey, Callbacks cal mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest configurationUpdateCallbackURLsRequestBuilder( - String applicationkey, Callbacks callbacks) throws ApiException { + private HttpRequest updateCallbackUrlsRequestBuilder(String applicationkey, Callbacks callbacks) + throws ApiException { // verify the required parameter 'applicationkey' is set if (applicationkey == null) { throw new ApiException( - 400, - "Missing the required parameter 'applicationkey' when calling" - + " configurationUpdateCallbackURLs"); + 400, "Missing the required parameter 'applicationkey' when calling updateCallbackUrls"); } String localVarPath = @@ -375,60 +328,4 @@ private HttpRequest configurationUpdateCallbackURLsRequestBuilder( localVarContentTypes, localVarAuthNames); } - - /** - * Update Numbers Assign a number or a list of numbers to an application. - * - * @param updateNumbersRequest (optional) - * @throws ApiException if fails to make API call - */ - public void configurationUpdateNumbers(UpdateNumbersRequest updateNumbersRequest) - throws ApiException { - - LOGGER.finest( - "[configurationUpdateNumbers]" + " " + "updateNumbersRequest: " + updateNumbersRequest); - - HttpRequest httpRequest = configurationUpdateNumbersRequestBuilder(updateNumbersRequest); - 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>() {})); - } - - private HttpRequest configurationUpdateNumbersRequestBuilder( - UpdateNumbersRequest updateNumbersRequest) throws ApiException { - - String localVarPath = "/v1/configuration/numbers"; - - List localVarQueryParams = new ArrayList<>(); - - Map localVarHeaderParams = new HashMap<>(); - - final Collection localVarAccepts = Arrays.asList(); - - final Collection localVarContentTypes = Arrays.asList("application/json"); - - final Collection localVarAuthNames = Arrays.asList("Basic", "Signed"); - final String serializedBody = mapper.serialize(localVarContentTypes, updateNumbersRequest); - - return new HttpRequest( - localVarPath, - HttpMethod.POST, - localVarQueryParams, - serializedBody, - localVarHeaderParams, - localVarAccepts, - localVarContentTypes, - localVarAuthNames); - } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CalloutsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceImpl.java similarity index 66% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CalloutsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceImpl.java index 768f2ca53..fdd52d2e1 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CalloutsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.voice.api.v1.internal; +package com.sinch.sdk.domains.voice.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -22,7 +22,12 @@ import com.sinch.sdk.core.http.HttpStatus; import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequest; +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; import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternal; +import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternalImpl; import com.sinch.sdk.domains.voice.models.v1.callouts.response.CalloutResponse; import java.util.ArrayList; import java.util.Arrays; @@ -32,15 +37,15 @@ import java.util.Map; import java.util.logging.Logger; -public class CalloutsApi { +public class CalloutsServiceImpl implements com.sinch.sdk.domains.voice.api.v1.CalloutsService { - private static final Logger LOGGER = Logger.getLogger(CalloutsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(CalloutsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public CalloutsApi( + public CalloutsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -51,16 +56,7 @@ public CalloutsApi( this.mapper = mapper; } - /** - * Callout Request Makes a call out to a phone number. The types of callouts currently supported - * are conference callouts, text-to-speech callouts, and custom callouts. The custom callout is - * the most flexible, but text-to-speech and conference callouts are more convenient. - * - * @param calloutRequestInternal (optional) - * @return CalloutResponse - * @throws ApiException if fails to make API call - */ - public CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) + private CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) throws ApiException { LOGGER.finest("[callouts]" + " " + "calloutRequestInternal: " + calloutRequestInternal); @@ -71,8 +67,7 @@ public CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -109,4 +104,30 @@ private HttpRequest calloutsRequestBuilder(CalloutRequestInternal calloutRequest localVarContentTypes, localVarAuthNames); } + + public String textToSpeech(CalloutRequestTTS parameters) { + + return call(parameters); + } + + public String conference(CalloutRequestConference parameters) { + + return call(parameters); + } + + public String custom(CalloutRequestCustom parameters) { + + return call(parameters); + } + + public String call(CalloutRequest parameters) { + + CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); + request.setActualInstance(parameters); + CalloutResponse response = callouts(request); + if (null == response) { + return null; + } + return response.getCallId(); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CallsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceImpl.java similarity index 58% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CallsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceImpl.java index 3c80670a0..afd380188 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/CallsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.voice.api.v1.internal; +package com.sinch.sdk.domains.voice.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -23,6 +23,7 @@ import com.sinch.sdk.core.http.URLParameter; 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.response.CallInformation; import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl; import java.util.ArrayList; @@ -33,15 +34,15 @@ import java.util.Map; import java.util.logging.Logger; -public class CallsApi { +public class CallsServiceImpl implements com.sinch.sdk.domains.voice.api.v1.CallsService { - private static final Logger LOGGER = Logger.getLogger(CallsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(CallsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public CallsApi( + public CallsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -52,30 +53,18 @@ public CallsApi( this.mapper = mapper; } - /** - * Get information about a call You can retrieve information about an ongoing or completed call - * using a call ID. You can find the call ID of an ongoing call by viewing the response object - * from a callout request. You can find the call ID of a completed call by looking at your call - * logs in your Sinch [Dashboard](https://dashboard.sinch.com/voice/logs). Note: You can only use - * this method for calls that terminate to PSTN or SIP networks from an In-app call. - * - * @param callId The unique identifier of the call. This value is generated by the system. - * (required) - * @return CallInformation - * @throws ApiException if fails to make API call - */ - public CallInformation callingGetCallResult(String callId) throws ApiException { - - LOGGER.finest("[callingGetCallResult]" + " " + "callId: " + callId); - - HttpRequest httpRequest = callingGetCallResultRequestBuilder(callId); + @Override + public CallInformation get(String callId) throws ApiException { + + LOGGER.finest("[get]" + " " + "callId: " + callId); + + HttpRequest httpRequest = getRequestBuilder(callId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -86,11 +75,10 @@ public CallInformation callingGetCallResult(String callId) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingGetCallResultRequestBuilder(String callId) throws ApiException { + private HttpRequest getRequestBuilder(String callId) throws ApiException { // verify the required parameter 'callId' is set if (callId == null) { - throw new ApiException( - 400, "Missing the required parameter 'callId' when calling callingGetCallResult"); + throw new ApiException(400, "Missing the required parameter 'callId' when calling get"); } String localVarPath = @@ -120,31 +108,12 @@ private HttpRequest callingGetCallResultRequestBuilder(String callId) throws Api localVarAuthNames); } - /** - * Manage Call with `callLeg` This method is used to manage ongoing, connected calls. - * This method is only used when using the `PlayFiles` and `Say` instructions - * in the request body. This method uses SVAML in the request body to perform various tasks - * related to the call. For more information about SVAML, see the [Callback - * API](https://developers.sinch.com/docs/voice/api-reference/svaml/) documentation. Note: You can - * only use this method for calls that originate from or terminate to PSTN or SIP networks. - * - * @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 `PlayFiles` and `Say` instructions to indicate which channel the - * sound will be played on. Valid options are `caller`, `callee` or - * `both`. If not specified, the default value is - * `caller`.<br><Warning>The `callLeg` identifier is ignored - * for calls that are part of a conference and calls initiated using the Callout - * API.</Warning> (required) - * @param svamlControl (optional) - * @throws ApiException if fails to make API call - */ - public void callingManageCallWithCallLeg(String callId, String callLeg, SvamlControl svamlControl) + @Override + public void manageWithCallLeg(String callId, CallLeg callLeg, SvamlControl svamlControl) throws ApiException { LOGGER.finest( - "[callingManageCallWithCallLeg]" + "[manageWithCallLeg]" + " " + "callId: " + callId @@ -155,8 +124,7 @@ public void callingManageCallWithCallLeg(String callId, String callLeg, SvamlCon + "svamlControl: " + svamlControl); - HttpRequest httpRequest = - callingManageCallWithCallLegRequestBuilder(callId, callLeg, svamlControl); + HttpRequest httpRequest = manageWithCallLegRequestBuilder(callId, callLeg, svamlControl); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -173,18 +141,17 @@ public void callingManageCallWithCallLeg(String callId, String callLeg, SvamlCon mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingManageCallWithCallLegRequestBuilder( - String callId, String callLeg, SvamlControl svamlControl) throws ApiException { + private HttpRequest manageWithCallLegRequestBuilder( + String callId, CallLeg callLeg, SvamlControl svamlControl) throws ApiException { // verify the required parameter 'callId' is set if (callId == null) { throw new ApiException( - 400, "Missing the required parameter 'callId' when calling callingManageCallWithCallLeg"); + 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 callingManageCallWithCallLeg"); + 400, "Missing the required parameter 'callLeg' when calling manageWithCallLeg"); } String localVarPath = @@ -215,24 +182,12 @@ private HttpRequest callingManageCallWithCallLegRequestBuilder( localVarAuthNames); } - /** - * Update a call in progress This method is used to manage ongoing, connected calls. This method - * uses SVAML in the request body to perform various tasks related to the call. For more - * information about SVAML, see the [Callback - * API](https://developers.sinch.com/docs/voice/api-reference/svaml/) documentation. This method - * can only be used for calls that originate from or terminate to PSTN or SIP networks. - * - * @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 - */ - public void callingUpdateCall(String callId, SvamlControl svamlControl) throws ApiException { + @Override + public void update(String callId, SvamlControl svamlControl) throws ApiException { - LOGGER.finest( - "[callingUpdateCall]" + " " + "callId: " + callId + ", " + "svamlControl: " + svamlControl); + LOGGER.finest("[update]" + " " + "callId: " + callId + ", " + "svamlControl: " + svamlControl); - HttpRequest httpRequest = callingUpdateCallRequestBuilder(callId, svamlControl); + HttpRequest httpRequest = updateRequestBuilder(callId, svamlControl); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -249,12 +204,11 @@ public void callingUpdateCall(String callId, SvamlControl svamlControl) throws A mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingUpdateCallRequestBuilder(String callId, SvamlControl svamlControl) + private HttpRequest updateRequestBuilder(String callId, SvamlControl svamlControl) throws ApiException { // verify the required parameter 'callId' is set if (callId == null) { - throw new ApiException( - 400, "Missing the required parameter 'callId' when calling callingUpdateCall"); + throw new ApiException(400, "Missing the required parameter 'callId' when calling update"); } String localVarPath = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ConferencesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceImpl.java similarity index 67% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ConferencesApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceImpl.java index e07596322..0f4275201 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/internal/ConferencesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.voice.api.v1.internal; +package com.sinch.sdk.domains.voice.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -23,7 +23,9 @@ import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestConference; import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternal; +import com.sinch.sdk.domains.voice.models.v1.callouts.request.internal.CalloutRequestInternalImpl; import com.sinch.sdk.domains.voice.models.v1.callouts.response.CalloutResponse; import com.sinch.sdk.domains.voice.models.v1.conferences.request.ManageConferenceParticipantRequest; import com.sinch.sdk.domains.voice.models.v1.conferences.response.GetConferenceInfoResponse; @@ -35,15 +37,16 @@ import java.util.Map; import java.util.logging.Logger; -public class ConferencesApi { +public class ConferencesServiceImpl + implements com.sinch.sdk.domains.voice.api.v1.ConferencesService { - private static final Logger LOGGER = Logger.getLogger(ConferencesApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(ConferencesServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public ConferencesApi( + public ConferencesServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -54,29 +57,18 @@ public ConferencesApi( this.mapper = mapper; } - /** - * Get Conference Info Returns information about a conference that matches the provided conference - * ID. - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * (required) - * @return GetConferenceInfoResponse - * @throws ApiException if fails to make API call - */ - public GetConferenceInfoResponse callingGetConferenceInfo(String conferenceId) + private CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) throws ApiException { - LOGGER.finest("[callingGetConferenceInfo]" + " " + "conferenceId: " + conferenceId); + LOGGER.finest("[callouts]" + " " + "calloutRequestInternal: " + calloutRequestInternal); - HttpRequest httpRequest = callingGetConferenceInfoRequestBuilder(conferenceId); + HttpRequest httpRequest = calloutsRequestBuilder(calloutRequestInternal); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -87,20 +79,10 @@ public GetConferenceInfoResponse callingGetConferenceInfo(String conferenceId) mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingGetConferenceInfoRequestBuilder(String conferenceId) + private HttpRequest calloutsRequestBuilder(CalloutRequestInternal calloutRequestInternal) throws ApiException { - // verify the required parameter 'conferenceId' is set - if (conferenceId == null) { - throw new ApiException( - 400, - "Missing the required parameter 'conferenceId' when calling callingGetConferenceInfo"); - } - String localVarPath = - "/calling/v1/conferences/id/{conferenceId}" - .replaceAll( - "\\{" + "conferenceId" + "\\}", - URLPathUtils.encodePathSegment(conferenceId.toString())); + String localVarPath = "/calling/v1/callouts"; List localVarQueryParams = new ArrayList<>(); @@ -108,14 +90,14 @@ private HttpRequest callingGetConferenceInfoRequestBuilder(String conferenceId) final Collection localVarAccepts = Arrays.asList("application/json"); - final Collection localVarContentTypes = Arrays.asList(); + final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "Signed"); - final String serializedBody = null; + final String serializedBody = mapper.serialize(localVarContentTypes, calloutRequestInternal); return new HttpRequest( localVarPath, - HttpMethod.GET, + HttpMethod.POST, localVarQueryParams, serializedBody, localVarHeaderParams, @@ -124,24 +106,18 @@ private HttpRequest callingGetConferenceInfoRequestBuilder(String conferenceId) localVarAuthNames); } - /** - * Kick Conference All Removes all participants from a conference. - * - * @param conferenceId The unique identifier of the conference. The user sets this value. - * (required) - * @throws ApiException if fails to make API call - */ - public void callingKickConferenceAll(String conferenceId) throws ApiException { + @Override + public GetConferenceInfoResponse get(String conferenceId) throws ApiException { - LOGGER.finest("[callingKickConferenceAll]" + " " + "conferenceId: " + conferenceId); + LOGGER.finest("[get]" + " " + "conferenceId: " + conferenceId); - HttpRequest httpRequest = callingKickConferenceAllRequestBuilder(conferenceId); + HttpRequest httpRequest = getRequestBuilder(conferenceId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - return; + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -152,13 +128,10 @@ public void callingKickConferenceAll(String conferenceId) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingKickConferenceAllRequestBuilder(String conferenceId) - throws ApiException { + private HttpRequest getRequestBuilder(String conferenceId) throws ApiException { // verify the required parameter 'conferenceId' is set if (conferenceId == null) { - throw new ApiException( - 400, - "Missing the required parameter 'conferenceId' when calling callingKickConferenceAll"); + throw new ApiException(400, "Missing the required parameter 'conferenceId' when calling get"); } String localVarPath = @@ -171,7 +144,7 @@ private HttpRequest callingKickConferenceAllRequestBuilder(String conferenceId) Map localVarHeaderParams = new HashMap<>(); - final Collection localVarAccepts = Arrays.asList(); + final Collection localVarAccepts = Arrays.asList("application/json"); final Collection localVarContentTypes = Arrays.asList(); @@ -180,7 +153,7 @@ private HttpRequest callingKickConferenceAllRequestBuilder(String conferenceId) return new HttpRequest( localVarPath, - HttpMethod.DELETE, + HttpMethod.GET, localVarQueryParams, serializedBody, localVarHeaderParams, @@ -189,29 +162,12 @@ private HttpRequest callingKickConferenceAllRequestBuilder(String conferenceId) localVarAuthNames); } - /** - * Kick Conference Participant Remove a specified conference participant from a specified - * conference. - * - * @param callId The unique identifier of the call. This value is generated by the system. - * (required) - * @param conferenceId The unique identifier of the conference. The user sets this value. - * (required) - * @throws ApiException if fails to make API call - */ - public void callingKickConferenceParticipant(String callId, String conferenceId) - throws ApiException { + @Override + public void kickAll(String conferenceId) throws ApiException { - LOGGER.finest( - "[callingKickConferenceParticipant]" - + " " - + "callId: " - + callId - + ", " - + "conferenceId: " - + conferenceId); + LOGGER.finest("[kickAll]" + " " + "conferenceId: " + conferenceId); - HttpRequest httpRequest = callingKickConferenceParticipantRequestBuilder(callId, conferenceId); + HttpRequest httpRequest = kickAllRequestBuilder(conferenceId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -228,25 +184,15 @@ public void callingKickConferenceParticipant(String callId, String conferenceId) mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingKickConferenceParticipantRequestBuilder( - String callId, String conferenceId) throws ApiException { - // verify the required parameter 'callId' is set - if (callId == null) { - throw new ApiException( - 400, - "Missing the required parameter 'callId' when calling callingKickConferenceParticipant"); - } + private HttpRequest kickAllRequestBuilder(String conferenceId) throws ApiException { // verify the required parameter 'conferenceId' is set if (conferenceId == null) { throw new ApiException( - 400, - "Missing the required parameter 'conferenceId' when calling" - + " callingKickConferenceParticipant"); + 400, "Missing the required parameter 'conferenceId' when calling kickAll"); } String localVarPath = - "/calling/v1/conferences/id/{conferenceId}/{callId}" - .replaceAll("\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString())) + "/calling/v1/conferences/id/{conferenceId}" .replaceAll( "\\{" + "conferenceId" + "\\}", URLPathUtils.encodePathSegment(conferenceId.toString())); @@ -255,7 +201,7 @@ private HttpRequest callingKickConferenceParticipantRequestBuilder( Map localVarHeaderParams = new HashMap<>(); - final Collection localVarAccepts = Arrays.asList("application/json"); + final Collection localVarAccepts = Arrays.asList(); final Collection localVarContentTypes = Arrays.asList(); @@ -273,38 +219,13 @@ private HttpRequest callingKickConferenceParticipantRequestBuilder( localVarAuthNames); } - /** - * Manage Conference Participant Manages conference participant in a specified conference: * mute - * / unmute * put on hold / resume. - * - * @param callId The unique identifier of the call. This value is generated by the system. - * (required) - * @param conferenceId The unique identifier of the conference. The user sets this value. - * (required) - * @param manageConferenceParticipantRequest (optional) - * @throws ApiException if fails to make API call - */ - public void callingManageConferenceParticipant( - String callId, - String conferenceId, - ManageConferenceParticipantRequest manageConferenceParticipantRequest) - throws ApiException { + @Override + public void kickParticipant(String conferenceId, String callId) throws ApiException { LOGGER.finest( - "[callingManageConferenceParticipant]" - + " " - + "callId: " - + callId - + ", " - + "conferenceId: " - + conferenceId - + ", " - + "manageConferenceParticipantRequest: " - + manageConferenceParticipantRequest); + "[kickParticipant]" + " " + "conferenceId: " + conferenceId + ", " + "callId: " + callId); - HttpRequest httpRequest = - callingManageConferenceParticipantRequestBuilder( - callId, conferenceId, manageConferenceParticipantRequest); + HttpRequest httpRequest = kickParticipantRequestBuilder(conferenceId, callId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -321,32 +242,26 @@ public void callingManageConferenceParticipant( mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest callingManageConferenceParticipantRequestBuilder( - String callId, - String conferenceId, - ManageConferenceParticipantRequest manageConferenceParticipantRequest) + private HttpRequest kickParticipantRequestBuilder(String conferenceId, String callId) throws ApiException { - // verify the required parameter 'callId' is set - if (callId == null) { - throw new ApiException( - 400, - "Missing the required parameter 'callId' when calling" - + " callingManageConferenceParticipant"); - } // verify the required parameter 'conferenceId' is set if (conferenceId == null) { throw new ApiException( - 400, - "Missing the required parameter 'conferenceId' when calling" - + " callingManageConferenceParticipant"); + 400, "Missing the required parameter 'conferenceId' when calling kickParticipant"); + } + // verify the required parameter 'callId' is set + if (callId == null) { + throw new ApiException( + 400, "Missing the required parameter 'callId' when calling kickParticipant"); } String localVarPath = "/calling/v1/conferences/id/{conferenceId}/{callId}" - .replaceAll("\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString())) .replaceAll( "\\{" + "conferenceId" + "\\}", - URLPathUtils.encodePathSegment(conferenceId.toString())); + URLPathUtils.encodePathSegment(conferenceId.toString())) + .replaceAll( + "\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString())); List localVarQueryParams = new ArrayList<>(); @@ -354,15 +269,14 @@ private HttpRequest callingManageConferenceParticipantRequestBuilder( final Collection localVarAccepts = Arrays.asList("application/json"); - final Collection localVarContentTypes = Arrays.asList("application/json"); + final Collection localVarContentTypes = Arrays.asList(); final Collection localVarAuthNames = Arrays.asList("Basic", "Signed"); - final String serializedBody = - mapper.serialize(localVarContentTypes, manageConferenceParticipantRequest); + final String serializedBody = null; return new HttpRequest( localVarPath, - HttpMethod.PATCH, + HttpMethod.DELETE, localVarQueryParams, serializedBody, localVarHeaderParams, @@ -371,28 +285,33 @@ private HttpRequest callingManageConferenceParticipantRequestBuilder( localVarAuthNames); } - /** - * Callout Request Makes a call out to a phone number. The types of callouts currently supported - * are conference callouts, text-to-speech callouts, and custom callouts. The custom callout is - * the most flexible, but text-to-speech and conference callouts are more convenient. - * - * @param calloutRequestInternal (optional) - * @return CalloutResponse - * @throws ApiException if fails to make API call - */ - public CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) + @Override + public void manageParticipant( + String conferenceId, + String callId, + ManageConferenceParticipantRequest manageConferenceParticipantRequest) throws ApiException { - LOGGER.finest("[callouts]" + " " + "calloutRequestInternal: " + calloutRequestInternal); + LOGGER.finest( + "[manageParticipant]" + + " " + + "conferenceId: " + + conferenceId + + ", " + + "callId: " + + callId + + ", " + + "manageConferenceParticipantRequest: " + + manageConferenceParticipantRequest); - HttpRequest httpRequest = calloutsRequestBuilder(calloutRequestInternal); + HttpRequest httpRequest = + manageParticipantRequestBuilder(conferenceId, callId, manageConferenceParticipantRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return; } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -403,10 +322,29 @@ public CalloutResponse callouts(CalloutRequestInternal calloutRequestInternal) mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest calloutsRequestBuilder(CalloutRequestInternal calloutRequestInternal) + private HttpRequest manageParticipantRequestBuilder( + String conferenceId, + String callId, + ManageConferenceParticipantRequest manageConferenceParticipantRequest) throws ApiException { + // verify the required parameter 'conferenceId' is set + if (conferenceId == null) { + throw new ApiException( + 400, "Missing the required parameter 'conferenceId' when calling manageParticipant"); + } + // verify the required parameter 'callId' is set + if (callId == null) { + throw new ApiException( + 400, "Missing the required parameter 'callId' when calling manageParticipant"); + } - String localVarPath = "/calling/v1/callouts"; + String localVarPath = + "/calling/v1/conferences/id/{conferenceId}/{callId}" + .replaceAll( + "\\{" + "conferenceId" + "\\}", + URLPathUtils.encodePathSegment(conferenceId.toString())) + .replaceAll( + "\\{" + "callId" + "\\}", URLPathUtils.encodePathSegment(callId.toString())); List localVarQueryParams = new ArrayList<>(); @@ -417,11 +355,12 @@ private HttpRequest calloutsRequestBuilder(CalloutRequestInternal calloutRequest final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "Signed"); - final String serializedBody = mapper.serialize(localVarContentTypes, calloutRequestInternal); + final String serializedBody = + mapper.serialize(localVarContentTypes, manageConferenceParticipantRequest); return new HttpRequest( localVarPath, - HttpMethod.POST, + HttpMethod.PATCH, localVarQueryParams, serializedBody, localVarHeaderParams, @@ -429,4 +368,15 @@ private HttpRequest calloutsRequestBuilder(CalloutRequestInternal calloutRequest localVarContentTypes, localVarAuthNames); } + + public String call(CalloutRequestConference parameters) { + + CalloutRequestInternalImpl request = new CalloutRequestInternalImpl(); + request.setActualInstance(parameters); + CalloutResponse response = callouts(request); + if (null == response) { + return null; + } + return response.getCallId(); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersListResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersListResponse.java new file mode 100644 index 000000000..fc4d72cce --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersListResponse.java @@ -0,0 +1,47 @@ +/* + * Voice API | Sinch + * + * OpenAPI document version: 1.0.1 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.voice.models.v1.applications.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import java.util.Collection; +import java.util.Collections; + +/** Auto paginated response for list of OwnedNumberInformation */ +public class OwnedNumbersListResponse extends ListResponse { + + private final Page page; + + public OwnedNumbersListResponse(Page page) { + this.page = page; + } + + @Override + public boolean hasNextPage() { + return false; + } + + @Override + public OwnedNumbersListResponse nextPage() { + + return null; + } + + @Override + public Collection getContent() { + return page == null ? Collections.emptyList() : page.getEntities(); + } + + @Override + public String toString() { + return "OwnedNumbersListResponse {" + "page=" + page + '}'; + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternal.java similarity index 72% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternal.java index ff4d5340f..a696b68fd 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternal.java @@ -8,14 +8,15 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.voice.models.v1.applications.response; +package com.sinch.sdk.domains.voice.models.v1.applications.response.internal; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation; import java.util.List; -/** OwnedNumbersResponse */ -@JsonDeserialize(builder = OwnedNumbersResponseImpl.Builder.class) -public interface OwnedNumbersResponse { +/** OwnedNumbersListResponseInternal */ +@JsonDeserialize(builder = OwnedNumbersListResponseInternalImpl.Builder.class) +public interface OwnedNumbersListResponseInternal { /** * The object type. Will always be list of numbers, associated application keys and capabilities @@ -30,7 +31,7 @@ public interface OwnedNumbersResponse { * @return New Builder instance */ static Builder builder() { - return new OwnedNumbersResponseImpl.Builder(); + return new OwnedNumbersListResponseInternalImpl.Builder(); } /** Dedicated Builder */ @@ -50,6 +51,6 @@ interface Builder { * * @return The instance build with current builder values */ - OwnedNumbersResponse build(); + OwnedNumbersListResponseInternal build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternalImpl.java similarity index 73% rename from openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternalImpl.java index c5c16bc94..c6d150e6b 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/internal/OwnedNumbersListResponseInternalImpl.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.voice.models.v1.applications.response; +package com.sinch.sdk.domains.voice.models.v1.applications.response.internal; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -7,22 +7,24 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation; import java.util.List; import java.util.Objects; -@JsonPropertyOrder({OwnedNumbersResponseImpl.JSON_PROPERTY_NUMBERS}) +@JsonPropertyOrder({OwnedNumbersListResponseInternalImpl.JSON_PROPERTY_NUMBERS}) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class OwnedNumbersResponseImpl implements OwnedNumbersResponse { +public class OwnedNumbersListResponseInternalImpl implements OwnedNumbersListResponseInternal { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_NUMBERS = "numbers"; private OptionalValue> numbers; - public OwnedNumbersResponseImpl() {} + public OwnedNumbersListResponseInternalImpl() {} - protected OwnedNumbersResponseImpl(OptionalValue> numbers) { + protected OwnedNumbersListResponseInternalImpl( + OptionalValue> numbers) { this.numbers = numbers; } @@ -46,7 +48,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - OwnedNumbersResponseImpl getNumbersResponseObj = (OwnedNumbersResponseImpl) o; + OwnedNumbersListResponseInternalImpl getNumbersResponseObj = + (OwnedNumbersListResponseInternalImpl) o; return Objects.equals(this.numbers, getNumbersResponseObj.numbers); } @@ -58,7 +61,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class OwnedNumbersResponseImpl {\n"); + sb.append("class OwnedNumbersListResponseInternalImpl {\n"); sb.append(" numbers: ").append(toIndentedString(numbers)).append("\n"); sb.append("}"); return sb.toString(); @@ -75,7 +78,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements OwnedNumbersResponse.Builder { + static class Builder implements OwnedNumbersListResponseInternal.Builder { OptionalValue> numbers = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_NUMBERS) @@ -84,8 +87,8 @@ public Builder setNumbers(List numbers) { return this; } - public OwnedNumbersResponse build() { - return new OwnedNumbersResponseImpl(numbers); + public OwnedNumbersListResponseInternal build() { + return new OwnedNumbersListResponseInternalImpl(numbers); } } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseTest.java index 1568a6791..967ae9d67 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersResponseTest.java @@ -5,14 +5,15 @@ import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.voice.models.v1.applications.Capability; +import com.sinch.sdk.domains.voice.models.v1.applications.response.internal.OwnedNumbersListResponseInternal; import java.util.Arrays; import org.junit.jupiter.api.Test; @TestWithResources public class OwnedNumbersResponseTest extends BaseTest { - public static OwnedNumbersResponse expected = - OwnedNumbersResponse.builder() + public static OwnedNumbersListResponseInternal expected = + OwnedNumbersListResponseInternal.builder() .setNumbers( Arrays.asList( OwnedNumberInformation.builder() @@ -27,7 +28,7 @@ public class OwnedNumbersResponseTest extends BaseTest { .build(); @GivenJsonResource("/domains/voice/v1/applications/response/OwnedNumbersResponseDto.json") - OwnedNumbersResponse loaded; + OwnedNumbersListResponseInternal loaded; @Test void deserializeResponse() {