From 829fd6181c669b839f3ee2aa98b4b7285d7c0fbe Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 13 Feb 2026 10:27:55 +0100 Subject: [PATCH 1/6] feat (Verification): Remove adaptor layer for Verification API --- .../adapters/VerificationService.java | 20 -- .../api/v1/VerificationReportService.java | 134 -------- .../api/v1/VerificationService.java | 8 +- .../api/v1/VerificationStartService.java | 73 ----- .../api/v1/VerificationStatusService.java | 50 --- ...HooksService.java => WebhooksService.java} | 2 +- .../adapters/VerificationReportService.java | 112 ------- .../api/v1/adapters/VerificationService.java | 46 ++- .../v1/adapters/VerificationStartService.java | 85 ----- .../adapters/VerificationStatusService.java | 64 ---- ...HooksService.java => WebhooksService.java} | 6 +- .../v1/report/request/package-info.java | 2 +- .../VerificationReportResponseMapper.java | 38 +++ .../v1/report/response/package-info.java | 2 +- .../models/v1/start/request/package-info.java | 2 +- .../VerificationStartResponseMapper.java | 38 +++ .../v1/start/response/package-info.java | 2 +- .../models/v1/status/package-info.java | 2 +- .../VerificationStatusResponseMapper.java | 38 +++ .../v1/status/response/package-info.java | 2 +- .../VerificationReportServiceTest.java | 299 +++++++++++++----- .../VerificationStartServiceTest.java | 269 ++++++++++------ .../VerificationStatusServiceTest.java | 119 +++++-- .../api/v1/adapters/WebhooksServiceTest.java | 4 +- .../domains/verification/v1/ReportSteps.java | 4 +- .../domains/verification/v1/StartSteps.java | 4 +- .../domains/verification/v1/StatusSteps.java | 4 +- .../verification/v1/WebhooksEventsSteps.java | 4 +- .../verification/VerificationsSample.java | 4 +- .../java/verification/report/ReportById.java | 6 +- .../verification/report/ReportByIdentity.java | 7 +- .../main/java/verification/start/Start.java | 6 +- .../java/verification/status/GetById.java | 6 +- .../verification/status/GetByIdentity.java | 6 +- .../verification/status/GetByReference.java | 6 +- .../app/verification/Controller.java | 4 +- .../adapters/VerificationBaseTest.java | 2 +- .../api/v1/adapters/VerificationBaseTest.java | 11 + .../VerificationReportRequestDtoTest.java | 34 +- .../VerificationReportResponseDtoTest.java | 79 ++--- .../request/VerificationStartRequestTest.java | 102 +++--- .../VerificationStartResponseTest.java | 112 +++---- .../VerificationStatusResponseTest.java | 205 ++++++------ 43 files changed, 922 insertions(+), 1101 deletions(-) delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.java rename client/src/main/com/sinch/sdk/domains/verification/api/v1/{WebHooksService.java => WebhooksService.java} (98%) delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusService.java rename client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/{WebHooksService.java => WebhooksService.java} (91%) create mode 100644 client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/VerificationReportResponseMapper.java create mode 100644 client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/VerificationStartResponseMapper.java create mode 100644 client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/VerificationStatusResponseMapper.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationBaseTest.java diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java index ec078fd2c..5eb6d860a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationService.java @@ -9,10 +9,6 @@ public class VerificationService implements com.sinch.sdk.domains.verification.V private final com.sinch.sdk.domains.verification.api.v1.VerificationService v1; - static { - LocalLazyInit.init(); - } - public VerificationService( ApplicationCredentials credentials, VerificationContext context, @@ -26,20 +22,4 @@ public VerificationService( public com.sinch.sdk.domains.verification.api.v1.VerificationService v1() { return this.v1; } - - static final class LocalLazyInit { - - private LocalLazyInit() { - IdentityMapper.initMapper(); - } - - public static LocalLazyInit init() { - return LocalLazyInit.LazyHolder.INSTANCE; - } - - private static class LazyHolder { - - public static final LocalLazyInit INSTANCE = new LocalLazyInit(); - } - } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.java deleted file mode 100644 index c418aff61..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.sinch.sdk.domains.verification.api.v1; - -import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; - -/** - * Verification Report Service - * - *

Report about a verification request - * - * @see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications - * @since 1.1 - */ -public interface VerificationReportService { - - /** - * Report a verification using {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#SMS} & Identity - * - *

Report the received verification code to verify it, using the identity of the user - * - * @param identity Currently Only {@link - * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponseSms reportSmsByIdentity( - NumberIdentity identity, VerificationReportRequestSms parameters); - - /** - * Report a verification using {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#FLASH_CALL} & Identity - * - *

Report the received verification code to verify it, using the identity of the user - * - * @param identity Currently Only {@link - * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponseFlashCall reportFlashCallByIdentity( - NumberIdentity identity, VerificationReportRequestFlashCall parameters); - - /** - * Report a verification using {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#PHONE_CALL} & Identity - * - *

Report the received verification code to verify it, using the identity of the user - * - * @param identity Currently Only {@link - * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponsePhoneCall reportPhoneCallByIdentity( - NumberIdentity identity, VerificationReportRequestPhoneCall parameters); - - /** - * Report a verification using {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#WHATSAPP} & Identity - * - *

Report the received verification code to verify it, using the identity of the user - * - * @param identity Currently Only {@link - * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported - * @param parameters Parameters to be used to get report - * @return Verification report response - * @apiNote This is a BETA feature and can be changed before GA - * @since 2.0 - */ - VerificationReportResponseWhatsApp reportWhatsAppByIdentity( - NumberIdentity identity, VerificationReportRequestWhatsApp parameters); - - /** - * Report the received verification code to verify it, using the Verification ID of the {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#SMS} Verification request - * - * @param id ID returned from start verification - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponseSms reportSmsById(String id, VerificationReportRequestSms parameters); - - /** - * Report the received verification code to verify it, using the Verification ID of the {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#FLASH_CALL} Verification - * request - * - * @param id ID returned from start verification - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponseFlashCall reportFlashCallById( - String id, VerificationReportRequestFlashCall parameters); - - /** - * Report the received verification code to verify it, using the Verification ID of the {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#PHONE_CALL} Verification - * request - * - * @param id ID returned from start verification - * @param parameters Parameters to be used to get report - * @return Verification report response - * @since 1.1 - */ - VerificationReportResponsePhoneCall reportPhoneCallById( - String id, VerificationReportRequestPhoneCall parameters); - - /** - * Report the received verification code to verify it, using the Verification ID of the {@link - * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#WHATSAPP} Verification request - * - * @param id ID returned from start verification - * @param parameters Parameters to be used to get report - * @return Verification report response - * @apiNote This is a BETA feature and can be changed before GA - * @since 2.0 - */ - VerificationReportResponseWhatsApp reportWhatsAppById( - String id, VerificationReportRequestWhatsApp parameters); -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationService.java index a09e7c397..fc01b4a52 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationService.java @@ -17,7 +17,7 @@ public interface VerificationService { * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications">Documentation * @since 1.1 */ - VerificationStartService verificationStart(); + VerificationsStartService verificationStart(); /** * Verifications Report Service instance @@ -27,7 +27,7 @@ public interface VerificationService { * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications">Documentation * @since 1.1 */ - VerificationReportService verificationReport(); + VerificationsReportService verificationReport(); /** * Verifications Status Service instance @@ -37,7 +37,7 @@ public interface VerificationService { * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-status">Documentation * @since 1.1 */ - VerificationStatusService verificationStatus(); + VerificationsStatusService verificationStatus(); /** * Webhooks helpers instance @@ -47,5 +47,5 @@ public interface VerificationService { * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks">Documentation * @since 1.1 */ - WebHooksService webhooks(); + WebhooksService webhooks(); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.java deleted file mode 100644 index 6c880487a..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.sinch.sdk.domains.verification.api.v1; - -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; - -/** - * Verification Start Service - * - *

Start new verification requests - * - *

This method is used by the mobile and web Verification SDKs to start a verification. It can - * also be used to request a verification from your backend, by making a request. - * - * @see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications - * @since 1.1 - */ -public interface VerificationStartService { - - /** - * Start verification by SMS - * - * @param parameters Parameters to be used to start verification - * @return Verification response - * @since 1.1 - */ - VerificationStartResponseSms startSms(VerificationStartRequestSms parameters); - - /** - * Start verification by FLASH_CALL - * - * @param parameters Parameters to be used to start verification - * @return Verification response - * @since 1.1 - */ - VerificationStartResponseFlashCall startFlashCall(VerificationStartRequestFlashCall parameters); - - /** - * Start verification by PHONE_CALL - * - * @param parameters Parameters to be used to start verification - * @return Verification response - * @since 1.1 - */ - VerificationStartResponsePhoneCall startPhoneCall(VerificationStartRequestPhoneCall parameters); - - /** - * Start verification by DATA - * - * @param parameters Parameters to be used to start verification - * @return Verification response - * @since 1.1 - */ - VerificationStartResponseData startData(VerificationStartRequestData parameters); - - /** - * Start verification by WhatsApp - * - * @apiNote This is a BETA feature and can be changed before GA - * @param parameters Parameters to be used to start verification - * @return Verification response - * @since 2.0 - */ - VerificationStartResponseWhatsApp startWhatsApp(VerificationStartRequestWhatsApp parameters); -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.java deleted file mode 100644 index 3b5081d9a..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.sinch.sdk.domains.verification.api.v1; - -import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; -import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; - -/** - * Get the status of specific verification requests in the verification process. Returns the status - * of pending and completed verifications. You can retrieve the status of verification requests by - * using the ID of the request, the phone number of the user being verified, or a custom reference - * string. - * - * @see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-status - * @since 1.1 - */ -public interface VerificationStatusService { - - /** - * Queries the verification result by sending the verification Identity (usually a phone number) - * and its method. With this query you can get the result of a verification. - * - * @param identity Currently Only {@link - * com.sinch.sdk.domains.verification.models.v1.NumberIdentity} is supported - * @param method Method used for verification - * @return Verification status response - * @since 1.1 - */ - VerificationStatusResponse getByIdentity(NumberIdentity identity, VerificationMethod method); - - /** - * Queries the verification result by sending the verification ID. With this query you can get the - * result of a verification. - * - * @param id The ID of the verification - * @return Verification status response - * @since 1.1 - */ - VerificationStatusResponse getById(String id); - - /** - * Queries the verification result by sending the verification Reference. With this query you can - * get the result of a verification - * - * @param reference The custom reference of the verification - * @return Verification status response - * @since 1.1 - */ - VerificationStatusResponse getByReference(String reference); -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/WebhooksService.java similarity index 98% rename from client/src/main/com/sinch/sdk/domains/verification/api/v1/WebHooksService.java rename to client/src/main/com/sinch/sdk/domains/verification/api/v1/WebhooksService.java index 0fbe0cfc4..937363ad6 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/api/v1/WebhooksService.java @@ -16,7 +16,7 @@ * * @since 1.1 */ -public interface WebHooksService { +public interface WebhooksService { /** * The Sinch Platform can initiate callback requests to a URL you define (Callback URL) on request diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportService.java deleted file mode 100644 index 5f5feb974..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportService.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.sinch.sdk.domains.verification.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.verification.api.v1.internal.VerificationsReportApi; -import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequest; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestInternalImpl; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponse; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.report.response.internal.VerificationReportResponseInternalImpl; -import com.sinch.sdk.models.VerificationContext; -import java.util.Map; - -public class VerificationReportService - implements com.sinch.sdk.domains.verification.api.v1.VerificationReportService { - - private final VerificationsReportApi api; - - public VerificationReportService( - VerificationContext context, HttpClient httpClient, Map authManagers) { - this.api = - new VerificationsReportApi( - httpClient, context.getVerificationServer(), authManagers, HttpMapper.getInstance()); - } - - protected VerificationsReportApi getApi() { - return this.api; - } - - @Override - public VerificationReportResponseSms reportSmsByIdentity( - NumberIdentity identity, VerificationReportRequestSms parameters) { - - return (VerificationReportResponseSms) reportByIdentity(identity, parameters); - } - - @Override - public VerificationReportResponseFlashCall reportFlashCallByIdentity( - NumberIdentity identity, VerificationReportRequestFlashCall parameters) { - - return (VerificationReportResponseFlashCall) reportByIdentity(identity, parameters); - } - - @Override - public VerificationReportResponsePhoneCall reportPhoneCallByIdentity( - NumberIdentity identity, VerificationReportRequestPhoneCall parameters) { - - return (VerificationReportResponsePhoneCall) reportByIdentity(identity, parameters); - } - - @Override - public VerificationReportResponseWhatsApp reportWhatsAppByIdentity( - NumberIdentity identity, VerificationReportRequestWhatsApp parameters) { - - return (VerificationReportResponseWhatsApp) reportByIdentity(identity, parameters); - } - - @Override - public VerificationReportResponseSms reportSmsById( - String id, VerificationReportRequestSms parameters) { - - return (VerificationReportResponseSms) reportById(id, parameters); - } - - @Override - public VerificationReportResponseFlashCall reportFlashCallById( - String id, VerificationReportRequestFlashCall parameters) { - - return (VerificationReportResponseFlashCall) reportById(id, parameters); - } - - @Override - public VerificationReportResponsePhoneCall reportPhoneCallById( - String id, VerificationReportRequestPhoneCall parameters) { - - return (VerificationReportResponsePhoneCall) reportById(id, parameters); - } - - @Override - public VerificationReportResponseWhatsApp reportWhatsAppById( - String id, VerificationReportRequestWhatsApp parameters) { - - return (VerificationReportResponseWhatsApp) reportById(id, parameters); - } - - private VerificationReportResponse reportByIdentity( - NumberIdentity identity, VerificationReportRequest parameters) { - VerificationReportRequestInternalImpl internal = new VerificationReportRequestInternalImpl(); - internal.setActualInstance(parameters); - VerificationReportResponseInternalImpl response = - (VerificationReportResponseInternalImpl) - getApi().reportVerificationByIdentity(identity.getEndpoint(), internal); - return (VerificationReportResponse) response.getActualInstance(); - } - - private VerificationReportResponse reportById(String id, VerificationReportRequest parameters) { - VerificationReportRequestInternalImpl internal = new VerificationReportRequestInternalImpl(); - internal.setActualInstance(parameters); - VerificationReportResponseInternalImpl response = - (VerificationReportResponseInternalImpl) getApi().reportVerificationById(id, internal); - return (VerificationReportResponse) response.getActualInstance(); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationService.java index 0de1679c8..f2e40c8c2 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationService.java @@ -4,8 +4,15 @@ 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.verification.adapters.IdentityMapper; +import com.sinch.sdk.domains.verification.api.v1.VerificationsReportService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStartService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseMapper; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseMapper; +import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseMapper; import com.sinch.sdk.models.ApplicationCredentials; import com.sinch.sdk.models.VerificationContext; import java.util.Map; @@ -28,10 +35,10 @@ public class VerificationService private final VerificationContext context; private final Supplier httpClientSupplier; - private volatile VerificationStartService startService; - private volatile VerificationReportService reportService; - private volatile VerificationStatusService statusService; - private volatile WebHooksService webhooks; + private volatile VerificationsStartService startService; + private volatile VerificationsReportService reportService; + private volatile VerificationsStatusService statusService; + private volatile WebhooksService webhooks; private volatile Map clientAuthManagers; private volatile Map webhooksAuthManagers; @@ -77,37 +84,49 @@ private void createAuthManagers(ApplicationCredentials credentials) { APPLICATION_SECURITY_SCHEME_KEYWORD_VERIFICATION, applicationAuthManager); } - public VerificationStartService verificationStart() { + public VerificationsStartService verificationStart() { if (null == this.startService) { instanceLazyInit(); this.startService = - new VerificationStartService(context, httpClientSupplier.get(), clientAuthManagers); + new VerificationsStartServiceImpl( + httpClientSupplier.get(), + context.getVerificationServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.startService; } - public VerificationReportService verificationReport() { + public VerificationsReportService verificationReport() { if (null == this.reportService) { instanceLazyInit(); this.reportService = - new VerificationReportService(context, httpClientSupplier.get(), clientAuthManagers); + new VerificationsReportServiceImpl( + httpClientSupplier.get(), + context.getVerificationServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.reportService; } - public VerificationStatusService verificationStatus() { + public VerificationsStatusService verificationStatus() { if (null == this.statusService) { instanceLazyInit(); this.statusService = - new VerificationStatusService(context, httpClientSupplier.get(), clientAuthManagers); + new VerificationsStatusServiceImpl( + httpClientSupplier.get(), + context.getVerificationServer(), + clientAuthManagers, + HttpMapper.getInstance()); } return this.statusService; } - public WebHooksService webhooks() { + public WebhooksService webhooks() { if (null == this.webhooks) { instanceLazyInit(); - this.webhooks = new WebHooksService(webhooksAuthManagers); + this.webhooks = new WebhooksService(webhooksAuthManagers); } return this.webhooks; } @@ -147,6 +166,9 @@ static final class LocalLazyInit { private LocalLazyInit() { IdentityMapper.initMapper(); + VerificationStartResponseMapper.initMapper(); + VerificationStatusResponseMapper.initMapper(); + VerificationReportResponseMapper.initMapper(); } public static LocalLazyInit init() { diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartService.java deleted file mode 100644 index 98e05ca4b..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.sinch.sdk.domains.verification.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.verification.api.v1.internal.VerificationsStartApi; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequest; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternalImpl; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponse; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternalImpl; -import com.sinch.sdk.models.VerificationContext; -import java.util.Map; -import java.util.Optional; - -public class VerificationStartService - implements com.sinch.sdk.domains.verification.api.v1.VerificationStartService { - - private final VerificationsStartApi api; - - public VerificationStartService( - VerificationContext context, HttpClient httpClient, Map authManagers) { - this.api = - new VerificationsStartApi( - httpClient, context.getVerificationServer(), authManagers, HttpMapper.getInstance()); - } - - protected VerificationsStartApi getApi() { - return this.api; - } - - @Override - public VerificationStartResponseSms startSms(VerificationStartRequestSms parameters) { - String acceptLanguage = parameters.getAcceptLanguage(); - return (VerificationStartResponseSms) start(parameters, acceptLanguage).orElse(null); - } - - @Override - public VerificationStartResponseFlashCall startFlashCall( - VerificationStartRequestFlashCall parameters) { - return (VerificationStartResponseFlashCall) start(parameters).orElse(null); - } - - @Override - public VerificationStartResponsePhoneCall startPhoneCall( - VerificationStartRequestPhoneCall parameters) { - return (VerificationStartResponsePhoneCall) start(parameters).orElse(null); - } - - @Override - public VerificationStartResponseData startData(VerificationStartRequestData parameters) { - return (VerificationStartResponseData) start(parameters).orElse(null); - } - - @Override - public VerificationStartResponseWhatsApp startWhatsApp( - VerificationStartRequestWhatsApp parameters) { - return (VerificationStartResponseWhatsApp) start(parameters).orElse(null); - } - - private Optional start(VerificationStartRequest parameters) { - return start(parameters, null); - } - - private Optional start( - VerificationStartRequest parameters, String acceptLanguage) { - VerificationStartRequestInternalImpl impl = new VerificationStartRequestInternalImpl(); - impl.setActualInstance(parameters); - VerificationStartResponseInternalImpl response = - (VerificationStartResponseInternalImpl) getApi().startVerification(impl, acceptLanguage); - if (null == response) { - return Optional.empty(); - } - return Optional.ofNullable((VerificationStartResponse) response.getActualInstance()); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusService.java deleted file mode 100644 index 64121f385..000000000 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusService.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.sinch.sdk.domains.verification.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.verification.api.v1.internal.VerificationStatusApi; -import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; -import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; -import com.sinch.sdk.domains.verification.models.v1.status.response.internal.VerificationStatusResponseInternalImpl; -import com.sinch.sdk.models.VerificationContext; -import java.util.Map; - -public class VerificationStatusService - implements com.sinch.sdk.domains.verification.api.v1.VerificationStatusService { - - private final VerificationStatusApi api; - - public VerificationStatusService( - VerificationContext context, HttpClient httpClient, Map authManagers) { - this.api = - new VerificationStatusApi( - httpClient, context.getVerificationServer(), authManagers, HttpMapper.getInstance()); - } - - protected VerificationStatusApi getApi() { - return this.api; - } - - @Override - public VerificationStatusResponse getByIdentity( - NumberIdentity identity, VerificationMethod method) { - - VerificationStatusResponseInternalImpl response = - (VerificationStatusResponseInternalImpl) - getApi().verificationStatusByIdentity(identity.getEndpoint(), method.value()); - if (null == response) { - return null; - } - return (VerificationStatusResponse) response.getActualInstance(); - } - - @Override - public VerificationStatusResponse getById(String id) { - - VerificationStatusResponseInternalImpl response = - (VerificationStatusResponseInternalImpl) getApi().verificationStatusById(id); - if (null == response) { - return null; - } - return (VerificationStatusResponse) response.getActualInstance(); - } - - @Override - public VerificationStatusResponse getByReference(String reference) { - - VerificationStatusResponseInternalImpl response = - (VerificationStatusResponseInternalImpl) getApi().verificationStatusByReference(reference); - if (null == response) { - return null; - } - return (VerificationStatusResponse) response.getActualInstance(); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksService.java similarity index 91% rename from client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebHooksService.java rename to client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksService.java index 980d5596e..5917a1872 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksService.java @@ -12,13 +12,13 @@ import java.util.Map; import java.util.logging.Logger; -public class WebHooksService implements com.sinch.sdk.domains.verification.api.v1.WebHooksService { +public class WebhooksService implements com.sinch.sdk.domains.verification.api.v1.WebhooksService { - private static final Logger LOGGER = Logger.getLogger(WebHooksService.class.getName()); + private static final Logger LOGGER = Logger.getLogger(WebhooksService.class.getName()); private final Map authManagers; - public WebHooksService(Map authManagers) { + public WebhooksService(Map authManagers) { this.authManagers = authManagers; } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/request/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/request/package-info.java index 95ecc0d23..1747fe377 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/request/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/request/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Report requests * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationReportService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsReportService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.report.request; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/VerificationReportResponseMapper.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/VerificationReportResponseMapper.java new file mode 100644 index 000000000..f533368ab --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/VerificationReportResponseMapper.java @@ -0,0 +1,38 @@ +package com.sinch.sdk.domains.verification.models.v1.report.response; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.verification.models.v1.report.response.internal.VerificationReportResponseInternalImpl; +import java.io.IOException; + +public class VerificationReportResponseMapper { + + public static void initMapper() { + SimpleModule module = + new SimpleModule().addDeserializer(VerificationReportResponse.class, new Deserializer()); + Mapper.getInstance().registerModule(module); + } + + static class Deserializer extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public VerificationReportResponse deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + VerificationReportResponseInternalImpl deserialized = + jp.readValueAs(VerificationReportResponseInternalImpl.class); + return (VerificationReportResponse) deserialized.getActualInstance(); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/package-info.java index b320a6bdd..93167c09c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/report/response/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Report responses * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationReportService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsReportService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.report.response; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/package-info.java index cb23c9614..6bda06389 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/request/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Start requests * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationStartService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsStartService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.start.request; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/VerificationStartResponseMapper.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/VerificationStartResponseMapper.java new file mode 100644 index 000000000..62d094849 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/VerificationStartResponseMapper.java @@ -0,0 +1,38 @@ +package com.sinch.sdk.domains.verification.models.v1.start.response; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternalImpl; +import java.io.IOException; + +public class VerificationStartResponseMapper { + + public static void initMapper() { + SimpleModule module = + new SimpleModule().addDeserializer(VerificationStartResponse.class, new Deserializer()); + Mapper.getInstance().registerModule(module); + } + + static class Deserializer extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public VerificationStartResponse deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + VerificationStartResponseInternalImpl deserialized = + jp.readValueAs(VerificationStartResponseInternalImpl.class); + return (VerificationStartResponse) deserialized.getActualInstance(); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/package-info.java index 7ff0bcdcd..447a85453 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/start/response/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Start responses * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationStartService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsStartService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.start.response; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/package-info.java index d78059223..3d1029f5b 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Status * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationStatusService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.status; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/VerificationStatusResponseMapper.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/VerificationStatusResponseMapper.java new file mode 100644 index 000000000..78584940e --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/VerificationStatusResponseMapper.java @@ -0,0 +1,38 @@ +package com.sinch.sdk.domains.verification.models.v1.status.response; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.verification.models.v1.status.response.internal.VerificationStatusResponseInternalImpl; +import java.io.IOException; + +public class VerificationStatusResponseMapper { + + public static void initMapper() { + SimpleModule module = + new SimpleModule().addDeserializer(VerificationStatusResponse.class, new Deserializer()); + Mapper.getInstance().registerModule(module); + } + + static class Deserializer extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public VerificationStatusResponse deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException { + + VerificationStatusResponseInternalImpl deserialized = + jp.readValueAs(VerificationStatusResponseInternalImpl.class); + return (VerificationStatusResponse) deserialized.getActualInstance(); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/package-info.java index ad9b886c5..9a96b634b 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/v1/status/response/package-info.java @@ -1,7 +1,7 @@ /** * Models related to Verifications Status responses * - * @see com.sinch.sdk.domains.verification.api.v1.VerificationStatusService + * @see com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService * @since 1.1 */ package com.sinch.sdk.domains.verification.models.v1.status.response; diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportServiceTest.java index 9a5c92f07..58242f3bc 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationReportServiceTest.java @@ -1,27 +1,35 @@ package com.sinch.sdk.domains.verification.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.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; 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.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.verification.adapters.VerificationBaseTest; -import com.sinch.sdk.domains.verification.api.v1.internal.VerificationsReportApi; +import com.sinch.sdk.domains.verification.api.v1.VerificationsReportService; import com.sinch.sdk.domains.verification.models.dto.v1.report.VerificationReportRequestDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.report.VerificationReportResponseDtoTest; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; -import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestInternal; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; -import com.sinch.sdk.models.VerificationContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,177 +38,296 @@ @TestWithResources public class VerificationReportServiceTest extends VerificationBaseTest { - @GivenJsonResource("/domains/verification/v1/report/VerificationReportRequestPhoneCallDto.json") - public VerificationReportRequestInternal verificationReportPhoneCallRequestDto; + @GivenTextResource("/domains/verification/v1/report/VerificationReportRequestPhoneCallDto.json") + public String verificationReportPhoneCallRequestDto; - @GivenJsonResource("/domains/verification/v1/report/VerificationReportRequestFlashCallDto.json") - public VerificationReportRequestInternal verificationReportFlashCallRequestDto; + @GivenTextResource("/domains/verification/v1/report/VerificationReportResponsePhoneCallDto.json") + public String verificationReportPhoneCallResponseDto; - @GivenJsonResource("/domains/verification/v1/report/VerificationReportRequestSmsDto.json") - public VerificationReportRequestInternal verificationReportSmsRequestDto; + @GivenTextResource("/domains/verification/v1/report/VerificationReportRequestFlashCallDto.json") + public String verificationReportFlashCallRequestDto; - @GivenJsonResource("/domains/verification/v1/report/VerificationReportRequestWhatsAppDto.json") - public VerificationReportRequestInternal verificationReportWhatsAppRequestDto; + @GivenTextResource("/domains/verification/v1/report/VerificationReportResponseFlashCallDto.json") + public String verificationReportFlashCallResponseDto; - @Mock VerificationsReportApi api; - @Mock VerificationContext context; + @GivenTextResource("/domains/verification/v1/report/VerificationReportRequestSmsDto.json") + public String verificationReportSmsRequestDto; + + @GivenTextResource("/domains/verification/v1/report/VerificationReportResponseSmsDto.json") + public String verificationReportSmsResponseDto; + + @GivenTextResource("/domains/verification/v1/report/VerificationReportRequestWhatsAppDto.json") + public String verificationReportWhatsAppRequestDto; + + @GivenTextResource("/domains/verification/v1/report/VerificationReportResponseWhatsAppDto.json") + public String verificationReportWhatsAppResponseDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Application"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - - VerificationReportService service; + VerificationsReportService service; @BeforeEach public void initMocks() { - VerificationReportService v1 = new VerificationReportService(context, httpClient, authManagers); - service = spy(v1); - doReturn(api).when(service).getApi(); + service = + new VerificationsReportServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void reportSmsByIdentity() throws ApiException { - when(api.reportVerificationByIdentity( - eq("endpoint string"), eq(verificationReportSmsRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportSmsDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/number/" + + URLPathUtils.encodePathSegment("endpoint string"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportSmsRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportSmsResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseSms response = service.reportSmsByIdentity( NumberIdentity.builder().setEndpoint("endpoint string").build(), - VerificationReportRequestDtoTest.verificationReportSmsDto - .getVerificationReportRequestSmsImpl()); + VerificationReportRequestDtoTest.verificationReportSmsDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportSmsDto - .getVerificationReportResponseSmsImpl()); + response, VerificationReportResponseDtoTest.verificationReportSmsDto); } @Test void reportFlashCallByIdentity() throws ApiException { - when(api.reportVerificationByIdentity( - eq("endpoint string"), eq(verificationReportFlashCallRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportFlashCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/number/" + + URLPathUtils.encodePathSegment("endpoint string"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportFlashCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportFlashCallResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseFlashCall response = service.reportFlashCallByIdentity( NumberIdentity.builder().setEndpoint("endpoint string").build(), - VerificationReportRequestDtoTest.verificationReportFlashCallDto - .getVerificationReportRequestFlashCallImpl()); + VerificationReportRequestDtoTest.verificationReportFlashCallDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportFlashCallDto - .getVerificationReportResponseFlashCallImpl()); + response, VerificationReportResponseDtoTest.verificationReportFlashCallDto); } @Test void reportPhoneCallByIdentity() throws ApiException { - when(api.reportVerificationByIdentity( - eq("endpoint string"), eq(verificationReportPhoneCallRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportPhoneCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/number/" + + URLPathUtils.encodePathSegment("endpoint string"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportPhoneCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportPhoneCallResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponsePhoneCall response = service.reportPhoneCallByIdentity( NumberIdentity.builder().setEndpoint("endpoint string").build(), - VerificationReportRequestDtoTest.verificationReportPhoneCallDto - .getVerificationReportRequestPhoneCallImpl()); + VerificationReportRequestDtoTest.verificationReportPhoneCallDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportPhoneCallDto - .getVerificationReportResponsePhoneCallImpl()); + response, VerificationReportResponseDtoTest.verificationReportPhoneCallDto); } @Test void reportWhatsAppByIdentity() throws ApiException { - when(api.reportVerificationByIdentity( - eq("endpoint string"), eq(verificationReportWhatsAppRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportWhatsAppDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/number/" + + URLPathUtils.encodePathSegment("endpoint string"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportWhatsAppRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportWhatsAppResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseWhatsApp response = service.reportWhatsAppByIdentity( NumberIdentity.builder().setEndpoint("endpoint string").build(), - VerificationReportRequestDtoTest.verificationReportWhatsAppDto - .getVerificationReportRequestWhatsAppImpl()); + VerificationReportRequestDtoTest.verificationReportWhatsAppDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportWhatsAppDto - .getVerificationReportResponseWhatsAppImpl()); + response, VerificationReportResponseDtoTest.verificationReportWhatsAppDto); } @Test void reportSmsById() throws ApiException { - when(api.reportVerificationById(eq("the id"), eq(verificationReportSmsRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportSmsDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/id/" + URLPathUtils.encodePathSegment("the id"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportSmsRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportSmsResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseSms response = - service.reportSmsById( - "the id", - VerificationReportRequestDtoTest.verificationReportSmsDto - .getVerificationReportRequestSmsImpl()); + service.reportSmsById("the id", VerificationReportRequestDtoTest.verificationReportSmsDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportSmsDto - .getVerificationReportResponseSmsImpl()); + response, VerificationReportResponseDtoTest.verificationReportSmsDto); } @Test void reportFlashCallById() throws ApiException { - when(api.reportVerificationById(eq("the id"), eq(verificationReportFlashCallRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportFlashCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/id/" + URLPathUtils.encodePathSegment("the id"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportFlashCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportFlashCallResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseFlashCall response = service.reportFlashCallById( - "the id", - VerificationReportRequestDtoTest.verificationReportFlashCallDto - .getVerificationReportRequestFlashCallImpl()); + "the id", VerificationReportRequestDtoTest.verificationReportFlashCallDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportFlashCallDto - .getVerificationReportResponseFlashCallImpl()); + response, VerificationReportResponseDtoTest.verificationReportFlashCallDto); } @Test void reportPhoneCallById() throws ApiException { - when(api.reportVerificationById(eq("the id"), eq(verificationReportPhoneCallRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportPhoneCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/id/" + URLPathUtils.encodePathSegment("the id"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportPhoneCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportPhoneCallResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponsePhoneCall response = service.reportPhoneCallById( - "the id", - VerificationReportRequestDtoTest.verificationReportPhoneCallDto - .getVerificationReportRequestPhoneCallImpl()); + "the id", VerificationReportRequestDtoTest.verificationReportPhoneCallDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportPhoneCallDto - .getVerificationReportResponsePhoneCallImpl()); + response, VerificationReportResponseDtoTest.verificationReportPhoneCallDto); } @Test void reportWhatsAppById() throws ApiException { - when(api.reportVerificationById(eq("the id"), eq(verificationReportWhatsAppRequestDto))) - .thenReturn(VerificationReportResponseDtoTest.verificationReportWhatsAppDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/id/" + URLPathUtils.encodePathSegment("the id"), + HttpMethod.PUT, + Collections.emptyList(), + verificationReportWhatsAppRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), verificationReportWhatsAppResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationReportResponseWhatsApp response = service.reportWhatsAppById( - "the id", - VerificationReportRequestDtoTest.verificationReportWhatsAppDto - .getVerificationReportRequestWhatsAppImpl()); + "the id", VerificationReportRequestDtoTest.verificationReportWhatsAppDto); TestHelpers.recursiveEquals( - response, - VerificationReportResponseDtoTest.verificationReportWhatsAppDto - .getVerificationReportResponseWhatsAppImpl()); + response, VerificationReportResponseDtoTest.verificationReportWhatsAppDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java index d3f71ce1b..2d173256d 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStartServiceTest.java @@ -2,32 +2,33 @@ 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.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; 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.core.models.ModelArgMatcher; +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.verification.adapters.VerificationBaseTest; -import com.sinch.sdk.domains.verification.api.v1.internal.VerificationsStartApi; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStartService; import com.sinch.sdk.domains.verification.models.dto.v1.start.request.VerificationStartRequestTest; import com.sinch.sdk.domains.verification.models.dto.v1.start.response.VerificationStartResponseTest; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequest; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSmsImpl; -import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternal; -import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternalImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; -import com.sinch.sdk.models.VerificationContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,149 +37,232 @@ @TestWithResources public class VerificationStartServiceTest extends VerificationBaseTest { - @GivenJsonResource( + @GivenTextResource( "/domains/verification/v1/start/request/VerificationStartRequestPhoneCallDto.json") - public VerificationStartRequestInternal startVerificationPhoneCallRequestDto; + String startVerificationPhoneCallRequestDto; - @GivenJsonResource( + @GivenTextResource( + "/domains/verification/v1/start/response/VerificationStartResponsePhoneCallDto.json") + String startVerificationStartResponsePhoneCallDto; + + @GivenTextResource( "/domains/verification/v1/start/request/VerificationStartRequestFlashCallDto.json") - public VerificationStartRequestInternal startVerificationFlashCallRequestDto; + String startVerificationFlashCallRequestDto; + + @GivenTextResource( + "/domains/verification/v1/start/response/VerificationStartResponseFlashCallDto.json") + String startVerificationFlashCallResponseDto; + + @GivenTextResource("/domains/verification/v1/start/request/VerificationStartRequestDataDto.json") + String startVerificationDataRequestDto; + + @GivenTextResource( + "/domains/verification/v1/start/response/VerificationStartResponseDataDto.json") + String startVerificationDataResponseDto; - @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestDataDto.json") - public VerificationStartRequestInternal startVerificationDataRequestDto; + @GivenTextResource("/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json") + String startVerificationSmsRequestDto; - @GivenJsonResource("/domains/verification/v1/start/request/VerificationStartRequestSmsDto.json") - public VerificationStartRequestInternal startVerificationSmsRequestDto; + @GivenTextResource("/domains/verification/v1/start/response/VerificationStartResponseSmsDto.json") + String startVerificationSmsResponseDto; - @GivenJsonResource( + @GivenTextResource( "/domains/verification/v1/start/request/VerificationStartRequestWhatsAppDto.json") - public VerificationStartRequestInternal startVerificationWhatsAppRequestDto; + public String startVerificationWhatsAppRequestDto; - @Mock VerificationsStartApi api; - @Mock VerificationContext context; + @GivenTextResource( + "/domains/verification/v1/start/response/VerificationStartResponseWhatsAppDto.json") + public String startVerificationWhatsAppResponseDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Application"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - - VerificationStartService service; + VerificationsStartService service; @BeforeEach public void initMocks() { - VerificationStartService v1 = new VerificationStartService(context, httpClient, authManagers); - service = spy(v1); - doReturn(api).when(service).getApi(); + service = + new VerificationsStartServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void startSms() throws ApiException { - when(api.startVerification( - argThat(new ModelArgMatcher<>(startVerificationSmsRequestDto)), eq(null))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationSmsDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationSmsRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), startVerificationSmsResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponseSms response = - service.startSms( - VerificationStartRequestTest.startVerificationSmsDto - .getVerificationStartRequestSmsImpl()); + service.startSms(VerificationStartRequestTest.startVerificationSmsDto); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationSmsDto.getActualInstance()); + response, VerificationStartResponseTest.expectedStartVerificationSmsDto); } @Test void startSmsWithAcceptLanguage() throws ApiException { - VerificationStartRequestSmsImpl startVerificationSmsRequestDtoImpl = - ((VerificationStartRequestInternalImpl) startVerificationSmsRequestDto) - .getVerificationStartRequestSmsImpl(); - VerificationStartRequest withAcceptLanguage = - VerificationStartRequestSms.builder() - .setIdentity(startVerificationSmsRequestDtoImpl.getIdentity()) - .setReference(startVerificationSmsRequestDtoImpl.getReference()) - .setCustom(startVerificationSmsRequestDtoImpl.getCustom()) - .setExpiry(startVerificationSmsRequestDtoImpl.getExpiry()) - .setCodeType(startVerificationSmsRequestDtoImpl.getCodeType()) - .setAcceptLanguage("es-ES") - .putExtraOption("my key", startVerificationSmsRequestDtoImpl.getExtraOption("my key")) - .build(); - VerificationStartRequestInternalImpl internalWithAcceptLanguage = - new VerificationStartRequestInternalImpl(); - internalWithAcceptLanguage.setActualInstance(withAcceptLanguage); - - when(api.startVerification( - argThat(new ModelArgMatcher<>(internalWithAcceptLanguage)), eq("es-ES"))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationSmsDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationSmsRequestDto, + Collections.singletonMap("Accept-Language", "es-ES"), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), startVerificationSmsResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponseSms response = - service.startSms( - VerificationStartRequestTest.startVerificationSmsDtoWithAcceptLanguage - .getVerificationStartRequestSmsImpl()); + service.startSms(VerificationStartRequestTest.startVerificationSmsDtoWithAcceptLanguage); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationSmsDto - .getVerificationStartResponseSmsImpl()); + response, VerificationStartResponseTest.expectedStartVerificationSmsDto); } @Test void startFlashCall() throws ApiException { - when(api.startVerification( - argThat(new ModelArgMatcher<>(startVerificationFlashCallRequestDto)), eq(null))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationFlashCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationFlashCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), startVerificationFlashCallResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponseFlashCall response = - service.startFlashCall( - VerificationStartRequestTest.startVerificationFlashCallDto - .getVerificationStartRequestFlashCallImpl()); + service.startFlashCall(VerificationStartRequestTest.startVerificationFlashCallDto); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationFlashCallDto - .getVerificationStartResponseFlashCallImpl()); + response, VerificationStartResponseTest.expectedStartVerificationFlashCallDto); } @Test void startPhoneCall() throws ApiException { - when(api.startVerification( - argThat(new ModelArgMatcher<>(startVerificationPhoneCallRequestDto)), eq(null))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationPhoneCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationPhoneCallRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, + null, + Collections.emptyMap(), + startVerificationStartResponsePhoneCallDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponsePhoneCall response = - service.startPhoneCall( - VerificationStartRequestTest.startVerificationPhoneCallDto - .getVerificationStartRequestPhoneCallImpl()); + service.startPhoneCall(VerificationStartRequestTest.startVerificationPhoneCallDto); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationPhoneCallDto - .getVerificationStartResponsePhoneCallImpl()); + response, VerificationStartResponseTest.expectedStartVerificationPhoneCallDto); } @Test void startData() throws ApiException { - when(api.startVerification(eq(startVerificationDataRequestDto), eq(null))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationDataDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationDataRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), startVerificationDataResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponseData response = - service.startData( - VerificationStartRequestTest.startVerificationDataDto - .getVerificationStartRequestDataImpl()); + service.startData(VerificationStartRequestTest.startVerificationDataDto); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationDataDto - .getVerificationStartResponseDataImpl()); + response, VerificationStartResponseTest.expectedStartVerificationDataDto); } @Test void startWhatsApp() throws ApiException { - when(api.startVerification( - argThat(new ModelArgMatcher<>(startVerificationWhatsAppRequestDto)), eq(null))) - .thenReturn(VerificationStartResponseTest.expectedStartVerificationWhatsAppDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications", + HttpMethod.POST, + Collections.emptyList(), + startVerificationWhatsAppRequestDto, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + AUTH_NAMES); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), startVerificationWhatsAppResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStartResponseWhatsApp response = service.startWhatsApp( @@ -186,7 +270,6 @@ void startWhatsApp() throws ApiException { .getVerificationStartRequestWhatsAppImpl()); TestHelpers.recursiveEquals( - response, - VerificationStartResponseTest.expectedStartVerificationWhatsAppDto.getActualInstance()); + response, VerificationStartResponseTest.expectedStartVerificationWhatsAppDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusServiceTest.java index 2fff0e080..a36c5987a 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationStatusServiceTest.java @@ -1,22 +1,32 @@ package com.sinch.sdk.domains.verification.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.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.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.verification.adapters.VerificationBaseTest; -import com.sinch.sdk.domains.verification.api.v1.internal.VerificationStatusApi; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; import com.sinch.sdk.domains.verification.models.dto.v1.status.VerificationStatusResponseTest; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; -import com.sinch.sdk.models.VerificationContext; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,24 +35,54 @@ @TestWithResources public class VerificationStatusServiceTest extends VerificationBaseTest { - @Mock VerificationStatusApi api; - @Mock VerificationContext context; + @GivenTextResource("/domains/verification/v1/status/VerificationStatusResponseSmsDto.json") + String verificationStatusResponseSmsDto; + + @GivenTextResource("/domains/verification/v1/status/VerificationStatusResponsePhoneCallDto.json") + String verificationStatusResponsePhoneCallDto; + + @GivenTextResource("/domains/verification/v1/status/VerificationStatusResponseFlashCallDto.json") + String verificationStatusResponseFlashCallDto; + + static final Collection AUTH_NAMES = Arrays.asList("Basic", "Application"); + + @Mock ServerConfiguration serverConfiguration; @Mock HttpClient httpClient; @Mock Map authManagers; - - VerificationStatusService service; + VerificationsStatusService service; @BeforeEach public void initMocks() { - service = spy(new VerificationStatusService(context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new VerificationsStatusServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance()); } @Test void getByIdentity() throws ApiException { - when(api.verificationStatusByIdentity(eq("endpoint string"), eq("sms"))) - .thenReturn(VerificationStatusResponseTest.expectedVerificationSmsDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/" + + URLPathUtils.encodePathSegment(VerificationMethod.SMS.toString()) + + "/number/" + + URLPathUtils.encodePathSegment("endpoint string"), + 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(), verificationStatusResponseSmsDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStatusResponse response = service.getByIdentity( @@ -50,36 +90,65 @@ void getByIdentity() throws ApiException { VerificationMethod.SMS); TestHelpers.recursiveEquals( - response, - VerificationStatusResponseTest.expectedVerificationSmsDto - .getVerificationStatusResponseSmsImpl()); + response, VerificationStatusResponseTest.expectedVerificationSmsDto); } @Test void getById() throws ApiException { - when(api.verificationStatusById(eq("the id"))) - .thenReturn(VerificationStatusResponseTest.expectedVerificationPhoneCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/id/" + URLPathUtils.encodePathSegment("the 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(), verificationStatusResponsePhoneCallDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStatusResponse response = service.getById("the id"); TestHelpers.recursiveEquals( - response, - VerificationStatusResponseTest.expectedVerificationPhoneCallDto - .getVerificationStatusResponsePhoneCallImpl()); + response, VerificationStatusResponseTest.expectedVerificationPhoneCallDto); } @Test void getByReference() throws ApiException { - when(api.verificationStatusByReference(eq("the reference"))) - .thenReturn(VerificationStatusResponseTest.expectedVerificationFlashCallDto); + HttpRequest httpRequest = + new HttpRequest( + "/verification/v1/verifications/reference/" + + URLPathUtils.encodePathSegment("the reference"), + 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(), verificationStatusResponseFlashCallDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); VerificationStatusResponse response = service.getByReference("the reference"); TestHelpers.recursiveEquals( - response, - VerificationStatusResponseTest.expectedVerificationFlashCallDto - .getVerificationStatusResponseFlashCallImpl()); + response, VerificationStatusResponseTest.expectedVerificationFlashCallDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksServiceTest.java index c8d585939..b61d9011b 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/WebhooksServiceTest.java @@ -5,7 +5,7 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.verification.adapters.VerificationBaseTest; -import com.sinch.sdk.domains.verification.api.v1.WebHooksService; +import com.sinch.sdk.domains.verification.api.v1.WebhooksService; import com.sinch.sdk.domains.verification.models.dto.v1.webhooks.VerificationRequestEventDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.webhooks.VerificationResponseEventDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.webhooks.VerificationResultEventDtoTest; @@ -46,7 +46,7 @@ public class WebhooksServiceTest extends VerificationBaseTest { @GivenTextResource("/domains/verification/v1/webhooks/VerificationResponseWhatsApp.json") String jsonResponseWhatsApp; - WebHooksService webHooksService; + WebhooksService webHooksService; @Test void checkApplicationAuthentication() throws ApiException { diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/ReportSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/ReportSteps.java index dfde1a726..b8889dff5 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/ReportSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/ReportSteps.java @@ -1,7 +1,7 @@ package com.sinch.sdk.e2e.domains.verification.v1; import com.sinch.sdk.core.TestHelpers; -import com.sinch.sdk.domains.verification.api.v1.VerificationReportService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsReportService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.VerificationStatus; import com.sinch.sdk.domains.verification.models.v1.VerificationStatusReason; @@ -21,7 +21,7 @@ public class ReportSteps { - VerificationReportService service; + VerificationsReportService service; VerificationReportResponse reportSmsByIdResponse; VerificationReportResponse reportSmsByIdentityResponse; VerificationReportResponse reportCalloutByIdResponse; diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StartSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StartSteps.java index bc6c3414c..e4ed32003 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StartSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StartSteps.java @@ -2,7 +2,7 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.verification.api.v1.VerificationStartService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStartService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.SmsCodeType; import com.sinch.sdk.domains.verification.models.v1.WhatsAppCodeType; @@ -29,7 +29,7 @@ public class StartSteps { - VerificationStartService service; + VerificationsStartService service; VerificationStartResponse startVerificationBySmsResponse; VerificationStartResponse startVerificationByPhoneCallResponse; VerificationStartResponse startVerificationByFlashCallResponse; diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StatusSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StatusSteps.java index 555af42f3..8a780bdef 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StatusSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/StatusSteps.java @@ -1,7 +1,7 @@ package com.sinch.sdk.e2e.domains.verification.v1; import com.sinch.sdk.core.TestHelpers; -import com.sinch.sdk.domains.verification.api.v1.VerificationStatusService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.Price; import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; @@ -21,7 +21,7 @@ public class StatusSteps { - VerificationStatusService service; + VerificationsStatusService service; VerificationStatusResponse statusByIdResponse; VerificationStatusResponse statusByIdentityResponse; VerificationStatusResponse statusByReferenceResponse; diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/WebhooksEventsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/WebhooksEventsSteps.java index 69f984eaf..09d9e7a3d 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/WebhooksEventsSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/verification/v1/WebhooksEventsSteps.java @@ -1,7 +1,7 @@ package com.sinch.sdk.e2e.domains.verification.v1; import com.sinch.sdk.core.TestHelpers; -import com.sinch.sdk.domains.verification.api.v1.WebHooksService; +import com.sinch.sdk.domains.verification.api.v1.WebhooksService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.Price; import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; @@ -29,7 +29,7 @@ public class WebhooksEventsSteps { static final String WEBHOOKS_PATH = Config.VERIFICATION_HOST_NAME + "/webhooks/verification/"; - WebHooksService service; + WebhooksService service; static VerificationEvent expectedVerificationRequestEvent = VerificationRequestEvent.builder() diff --git a/examples/getting-started/verification/user-verification-using-sms-pin/src/main/java/verification/VerificationsSample.java b/examples/getting-started/verification/user-verification-using-sms-pin/src/main/java/verification/VerificationsSample.java index 53cff4e73..3dba8d23c 100644 --- a/examples/getting-started/verification/user-verification-using-sms-pin/src/main/java/verification/VerificationsSample.java +++ b/examples/getting-started/verification/user-verification-using-sms-pin/src/main/java/verification/VerificationsSample.java @@ -45,7 +45,7 @@ public void start() { * @return Verification ID */ private String startSmsVerification( - VerificationStartService service, E164PhoneNumber phoneNumber) { + VerificationsStartService service, E164PhoneNumber phoneNumber) { echo("Sending verification request onto '%s'", phoneNumber.stringValue()); @@ -66,7 +66,7 @@ private String startSmsVerification( * @param code Code received by SMS * @param id Verification ID related to the verification */ - private void reportSmsVerification(VerificationReportService service, Integer code, String id) { + private void reportSmsVerification(VerificationsReportService service, Integer code, String id) { VerificationReportRequestSms parameters = VerificationReportRequestSms.builder().setCode(String.valueOf(code)).build(); diff --git a/examples/snippets/src/main/java/verification/report/ReportById.java b/examples/snippets/src/main/java/verification/report/ReportById.java index 3c39277b4..2457dc384 100644 --- a/examples/snippets/src/main/java/verification/report/ReportById.java +++ b/examples/snippets/src/main/java/verification/report/ReportById.java @@ -8,7 +8,7 @@ package verification.report; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationReportService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsReportService; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponse; import com.sinch.sdk.models.Configuration; @@ -37,7 +37,7 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationReportService verificationReportService = + VerificationsReportService verificationsReportService = client.verification().v1().verificationReport(); LOGGER.info( @@ -47,7 +47,7 @@ public static void main(String[] args) { VerificationReportRequestSms.builder().setCode(receivedVerificationCode).build(); VerificationReportResponse response = - verificationReportService.reportSmsById(verificationId, request); + verificationsReportService.reportSmsById(verificationId, request); LOGGER.info("Response: " + response); } diff --git a/examples/snippets/src/main/java/verification/report/ReportByIdentity.java b/examples/snippets/src/main/java/verification/report/ReportByIdentity.java index 23d43e7cd..e095591de 100644 --- a/examples/snippets/src/main/java/verification/report/ReportByIdentity.java +++ b/examples/snippets/src/main/java/verification/report/ReportByIdentity.java @@ -8,7 +8,7 @@ package verification.report; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationReportService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsReportService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponse; @@ -38,7 +38,7 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationReportService verificationReportService = + VerificationsReportService verificationsReportService = client.verification().v1().verificationReport(); LOGGER.info(String.format("Report SMS verification code for phone number '%s'", phoneNumber)); @@ -47,7 +47,8 @@ public static void main(String[] args) { VerificationReportRequestSms.builder().setCode(receivedVerificationCode).build(); VerificationReportResponse response = - verificationReportService.reportSmsByIdentity(NumberIdentity.valueOf(phoneNumber), request); + verificationsReportService.reportSmsByIdentity( + NumberIdentity.valueOf(phoneNumber), request); LOGGER.info("Response: " + response); } diff --git a/examples/snippets/src/main/java/verification/start/Start.java b/examples/snippets/src/main/java/verification/start/Start.java index 030bfee60..d4def2da5 100644 --- a/examples/snippets/src/main/java/verification/start/Start.java +++ b/examples/snippets/src/main/java/verification/start/Start.java @@ -8,7 +8,7 @@ package verification.start; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationStartService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStartService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponse; @@ -36,7 +36,7 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationStartService verificationStartService = + VerificationsStartService verificationsStartService = client.verification().v1().verificationStart(); LOGGER.info(String.format("Start a verification by SMS onto phone number '%s'", phoneNumber)); @@ -46,7 +46,7 @@ public static void main(String[] args) { .setIdentity(NumberIdentity.valueOf(phoneNumber)) .build(); - VerificationStartResponse response = verificationStartService.startSms(request); + VerificationStartResponse response = verificationsStartService.startSms(request); LOGGER.info("Response: " + response); } diff --git a/examples/snippets/src/main/java/verification/status/GetById.java b/examples/snippets/src/main/java/verification/status/GetById.java index 4bfd79c6d..c8ef3e133 100644 --- a/examples/snippets/src/main/java/verification/status/GetById.java +++ b/examples/snippets/src/main/java/verification/status/GetById.java @@ -8,7 +8,7 @@ package verification.status; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationStatusService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; import com.sinch.sdk.models.Configuration; import java.util.logging.Logger; @@ -34,12 +34,12 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationStatusService verificationStatusService = + VerificationsStatusService verificationsStatusService = client.verification().v1().verificationStatus(); LOGGER.info(String.format("Verification status for verification ID '%s'", verificationId)); - VerificationStatusResponse response = verificationStatusService.getById(verificationId); + VerificationStatusResponse response = verificationsStatusService.getById(verificationId); LOGGER.info("Response: " + response); } diff --git a/examples/snippets/src/main/java/verification/status/GetByIdentity.java b/examples/snippets/src/main/java/verification/status/GetByIdentity.java index 921ecf393..a6ac13b69 100644 --- a/examples/snippets/src/main/java/verification/status/GetByIdentity.java +++ b/examples/snippets/src/main/java/verification/status/GetByIdentity.java @@ -8,7 +8,7 @@ package verification.status; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationStatusService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; @@ -39,7 +39,7 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationStatusService verificationStatusService = + VerificationsStatusService verificationsStatusService = client.verification().v1().verificationStatus(); LOGGER.info(String.format("Verification status for phone number '%s'", phoneNumber)); @@ -47,7 +47,7 @@ public static void main(String[] args) { NumberIdentity identity = NumberIdentity.valueOf(phoneNumber); VerificationStatusResponse response = - verificationStatusService.getByIdentity(identity, verificationMethod); + verificationsStatusService.getByIdentity(identity, verificationMethod); LOGGER.info("Response: " + response); } diff --git a/examples/snippets/src/main/java/verification/status/GetByReference.java b/examples/snippets/src/main/java/verification/status/GetByReference.java index 7d69837cd..0342895ba 100644 --- a/examples/snippets/src/main/java/verification/status/GetByReference.java +++ b/examples/snippets/src/main/java/verification/status/GetByReference.java @@ -8,7 +8,7 @@ package verification.status; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.VerificationStatusService; +import com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; import com.sinch.sdk.models.Configuration; import java.util.logging.Logger; @@ -34,7 +34,7 @@ public static void main(String[] args) { SinchClient client = new SinchClient(configuration); - VerificationStatusService verificationStatusService = + VerificationsStatusService verificationsStatusService = client.verification().v1().verificationStatus(); LOGGER.info( @@ -42,7 +42,7 @@ public static void main(String[] args) { "Verification status for verification with reference '%s'", verificationReference)); VerificationStatusResponse response = - verificationStatusService.getByReference(verificationReference); + verificationsStatusService.getByReference(verificationReference); LOGGER.info("Response: " + response); } diff --git a/examples/webhooks/src/main/java/com/mycompany/app/verification/Controller.java b/examples/webhooks/src/main/java/com/mycompany/app/verification/Controller.java index 8f1acc637..def882d81 100644 --- a/examples/webhooks/src/main/java/com/mycompany/app/verification/Controller.java +++ b/examples/webhooks/src/main/java/com/mycompany/app/verification/Controller.java @@ -1,7 +1,7 @@ package com.mycompany.app.verification; import com.sinch.sdk.SinchClient; -import com.sinch.sdk.domains.verification.api.v1.WebHooksService; +import com.sinch.sdk.domains.verification.api.v1.WebhooksService; import com.sinch.sdk.domains.verification.models.v1.webhooks.VerificationRequestEvent; import com.sinch.sdk.domains.verification.models.v1.webhooks.VerificationResultEvent; import com.sinch.sdk.domains.verification.models.v1.webhooks.VerificationSmsDeliveredEvent; @@ -37,7 +37,7 @@ public Controller(SinchClient sinchClient, ServerBusinessLogic webhooksBusinessL public ResponseEntity VerificationEvent( @RequestHeader Map headers, @RequestBody String body) { - WebHooksService webhooks = sinchClient.verification().v1().webhooks(); + WebhooksService webhooks = sinchClient.verification().v1().webhooks(); // ensure valid authentication to handle request // set this value to true to validate request from Sinch servers diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationBaseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationBaseTest.java index da867d730..eddb7c836 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationBaseTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationBaseTest.java @@ -6,6 +6,6 @@ public class VerificationBaseTest extends BaseTest { static { // faking a service init to trigger dedicated serializers initialization - VerificationService.LocalLazyInit.init(); + new com.sinch.sdk.domains.verification.api.v1.adapters.VerificationBaseTest(); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationBaseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationBaseTest.java new file mode 100644 index 000000000..eff9e44bd --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationBaseTest.java @@ -0,0 +1,11 @@ +package com.sinch.sdk.domains.verification.api.v1.adapters; + +import com.sinch.sdk.BaseTest; + +public class VerificationBaseTest extends BaseTest { + + static { + // faking a service init to trigger dedicated serializers initialization + VerificationService.LocalLazyInit.init(); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportRequestDtoTest.java index 89727239a..32ff2d5dd 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportRequestDtoTest.java @@ -5,14 +5,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.BaseTest; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCallImpl; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCallImpl; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSmsImpl; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsAppImpl; -import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestInternalImpl; import org.json.JSONException; import org.junit.jupiter.api.Test; import org.skyscreamer.jsonassert.JSONAssert; @@ -20,24 +15,17 @@ @TestWithResources public class VerificationReportRequestDtoTest extends BaseTest { - public static VerificationReportRequestInternalImpl verificationReportPhoneCallDto = - new VerificationReportRequestInternalImpl( - (VerificationReportRequestPhoneCallImpl) - VerificationReportRequestPhoneCall.builder().setCode("foo code").build()); - - public static VerificationReportRequestInternalImpl verificationReportFlashCallDto = - new VerificationReportRequestInternalImpl( - (VerificationReportRequestFlashCallImpl) - VerificationReportRequestFlashCall.builder().setCli("foo cli").build()); - public static VerificationReportRequestInternalImpl verificationReportSmsDto = - new VerificationReportRequestInternalImpl( - (VerificationReportRequestSmsImpl) - VerificationReportRequestSms.builder().setCode("foo code").build()); - - public static VerificationReportRequestInternalImpl verificationReportWhatsAppDto = - new VerificationReportRequestInternalImpl( - (VerificationReportRequestWhatsAppImpl) - VerificationReportRequestWhatsApp.builder().setCode("foo code").build()); + public static VerificationReportRequestPhoneCall verificationReportPhoneCallDto = + VerificationReportRequestPhoneCall.builder().setCode("foo code").build(); + + public static VerificationReportRequestFlashCall verificationReportFlashCallDto = + VerificationReportRequestFlashCall.builder().setCli("foo cli").build(); + + public static VerificationReportRequestSms verificationReportSmsDto = + VerificationReportRequestSms.builder().setCode("foo code").build(); + + public static VerificationReportRequestWhatsApp verificationReportWhatsAppDto = + VerificationReportRequestWhatsApp.builder().setCode("foo code").build(); @GivenTextResource("/domains/verification/v1/report/VerificationReportRequestPhoneCallDto.json") String jsonVerificationReportPhoneCall; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportResponseDtoTest.java index 1bebe2d3f..43cfd1da7 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/report/VerificationReportResponseDtoTest.java @@ -2,74 +2,61 @@ import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.verification.api.v1.adapters.VerificationBaseTest; import com.sinch.sdk.domains.verification.models.v1.VerificationStatus; import com.sinch.sdk.domains.verification.models.v1.VerificationStatusReason; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponse; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCallImpl; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCallImpl; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSmsImpl; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsAppImpl; -import com.sinch.sdk.domains.verification.models.v1.report.response.internal.VerificationReportResponseInternal; -import com.sinch.sdk.domains.verification.models.v1.report.response.internal.VerificationReportResponseInternalImpl; import org.junit.jupiter.api.Test; @TestWithResources -public class VerificationReportResponseDtoTest extends BaseTest { +public class VerificationReportResponseDtoTest extends VerificationBaseTest { @GivenJsonResource("/domains/verification/v1/report/VerificationReportResponsePhoneCallDto.json") - VerificationReportResponseInternal expectedVerificationReportPhoneCall; + VerificationReportResponse expectedVerificationReportPhoneCall; - public static VerificationReportResponseInternalImpl verificationReportPhoneCallDto = - new VerificationReportResponseInternalImpl( - (VerificationReportResponsePhoneCallImpl) - VerificationReportResponsePhoneCall.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.INVALID_CLI) - .setCallComplete(true) - .build()); + public static VerificationReportResponsePhoneCall verificationReportPhoneCallDto = + VerificationReportResponsePhoneCall.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.INVALID_CLI) + .setCallComplete(true) + .build(); @GivenJsonResource("/domains/verification/v1/report/VerificationReportResponseFlashCallDto.json") - VerificationReportResponseInternal expectedVerificationReportFlashCall; + VerificationReportResponse expectedVerificationReportFlashCall; - public static VerificationReportResponseInternalImpl verificationReportFlashCallDto = - new VerificationReportResponseInternalImpl( - (VerificationReportResponseFlashCallImpl) - VerificationReportResponseFlashCall.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.FRAUD) - .setCallComplete(true) - .build()); + public static VerificationReportResponseFlashCall verificationReportFlashCallDto = + VerificationReportResponseFlashCall.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.FRAUD) + .setCallComplete(true) + .build(); @GivenJsonResource("/domains/verification/v1/report/VerificationReportResponseSmsDto.json") - VerificationReportResponseInternal expectedVerificationReportSms; + VerificationReportResponse expectedVerificationReportSms; - public static VerificationReportResponseInternalImpl verificationReportSmsDto = - new VerificationReportResponseInternalImpl( - (VerificationReportResponseSmsImpl) - VerificationReportResponseSms.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.EXPIRED) - .build()); + public static VerificationReportResponseSms verificationReportSmsDto = + VerificationReportResponseSms.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.EXPIRED) + .build(); @GivenJsonResource("/domains/verification/v1/report/VerificationReportResponseWhatsAppDto.json") - VerificationReportResponseInternal expectedVerificationReportWhatsApp; + VerificationReportResponse expectedVerificationReportWhatsApp; - public static VerificationReportResponseInternalImpl verificationReportWhatsAppDto = - new VerificationReportResponseInternalImpl( - (VerificationReportResponseWhatsAppImpl) - VerificationReportResponseWhatsApp.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.EXPIRED) - .build()); + public static VerificationReportResponseWhatsApp verificationReportWhatsAppDto = + VerificationReportResponseWhatsApp.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.EXPIRED) + .build(); @Test void deserializePhoneCall() { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java index bad5a79d0..9fbc8f8b3 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/request/VerificationStartRequestTest.java @@ -9,13 +9,9 @@ import com.sinch.sdk.domains.verification.models.v1.WhatsAppCodeType; import com.sinch.sdk.domains.verification.models.v1.start.request.PhoneCallSpeech; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestDataImpl; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCallImpl; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCallImpl; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; -import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSmsImpl; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsApp; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsAppImpl; import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartRequestInternalImpl; @@ -26,60 +22,50 @@ @TestWithResources public class VerificationStartRequestTest extends VerificationBaseTest { - public static VerificationStartRequestInternalImpl startVerificationPhoneCallDto = - new VerificationStartRequestInternalImpl( - (VerificationStartRequestPhoneCallImpl) - VerificationStartRequestPhoneCall.builder() - .setCustom("a custom") - .setReference("a reference") - .setIdentity(NumberIdentity.valueOf("+endpoint")) - .setSpeech(PhoneCallSpeech.builder().setLocale("fr-FR").build()) - .putExtraOption("my key", "my value") - .build()); - - public static VerificationStartRequestInternalImpl startVerificationFlashCallDto = - new VerificationStartRequestInternalImpl( - (VerificationStartRequestFlashCallImpl) - VerificationStartRequestFlashCall.builder() - .setCustom("a custom") - .setReference("a reference") - .setIdentity(NumberIdentity.valueOf("+endpoint")) - .setDialTimeout(17) - .setInterceptionTimeout(23) - .putExtraOption("my key", "my value") - .build()); - public static VerificationStartRequestInternalImpl startVerificationDataDto = - new VerificationStartRequestInternalImpl( - (VerificationStartRequestDataImpl) - VerificationStartRequestData.builder() - .setCustom("a custom") - .setReference("a reference") - .setIdentity(NumberIdentity.valueOf("+endpoint")) - .build()); - public static VerificationStartRequestInternalImpl startVerificationSmsDto = - new VerificationStartRequestInternalImpl( - (VerificationStartRequestSmsImpl) - VerificationStartRequestSms.builder() - .setCustom("a custom") - .setReference("a reference") - .setIdentity(NumberIdentity.valueOf("+endpoint")) - .setExpiry("01:02:03") - .setCodeType(SmsCodeType.ALPHANUMERIC) - .putExtraOption("my key", "my value") - .build()); - - public static VerificationStartRequestInternalImpl startVerificationSmsDtoWithAcceptLanguage = - new VerificationStartRequestInternalImpl( - (VerificationStartRequestSmsImpl) - VerificationStartRequestSms.builder() - .setCustom("a custom") - .setReference("a reference") - .setIdentity(NumberIdentity.valueOf("+endpoint")) - .setExpiry("01:02:03") - .setCodeType(SmsCodeType.ALPHANUMERIC) - .setAcceptLanguage("es-ES") - .putExtraOption("my key", "my value") - .build()); + public static VerificationStartRequestPhoneCall startVerificationPhoneCallDto = + VerificationStartRequestPhoneCall.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.valueOf("+endpoint")) + .setSpeech(PhoneCallSpeech.builder().setLocale("fr-FR").build()) + .putExtraOption("my key", "my value") + .build(); + + public static VerificationStartRequestFlashCall startVerificationFlashCallDto = + VerificationStartRequestFlashCall.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.valueOf("+endpoint")) + .setDialTimeout(17) + .setInterceptionTimeout(23) + .putExtraOption("my key", "my value") + .build(); + public static VerificationStartRequestData startVerificationDataDto = + VerificationStartRequestData.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.valueOf("+endpoint")) + .build(); + public static VerificationStartRequestSms startVerificationSmsDto = + VerificationStartRequestSms.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.valueOf("+endpoint")) + .setExpiry("01:02:03") + .setCodeType(SmsCodeType.ALPHANUMERIC) + .putExtraOption("my key", "my value") + .build(); + + public static VerificationStartRequestSms startVerificationSmsDtoWithAcceptLanguage = + VerificationStartRequestSms.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.valueOf("+endpoint")) + .setExpiry("01:02:03") + .setCodeType(SmsCodeType.ALPHANUMERIC) + .setAcceptLanguage("es-ES") + .putExtraOption("my key", "my value") + .build(); public static VerificationStartRequestInternalImpl startVerificationWhatsAppDto = new VerificationStartRequestInternalImpl( diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java index 0b083ff70..a942c5001 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/start/response/VerificationStartResponseTest.java @@ -2,98 +2,82 @@ import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.verification.adapters.VerificationBaseTest; import com.sinch.sdk.domains.verification.models.dto.v1.start.LinkTest; import com.sinch.sdk.domains.verification.models.v1.SmsCodeType; import com.sinch.sdk.domains.verification.models.v1.WhatsAppCodeType; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponse; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseDataImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCallImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCallImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSmsImpl; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsAppImpl; -import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternal; -import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternalImpl; import org.junit.jupiter.api.Test; @TestWithResources -public class VerificationStartResponseTest extends BaseTest { +public class VerificationStartResponseTest extends VerificationBaseTest { @GivenJsonResource( "/domains/verification/v1/start/response/VerificationStartResponsePhoneCallDto.json") - VerificationStartResponseInternal loadedStartVerificationPhoneCallDto; + VerificationStartResponse loadedStartVerificationPhoneCallDto; - public static VerificationStartResponseInternalImpl expectedStartVerificationPhoneCallDto = - new VerificationStartResponseInternalImpl( - (VerificationStartResponsePhoneCallImpl) - VerificationStartResponsePhoneCall.builder() - .setId("the id") - .setLinks(LinkTest.expectedLinks) - .build()); + public static VerificationStartResponse expectedStartVerificationPhoneCallDto = + VerificationStartResponsePhoneCall.builder() + .setId("the id") + .setLinks(LinkTest.expectedLinks) + .build(); @GivenJsonResource( "/domains/verification/v1/start/response/VerificationStartResponseFlashCallDto.json") - VerificationStartResponseInternal loadedStartVerificationFlashCallDto; - - public static VerificationStartResponseInternalImpl expectedStartVerificationFlashCallDto = - new VerificationStartResponseInternalImpl( - (VerificationStartResponseFlashCallImpl) - VerificationStartResponseFlashCall.builder() - .setId("the id") - .setLinks(LinkTest.expectedLinks) - .setCliFilter("(.*)5312(.*)") - .setInterceptionTimeout(45) - .setReportTimeout(75) - .setDenyCallAfter(0) - .putExtraOption("my key", "my value") - .build()); + VerificationStartResponse loadedStartVerificationFlashCallDto; + + public static VerificationStartResponse expectedStartVerificationFlashCallDto = + VerificationStartResponseFlashCall.builder() + .setId("the id") + .setLinks(LinkTest.expectedLinks) + .setCliFilter("(.*)5312(.*)") + .setInterceptionTimeout(45) + .setReportTimeout(75) + .setDenyCallAfter(0) + .putExtraOption("my key", "my value") + .build(); @GivenJsonResource( "/domains/verification/v1/start/response/VerificationStartResponseDataDto.json") - VerificationStartResponseInternal loadedStartVerificationDataDto; + VerificationStartResponse loadedStartVerificationDataDto; - public static VerificationStartResponseInternalImpl expectedStartVerificationDataDto = - new VerificationStartResponseInternalImpl( - (VerificationStartResponseDataImpl) - VerificationStartResponseData.builder() - .setId("the id") - .setLinks(LinkTest.expectedLinks) - .setTargetUri("target URI") - .build()); + public static VerificationStartResponse expectedStartVerificationDataDto = + VerificationStartResponseData.builder() + .setId("the id") + .setLinks(LinkTest.expectedLinks) + .setTargetUri("target URI") + .build(); @GivenJsonResource("/domains/verification/v1/start/response/VerificationStartResponseSmsDto.json") - VerificationStartResponseInternal loadedStartVerificationSmsDto; - - public static VerificationStartResponseInternalImpl expectedStartVerificationSmsDto = - new VerificationStartResponseInternalImpl( - (VerificationStartResponseSmsImpl) - VerificationStartResponseSms.builder() - .setId("the id") - .setLinks(LinkTest.expectedLinks) - .setTemplate("Your verification code is {{CODE}}. Verified by Sinch") - .setInterceptionTimeout(298) - .setCodeType(SmsCodeType.NUMERIC) - .putExtraOption("my key", "my value") - .build()); + VerificationStartResponse loadedStartVerificationSmsDto; + + public static VerificationStartResponse expectedStartVerificationSmsDto = + VerificationStartResponseSms.builder() + .setId("the id") + .setLinks(LinkTest.expectedLinks) + .setTemplate("Your verification code is {{CODE}}. Verified by Sinch") + .setInterceptionTimeout(298) + .setCodeType(SmsCodeType.NUMERIC) + .putExtraOption("my key", "my value") + .build(); @GivenJsonResource( "/domains/verification/v1/start/response/VerificationStartResponseWhatsAppDto.json") - VerificationStartResponseInternal loadedStartVerificationWhatsAppDto; - - public static VerificationStartResponseInternalImpl expectedStartVerificationWhatsAppDto = - new VerificationStartResponseInternalImpl( - (VerificationStartResponseWhatsAppImpl) - VerificationStartResponseWhatsApp.builder() - .setId("the id") - .setLinks(LinkTest.expectedLinks) - .setCodeType(WhatsAppCodeType.NUMERIC) - .putExtraOption("my key", "my value") - .build()); + VerificationStartResponse loadedStartVerificationWhatsAppDto; + + public static VerificationStartResponse expectedStartVerificationWhatsAppDto = + VerificationStartResponseWhatsApp.builder() + .setId("the id") + .setLinks(LinkTest.expectedLinks) + .setCodeType(WhatsAppCodeType.NUMERIC) + .putExtraOption("my key", "my value") + .build(); @Test void deserializeStartPhoneCall() { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/status/VerificationStatusResponseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/status/VerificationStatusResponseTest.java index 3fc78a91a..be197d0b8 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/status/VerificationStatusResponseTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/status/VerificationStatusResponseTest.java @@ -12,138 +12,125 @@ import com.sinch.sdk.domains.verification.models.v1.status.StatusCallResult; import com.sinch.sdk.domains.verification.models.v1.status.StatusPrice; import com.sinch.sdk.domains.verification.models.v1.status.StatusSource; +import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseFlashCall; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseFlashCallImpl; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponsePhoneCall; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponsePhoneCallImpl; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseSms; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseSmsImpl; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseSmsPrice; import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseWhatsApp; -import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponseWhatsAppImpl; -import com.sinch.sdk.domains.verification.models.v1.status.response.internal.VerificationStatusResponseInternal; -import com.sinch.sdk.domains.verification.models.v1.status.response.internal.VerificationStatusResponseInternalImpl; import org.junit.jupiter.api.Test; @TestWithResources public class VerificationStatusResponseTest extends VerificationBaseTest { - public static VerificationStatusResponseInternalImpl expectedVerificationPhoneCallDto = - new VerificationStatusResponseInternalImpl( - (VerificationStatusResponsePhoneCallImpl) - VerificationStatusResponsePhoneCall.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.FRAUD) - .setCallComplete(true) - .setReference("my reference") - .setPrice( - StatusPrice.builder() - .setVerificationPrice( - Price.builder() - .setCurrencyId("verificationPrice currency id") - .setAmount(3.141516F) - .build()) - .setTerminationPrice( - Price.builder() - .setCurrencyId("terminationPrice currency id") - .setAmount(6.626070F) - .build()) - .setBillableDuration(34) + public static VerificationStatusResponse expectedVerificationPhoneCallDto = + VerificationStatusResponsePhoneCall.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.FRAUD) + .setCallComplete(true) + .setReference("my reference") + .setPrice( + StatusPrice.builder() + .setVerificationPrice( + Price.builder() + .setCurrencyId("verificationPrice currency id") + .setAmount(3.141516F) .build()) - .setIdentity(NumberIdentity.valueOf("endpoint value")) - .setCountryId("ES") - .setVerificationTimestamp( - DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) - .setCallResult(StatusCallResult.ANSWERED) - .build()); - public static VerificationStatusResponseInternalImpl expectedVerificationFlashCallDto = - new VerificationStatusResponseInternalImpl( - (VerificationStatusResponseFlashCallImpl) - VerificationStatusResponseFlashCall.builder() - .setId("the id") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.FRAUD) - .setReference("my reference") - .setPrice( - StatusPrice.builder() - .setVerificationPrice( - Price.builder() - .setCurrencyId("verificationPrice currency id") - .setAmount(3.141516F) - .build()) - .setTerminationPrice( - Price.builder() - .setCurrencyId("terminationPrice currency id") - .setAmount(6.626070F) - .build()) - .setBillableDuration(34) + .setTerminationPrice( + Price.builder() + .setCurrencyId("terminationPrice currency id") + .setAmount(6.626070F) .build()) - .setSource(StatusSource.MANUAL) - .setIdentity(NumberIdentity.valueOf("endpoint value")) - .setCountryId("ES") - .setVerificationTimestamp( - DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) - .setCallComplete(false) - .setCallResult(StatusCallResult.ANSWERED) - .build()); - public static VerificationStatusResponseInternalImpl expectedVerificationSmsDto = - new VerificationStatusResponseInternalImpl( - (VerificationStatusResponseSmsImpl) - VerificationStatusResponseSms.builder() - .setId("the id") - .setReference("my reference") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.FRAUD) - .setSource(StatusSource.INTERCEPTED) - .setPrice( - VerificationStatusResponseSmsPrice.builder() - .setVerificationPrice( - Price.builder() - .setCurrencyId("verificationPrice currency id") - .setAmount(3.141516F) - .build()) + .setBillableDuration(34) + .build()) + .setIdentity(NumberIdentity.valueOf("endpoint value")) + .setCountryId("ES") + .setVerificationTimestamp( + DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) + .setCallResult(StatusCallResult.ANSWERED) + .build(); + public static VerificationStatusResponse expectedVerificationFlashCallDto = + VerificationStatusResponseFlashCall.builder() + .setId("the id") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.FRAUD) + .setReference("my reference") + .setPrice( + StatusPrice.builder() + .setVerificationPrice( + Price.builder() + .setCurrencyId("verificationPrice currency id") + .setAmount(3.141516F) .build()) - .setIdentity(NumberIdentity.valueOf("endpoint value")) - .setCountryId("ES") - .setVerificationTimestamp( - DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) - .build()); + .setTerminationPrice( + Price.builder() + .setCurrencyId("terminationPrice currency id") + .setAmount(6.626070F) + .build()) + .setBillableDuration(34) + .build()) + .setSource(StatusSource.MANUAL) + .setIdentity(NumberIdentity.valueOf("endpoint value")) + .setCountryId("ES") + .setVerificationTimestamp( + DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) + .setCallComplete(false) + .setCallResult(StatusCallResult.ANSWERED) + .build(); + public static VerificationStatusResponse expectedVerificationSmsDto = + VerificationStatusResponseSms.builder() + .setId("the id") + .setReference("my reference") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.FRAUD) + .setSource(StatusSource.INTERCEPTED) + .setPrice( + VerificationStatusResponseSmsPrice.builder() + .setVerificationPrice( + Price.builder() + .setCurrencyId("verificationPrice currency id") + .setAmount(3.141516F) + .build()) + .build()) + .setIdentity(NumberIdentity.valueOf("endpoint value")) + .setCountryId("ES") + .setVerificationTimestamp( + DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) + .build(); - public static VerificationStatusResponseInternalImpl expectedVerificationWhatsAppDto = - new VerificationStatusResponseInternalImpl( - (VerificationStatusResponseWhatsAppImpl) - VerificationStatusResponseWhatsApp.builder() - .setId("the id") - .setReference("my reference") - .setStatus(VerificationStatus.FAIL) - .setReason(VerificationStatusReason.FRAUD) - .setSource(StatusSource.INTERCEPTED) - .setPrice( - VerificationStatusResponseSmsPrice.builder() - .setVerificationPrice( - Price.builder() - .setCurrencyId("verificationPrice currency id") - .setAmount(3.141516F) - .build()) + public static VerificationStatusResponse expectedVerificationWhatsAppDto = + VerificationStatusResponseWhatsApp.builder() + .setId("the id") + .setReference("my reference") + .setStatus(VerificationStatus.FAIL) + .setReason(VerificationStatusReason.FRAUD) + .setSource(StatusSource.INTERCEPTED) + .setPrice( + VerificationStatusResponseSmsPrice.builder() + .setVerificationPrice( + Price.builder() + .setCurrencyId("verificationPrice currency id") + .setAmount(3.141516F) .build()) - .setIdentity(NumberIdentity.valueOf("+33123456789")) - .setCountryId("ES") - .setVerificationTimestamp( - DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) - .build()); + .build()) + .setIdentity(NumberIdentity.valueOf("+33123456789")) + .setCountryId("ES") + .setVerificationTimestamp( + DateUtil.failSafeTimeStampToInstant("2024-05-22T09:38:59.5590437")) + .build(); @GivenJsonResource("/domains/verification/v1/status/VerificationStatusResponsePhoneCallDto.json") - VerificationStatusResponseInternal loadedVerificationPhoneCallDto; + VerificationStatusResponse loadedVerificationPhoneCallDto; @GivenJsonResource("/domains/verification/v1/status/VerificationStatusResponseFlashCallDto.json") - VerificationStatusResponseInternal loadedVerificationFlashCallDto; + VerificationStatusResponse loadedVerificationFlashCallDto; @GivenJsonResource("/domains/verification/v1/status/VerificationStatusResponseSmsDto.json") - VerificationStatusResponseInternal loadedVerificationSmsDto; + VerificationStatusResponse loadedVerificationSmsDto; @GivenJsonResource("/domains/verification/v1/status/VerificationStatusResponseWhatsAppDto.json") - VerificationStatusResponseInternal loadedVerificationWhatsAppDto; + VerificationStatusResponse loadedVerificationWhatsAppDto; @Test void deserializePhoneCall() { From 4d4aeeae3de3ed0fbb920c082aab733e9173d449 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 13 Feb 2026 10:28:28 +0100 Subject: [PATCH 2/6] feat (Verification): Remove adaptor layer for Verification API (generated sources) --- .../api/v1/VerificationsReportService.java | 136 ++++++++++++++ .../api/v1/VerificationsStartService.java | 72 ++++++++ .../api/v1/VerificationsStatusService.java | 56 ++++++ .../VerificationsReportServiceImpl.java} | 172 +++++++++++------- .../VerificationsStartServiceImpl.java | 171 +++++++++++++++++ .../VerificationsStatusServiceImpl.java} | 121 +++++------- .../v1/internal/VerificationsStartApi.java | 135 -------------- 7 files changed, 587 insertions(+), 276 deletions(-) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsReportService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStartService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStatusService.java rename openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/{internal/VerificationsReportApi.java => adapters/VerificationsReportServiceImpl.java} (51%) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStartServiceImpl.java rename openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/{internal/VerificationStatusApi.java => adapters/VerificationsStatusServiceImpl.java} (61%) delete mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsStartApi.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsReportService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsReportService.java new file mode 100644 index 000000000..be11976ba --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsReportService.java @@ -0,0 +1,136 @@ +/* + * Verification | Sinch + * + * OpenAPI document version: 2.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.verification.api.v1; + +import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsApp; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; + +/** Verifications report Service */ +public interface VerificationsReportService { + + /** + * Report a verification using {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#SMS} & Identity + * + *

Report the received verification code to verify it, using the identity of the user + * + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponseSms reportSmsByIdentity( + NumberIdentity identity, VerificationReportRequestSms parameters); + + /** + * Report a verification using {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#FLASH_CALL} & Identity + * + *

Report the received verification code to verify it, using the identity of the user + * + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponseFlashCall reportFlashCallByIdentity( + NumberIdentity identity, VerificationReportRequestFlashCall parameters); + + /** + * Report a verification using {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#PHONE_CALL} & Identity + * + *

Report the received verification code to verify it, using the identity of the user + * + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponsePhoneCall reportPhoneCallByIdentity( + NumberIdentity identity, VerificationReportRequestPhoneCall parameters); + + /** + * Report a verification using {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#WHATSAPP} & Identity + * + *

Report the received verification code to verify it, using the identity of the user + * + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.v1.NumberIdentity NumberIdentity} is supported + * @param parameters Parameters to be used to get report + * @return Verification report response + * @apiNote This is a BETA feature and can be changed before GA + * @since 2.0 + */ + VerificationReportResponseWhatsApp reportWhatsAppByIdentity( + NumberIdentity identity, VerificationReportRequestWhatsApp parameters); + + /** + * Report the received verification code to verify it, using the Verification ID of the {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#SMS} Verification request + * + * @param id ID returned from start verification + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponseSms reportSmsById(String id, VerificationReportRequestSms parameters); + + /** + * Report the received verification code to verify it, using the Verification ID of the {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#FLASH_CALL} Verification + * request + * + * @param id ID returned from start verification + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponseFlashCall reportFlashCallById( + String id, VerificationReportRequestFlashCall parameters); + + /** + * Report the received verification code to verify it, using the Verification ID of the {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#PHONE_CALL} Verification + * request + * + * @param id ID returned from start verification + * @param parameters Parameters to be used to get report + * @return Verification report response + * @since 1.1 + */ + VerificationReportResponsePhoneCall reportPhoneCallById( + String id, VerificationReportRequestPhoneCall parameters); + + /** + * Report the received verification code to verify it, using the Verification ID of the {@link + * com.sinch.sdk.domains.verification.models.v1.VerificationMethod#WHATSAPP} Verification request + * + * @param id ID returned from start verification + * @param parameters Parameters to be used to get report + * @return Verification report response + * @apiNote This is a BETA feature and can be changed before GA + * @since 2.0 + */ + VerificationReportResponseWhatsApp reportWhatsAppById( + String id, VerificationReportRequestWhatsApp parameters); +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStartService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStartService.java new file mode 100644 index 000000000..50aa64981 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStartService.java @@ -0,0 +1,72 @@ +/* + * Verification | Sinch + * + * OpenAPI document version: 2.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.verification.api.v1; + +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsApp; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; + +/** Verifications start Service */ +public interface VerificationsStartService { + + /** + * Start verification by SMS + * + * @param parameters Parameters to be used to start verification + * @return Verification response + * @since 1.1 + */ + VerificationStartResponseSms startSms(VerificationStartRequestSms parameters); + + /** + * Start verification by FLASH_CALL + * + * @param parameters Parameters to be used to start verification + * @return Verification response + * @since 1.1 + */ + VerificationStartResponseFlashCall startFlashCall(VerificationStartRequestFlashCall parameters); + + /** + * Start verification by PHONE_CALL + * + * @param parameters Parameters to be used to start verification + * @return Verification response + * @since 1.1 + */ + VerificationStartResponsePhoneCall startPhoneCall(VerificationStartRequestPhoneCall parameters); + + /** + * Start verification by DATA + * + * @param parameters Parameters to be used to start verification + * @return Verification response + * @since 1.1 + */ + VerificationStartResponseData startData(VerificationStartRequestData parameters); + + /** + * Start verification by WhatsApp + * + * @apiNote This is a BETA feature and can be changed before GA + * @param parameters Parameters to be used to start verification + * @return Verification response + * @since 2.0 + */ + VerificationStartResponseWhatsApp startWhatsApp(VerificationStartRequestWhatsApp parameters); +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStatusService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStatusService.java new file mode 100644 index 000000000..af809845b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/VerificationsStatusService.java @@ -0,0 +1,56 @@ +/* + * Verification | Sinch + * + * OpenAPI document version: 2.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.verification.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; +import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; +import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; + +/** VerificationsStatus Service */ +public interface VerificationsStatusService { + + /** + * Get verification by ID + * + *

Queries the verification result by sending the verification ID. With this query you can get + * the result of a verification. + * + * @param id The ID of the verification. (required) + * @return VerificationStatusResponse + * @throws ApiException if fails to make API call + */ + VerificationStatusResponse getById(String id) throws ApiException; + + /** + * Queries the verification result by sending the verification Identity (usually a phone number) + * and its method. With this query you can get the result of a verification. + * + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.v1.NumberIdentity} is supported + * @param method Method used for verification + * @return Verification status response + * @since 1.1 + */ + VerificationStatusResponse getByIdentity(NumberIdentity identity, VerificationMethod method); + + /** + * Get verification by Reference + * + *

Queries the verification result by sending the verification Reference. With this query you + * can get the result of a verification. + * + * @param reference The custom reference of the verification. (required) + * @return VerificationStatusResponse + * @throws ApiException if fails to make API call + */ + VerificationStatusResponse getByReference(String reference) throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsReportApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsReportServiceImpl.java similarity index 51% rename from openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsReportApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsReportServiceImpl.java index 328e2c422..0178a78b8 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsReportApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsReportServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.verification.api.v1.internal; +package com.sinch.sdk.domains.verification.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -23,8 +23,17 @@ 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.verification.models.v1.report.request.internal.VerificationReportRequestInternal; -import com.sinch.sdk.domains.verification.models.v1.report.response.internal.VerificationReportResponseInternal; +import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequest; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; +import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestWhatsApp; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponse; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseFlashCall; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponsePhoneCall; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; +import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseWhatsApp; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -33,15 +42,17 @@ import java.util.Map; import java.util.logging.Logger; -public class VerificationsReportApi { +public class VerificationsReportServiceImpl + implements com.sinch.sdk.domains.verification.api.v1.VerificationsReportService { - private static final Logger LOGGER = Logger.getLogger(VerificationsReportApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = + Logger.getLogger(VerificationsReportServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public VerificationsReportApi( + public VerificationsReportServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -52,18 +63,8 @@ public VerificationsReportApi( this.mapper = mapper; } - /** - * Report a verification with ID Report the received verification code to verify it, using the - * Verification ID of the Verification request. - * - * @param id The ID of the verification. (required) - * @param verificationReportRequestInternal (required) - * @return VerificationReportResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationReportResponseInternal reportVerificationById( - String id, VerificationReportRequestInternal verificationReportRequestInternal) - throws ApiException { + private VerificationReportResponse reportVerificationById( + String id, VerificationReportRequest verificationReportRequest) throws ApiException { LOGGER.finest( "[reportVerificationById]" @@ -71,19 +72,16 @@ public VerificationReportResponseInternal reportVerificationById( + "id: " + id + ", " - + "verificationReportRequestInternal: " - + verificationReportRequestInternal); + + "verificationReportRequest: " + + verificationReportRequest); - HttpRequest httpRequest = - reportVerificationByIdRequestBuilder(id, verificationReportRequestInternal); + HttpRequest httpRequest = reportVerificationByIdRequestBuilder(id, verificationReportRequest); 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 @@ -95,18 +93,17 @@ public VerificationReportResponseInternal reportVerificationById( } private HttpRequest reportVerificationByIdRequestBuilder( - String id, VerificationReportRequestInternal verificationReportRequestInternal) - throws ApiException { + String id, VerificationReportRequest verificationReportRequest) throws ApiException { // verify the required parameter 'id' is set if (id == null) { throw new ApiException( 400, "Missing the required parameter 'id' when calling reportVerificationById"); } - // verify the required parameter 'verificationReportRequestInternal' is set - if (verificationReportRequestInternal == null) { + // verify the required parameter 'verificationReportRequest' is set + if (verificationReportRequest == null) { throw new ApiException( 400, - "Missing the required parameter 'verificationReportRequestInternal' when calling" + "Missing the required parameter 'verificationReportRequest' when calling" + " reportVerificationById"); } @@ -123,8 +120,7 @@ private HttpRequest reportVerificationByIdRequestBuilder( final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "Application"); - final String serializedBody = - mapper.serialize(localVarContentTypes, verificationReportRequestInternal); + final String serializedBody = mapper.serialize(localVarContentTypes, verificationReportRequest); return new HttpRequest( localVarPath, @@ -137,21 +133,8 @@ private HttpRequest reportVerificationByIdRequestBuilder( localVarAuthNames); } - /** - * Report a verification using Identity Report the received verification code to verify it, using - * the identity of the user (in most cases, the phone number). For an SMS verification or Phone - * Call verification, this is the OTP code. For FlashCall, this is the CLI. - * - * @param endpoint For type `number` use a - * [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537)-compatible phone number. - * (required) - * @param verificationReportRequestInternal (required) - * @return VerificationReportResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationReportResponseInternal reportVerificationByIdentity( - String endpoint, VerificationReportRequestInternal verificationReportRequestInternal) - throws ApiException { + private VerificationReportResponse reportVerificationByIdentity( + String endpoint, VerificationReportRequest verificationReportRequest) throws ApiException { LOGGER.finest( "[reportVerificationByIdentity]" @@ -159,19 +142,17 @@ public VerificationReportResponseInternal reportVerificationByIdentity( + "endpoint: " + endpoint + ", " - + "verificationReportRequestInternal: " - + verificationReportRequestInternal); + + "verificationReportRequest: " + + verificationReportRequest); HttpRequest httpRequest = - reportVerificationByIdentityRequestBuilder(endpoint, verificationReportRequestInternal); + reportVerificationByIdentityRequestBuilder(endpoint, verificationReportRequest); 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 @@ -183,19 +164,18 @@ public VerificationReportResponseInternal reportVerificationByIdentity( } private HttpRequest reportVerificationByIdentityRequestBuilder( - String endpoint, VerificationReportRequestInternal verificationReportRequestInternal) - throws ApiException { + String endpoint, VerificationReportRequest verificationReportRequest) throws ApiException { // verify the required parameter 'endpoint' is set if (endpoint == null) { throw new ApiException( 400, "Missing the required parameter 'endpoint' when calling reportVerificationByIdentity"); } - // verify the required parameter 'verificationReportRequestInternal' is set - if (verificationReportRequestInternal == null) { + // verify the required parameter 'verificationReportRequest' is set + if (verificationReportRequest == null) { throw new ApiException( 400, - "Missing the required parameter 'verificationReportRequestInternal' when calling" + "Missing the required parameter 'verificationReportRequest' when calling" + " reportVerificationByIdentity"); } @@ -213,8 +193,7 @@ private HttpRequest reportVerificationByIdentityRequestBuilder( final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "Application"); - final String serializedBody = - mapper.serialize(localVarContentTypes, verificationReportRequestInternal); + final String serializedBody = mapper.serialize(localVarContentTypes, verificationReportRequest); return new HttpRequest( localVarPath, @@ -226,4 +205,69 @@ private HttpRequest reportVerificationByIdentityRequestBuilder( localVarContentTypes, localVarAuthNames); } + + @Override + public VerificationReportResponseSms reportSmsByIdentity( + NumberIdentity identity, VerificationReportRequestSms parameters) { + + return (VerificationReportResponseSms) reportByIdentity(identity, parameters); + } + + @Override + public VerificationReportResponseFlashCall reportFlashCallByIdentity( + NumberIdentity identity, VerificationReportRequestFlashCall parameters) { + + return (VerificationReportResponseFlashCall) reportByIdentity(identity, parameters); + } + + @Override + public VerificationReportResponsePhoneCall reportPhoneCallByIdentity( + NumberIdentity identity, VerificationReportRequestPhoneCall parameters) { + + return (VerificationReportResponsePhoneCall) reportByIdentity(identity, parameters); + } + + @Override + public VerificationReportResponseWhatsApp reportWhatsAppByIdentity( + NumberIdentity identity, VerificationReportRequestWhatsApp parameters) { + + return (VerificationReportResponseWhatsApp) reportByIdentity(identity, parameters); + } + + @Override + public VerificationReportResponseSms reportSmsById( + String id, VerificationReportRequestSms parameters) { + + return (VerificationReportResponseSms) reportById(id, parameters); + } + + @Override + public VerificationReportResponseFlashCall reportFlashCallById( + String id, VerificationReportRequestFlashCall parameters) { + + return (VerificationReportResponseFlashCall) reportById(id, parameters); + } + + @Override + public VerificationReportResponsePhoneCall reportPhoneCallById( + String id, VerificationReportRequestPhoneCall parameters) { + + return (VerificationReportResponsePhoneCall) reportById(id, parameters); + } + + @Override + public VerificationReportResponseWhatsApp reportWhatsAppById( + String id, VerificationReportRequestWhatsApp parameters) { + + return (VerificationReportResponseWhatsApp) reportById(id, parameters); + } + + private VerificationReportResponse reportByIdentity( + NumberIdentity identity, VerificationReportRequest parameters) { + return reportVerificationByIdentity(identity.getEndpoint(), parameters); + } + + private VerificationReportResponse reportById(String id, VerificationReportRequest parameters) { + return reportVerificationById(id, parameters); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStartServiceImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStartServiceImpl.java new file mode 100644 index 000000000..d65c43483 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStartServiceImpl.java @@ -0,0 +1,171 @@ +/* + * Verification | Sinch + * + * OpenAPI document version: 2.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.verification.api.v1.adapters; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +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.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +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.verification.models.v1.start.request.VerificationStartRequest; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; +import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestWhatsApp; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponse; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseData; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseFlashCall; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponsePhoneCall; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; +import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseWhatsApp; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.logging.Logger; + +public class VerificationsStartServiceImpl + implements com.sinch.sdk.domains.verification.api.v1.VerificationsStartService { + + private static final Logger LOGGER = + Logger.getLogger(VerificationsStartServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; + + public VerificationsStartServiceImpl( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + } + + private VerificationStartResponse startVerification( + String acceptLanguage, VerificationStartRequest verificationStartRequest) + throws ApiException { + + LOGGER.finest( + "[startVerification]" + + " " + + "acceptLanguage: " + + acceptLanguage + + ", " + + "verificationStartRequest: " + + verificationStartRequest); + + HttpRequest httpRequest = + startVerificationRequestBuilder(acceptLanguage, verificationStartRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + 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 + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest startVerificationRequestBuilder( + String acceptLanguage, VerificationStartRequest verificationStartRequest) + throws ApiException { + // verify the required parameter 'verificationStartRequest' is set + if (verificationStartRequest == null) { + throw new ApiException( + 400, + "Missing the required parameter 'verificationStartRequest' when calling" + + " startVerification"); + } + + String localVarPath = "/verification/v1/verifications"; + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + if (acceptLanguage != null) localVarHeaderParams.put("Accept-Language", acceptLanguage); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("Basic", "Application"); + final String serializedBody = mapper.serialize(localVarContentTypes, verificationStartRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + @Override + public VerificationStartResponseSms startSms(VerificationStartRequestSms parameters) { + String acceptLanguage = parameters.getAcceptLanguage(); + return (VerificationStartResponseSms) start(parameters, acceptLanguage).orElse(null); + } + + @Override + public VerificationStartResponseFlashCall startFlashCall( + VerificationStartRequestFlashCall parameters) { + return (VerificationStartResponseFlashCall) start(parameters).orElse(null); + } + + @Override + public VerificationStartResponsePhoneCall startPhoneCall( + VerificationStartRequestPhoneCall parameters) { + return (VerificationStartResponsePhoneCall) start(parameters).orElse(null); + } + + @Override + public VerificationStartResponseData startData(VerificationStartRequestData parameters) { + return (VerificationStartResponseData) start(parameters).orElse(null); + } + + @Override + public VerificationStartResponseWhatsApp startWhatsApp( + VerificationStartRequestWhatsApp parameters) { + return (VerificationStartResponseWhatsApp) start(parameters).orElse(null); + } + + private Optional start(VerificationStartRequest parameters) { + return start(parameters, null); + } + + private Optional start( + VerificationStartRequest parameters, String acceptLanguage) { + return Optional.ofNullable(startVerification(acceptLanguage, parameters)); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationStatusApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStatusServiceImpl.java similarity index 61% rename from openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationStatusApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStatusServiceImpl.java index f0a69f848..683a82127 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationStatusApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/adapters/VerificationsStatusServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.verification.api.v1.internal; +package com.sinch.sdk.domains.verification.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.verification.models.v1.status.response.internal.VerificationStatusResponseInternal; +import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; +import com.sinch.sdk.domains.verification.models.v1.VerificationMethod; +import com.sinch.sdk.domains.verification.models.v1.status.response.VerificationStatusResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -32,15 +34,17 @@ import java.util.Map; import java.util.logging.Logger; -public class VerificationStatusApi { +public class VerificationsStatusServiceImpl + implements com.sinch.sdk.domains.verification.api.v1.VerificationsStatusService { - private static final Logger LOGGER = Logger.getLogger(VerificationStatusApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = + Logger.getLogger(VerificationsStatusServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; - public VerificationStatusApi( + public VerificationsStatusServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -51,27 +55,18 @@ public VerificationStatusApi( this.mapper = mapper; } - /** - * Get verification by ID Queries the verification result by sending the verification ID. With - * this query you can get the result of a verification. - * - * @param id The ID of the verification. (required) - * @return VerificationStatusResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationStatusResponseInternal verificationStatusById(String id) throws ApiException { + @Override + public VerificationStatusResponse getById(String id) throws ApiException { - LOGGER.finest("[verificationStatusById]" + " " + "id: " + id); + LOGGER.finest("[getById]" + " " + "id: " + id); - HttpRequest httpRequest = verificationStatusByIdRequestBuilder(id); + HttpRequest httpRequest = getByIdRequestBuilder(id); 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 @@ -82,11 +77,10 @@ public VerificationStatusResponseInternal verificationStatusById(String id) thro mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest verificationStatusByIdRequestBuilder(String id) throws ApiException { + private HttpRequest getByIdRequestBuilder(String id) throws ApiException { // verify the required parameter 'id' is set if (id == null) { - throw new ApiException( - 400, "Missing the required parameter 'id' when calling verificationStatusById"); + throw new ApiException(400, "Missing the required parameter 'id' when calling getById"); } String localVarPath = @@ -115,39 +109,25 @@ private HttpRequest verificationStatusByIdRequestBuilder(String id) throws ApiEx localVarAuthNames); } - /** - * Get verification by Identity Queries the verification result by sending the verification - * Identity (usually a phone number) and its method. With this query you can get the result of a - * verification. - * - * @param endpoint For type `number` use a - * [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537)-compatible phone number. - * (required) - * @param method The method of the verification. (required) - * @return VerificationStatusResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationStatusResponseInternal verificationStatusByIdentity( - String endpoint, String method) throws ApiException { - - LOGGER.finest( - "[verificationStatusByIdentity]" - + " " - + "endpoint: " - + endpoint - + ", " - + "method: " - + method); - - HttpRequest httpRequest = verificationStatusByIdentityRequestBuilder(endpoint, method); + @Override + public VerificationStatusResponse getByIdentity( + NumberIdentity identity, VerificationMethod method) { + + return getByIdentity(identity.getEndpoint(), method.value()); + } + + private VerificationStatusResponse getByIdentity(String endpoint, String method) + throws ApiException { + + LOGGER.finest("[getByIdentity]" + " " + "endpoint: " + endpoint + ", " + "method: " + method); + + HttpRequest httpRequest = getByIdentityRequestBuilder(endpoint, method); 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 @@ -158,18 +138,17 @@ public VerificationStatusResponseInternal verificationStatusByIdentity( mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest verificationStatusByIdentityRequestBuilder(String endpoint, String method) + private HttpRequest getByIdentityRequestBuilder(String endpoint, String method) throws ApiException { // verify the required parameter 'endpoint' is set if (endpoint == null) { throw new ApiException( - 400, - "Missing the required parameter 'endpoint' when calling verificationStatusByIdentity"); + 400, "Missing the required parameter 'endpoint' when calling getByIdentity"); } // verify the required parameter 'method' is set if (method == null) { throw new ApiException( - 400, "Missing the required parameter 'method' when calling verificationStatusByIdentity"); + 400, "Missing the required parameter 'method' when calling getByIdentity"); } String localVarPath = @@ -201,28 +180,18 @@ private HttpRequest verificationStatusByIdentityRequestBuilder(String endpoint, localVarAuthNames); } - /** - * Get verification by Reference Queries the verification result by sending the verification - * Reference. With this query you can get the result of a verification. - * - * @param reference The custom reference of the verification. (required) - * @return VerificationStatusResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationStatusResponseInternal verificationStatusByReference(String reference) - throws ApiException { + @Override + public VerificationStatusResponse getByReference(String reference) throws ApiException { - LOGGER.finest("[verificationStatusByReference]" + " " + "reference: " + reference); + LOGGER.finest("[getByReference]" + " " + "reference: " + reference); - HttpRequest httpRequest = verificationStatusByReferenceRequestBuilder(reference); + HttpRequest httpRequest = getByReferenceRequestBuilder(reference); 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 @@ -233,13 +202,11 @@ public VerificationStatusResponseInternal verificationStatusByReference(String r mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest verificationStatusByReferenceRequestBuilder(String reference) - throws ApiException { + private HttpRequest getByReferenceRequestBuilder(String reference) throws ApiException { // verify the required parameter 'reference' is set if (reference == null) { throw new ApiException( - 400, - "Missing the required parameter 'reference' when calling verificationStatusByReference"); + 400, "Missing the required parameter 'reference' when calling getByReference"); } String localVarPath = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsStartApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsStartApi.java deleted file mode 100644 index 4a9f036b5..000000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/api/v1/internal/VerificationsStartApi.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Verification | Sinch - * - * OpenAPI document version: 2.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.verification.api.v1.internal; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; -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.http.HttpMethod; -import com.sinch.sdk.core.http.HttpRequest; -import com.sinch.sdk.core.http.HttpResponse; -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.verification.models.v1.start.request.internal.VerificationStartRequestInternal; -import com.sinch.sdk.domains.verification.models.v1.start.response.internal.VerificationStartResponseInternal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -public class VerificationsStartApi { - - private static final Logger LOGGER = Logger.getLogger(VerificationsStartApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; - - public VerificationsStartApi( - HttpClient httpClient, - ServerConfiguration serverConfiguration, - Map authManagersByOasSecuritySchemes, - HttpMapper mapper) { - this.httpClient = httpClient; - this.serverConfiguration = serverConfiguration; - this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; - this.mapper = mapper; - } - - /** - * Start verification This method is used by the mobile and web Verification SDKs to start a - * verification. It can also be used to request a verification from your backend, by making an - * request. - * - * @param verificationStartRequestInternal (required) - * @param acceptLanguage In SMS Verification, value of - * [Accept-Language](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) - * header is used to determine the language of an SMS message. (optional) - * @return VerificationStartResponseInternal - * @throws ApiException if fails to make API call - */ - public VerificationStartResponseInternal startVerification( - VerificationStartRequestInternal verificationStartRequestInternal, String acceptLanguage) - throws ApiException { - - LOGGER.finest( - "[startVerification]" - + " " - + "verificationStartRequestInternal: " - + verificationStartRequestInternal - + ", " - + "acceptLanguage: " - + acceptLanguage); - - HttpRequest httpRequest = - startVerificationRequestBuilder(verificationStartRequestInternal, acceptLanguage); - HttpResponse response = - httpClient.invokeAPI( - this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); - - if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); - } - // 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 startVerificationRequestBuilder( - VerificationStartRequestInternal verificationStartRequestInternal, String acceptLanguage) - throws ApiException { - // verify the required parameter 'verificationStartRequestInternal' is set - if (verificationStartRequestInternal == null) { - throw new ApiException( - 400, - "Missing the required parameter 'verificationStartRequestInternal' when calling" - + " startVerification"); - } - - String localVarPath = "/verification/v1/verifications"; - - List localVarQueryParams = new ArrayList<>(); - - Map localVarHeaderParams = new HashMap<>(); - if (acceptLanguage != null) localVarHeaderParams.put("Accept-Language", acceptLanguage); - - final Collection localVarAccepts = Arrays.asList("application/json"); - - final Collection localVarContentTypes = Arrays.asList("application/json"); - - final Collection localVarAuthNames = Arrays.asList("Basic", "Application"); - final String serializedBody = - mapper.serialize(localVarContentTypes, verificationStartRequestInternal); - - return new HttpRequest( - localVarPath, - HttpMethod.POST, - localVarQueryParams, - serializedBody, - localVarHeaderParams, - localVarAccepts, - localVarContentTypes, - localVarAuthNames); - } -} From f1afd96168dba155c43d367063dac6f1d49ba2e0 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 20 Feb 2026 16:44:33 +0100 Subject: [PATCH 3/6] doc (Verification): Migration guide update --- MIGRATION-GUIDE.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/MIGRATION-GUIDE.md b/MIGRATION-GUIDE.md index fc24cc663..cf8506e4e 100644 --- a/MIGRATION-GUIDE.md +++ b/MIGRATION-GUIDE.md @@ -369,6 +369,21 @@ Use the new versioned API under `voice().v1()` to get access to [VoiceService](h ### [`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 `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()) + +| 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 models ##### Common Report @@ -442,13 +457,3 @@ Use the new versioned API under `voice().v1()` to get access to [VoiceService](h - `VerificationMethod.DATA` enum no longer defined. No need to be replaced because not public definition is required. - `template` field removed from `VerificationStartRequestSms`. -#### Replacement APIs - -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()) - -| 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) | From 01b09aabc656fdf005c66af96422f761fbaafaae Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 18 Feb 2026 08:34:46 +0100 Subject: [PATCH 4/6] feat (Voice): Remove adaptator layer for Voice API --- MIGRATION-GUIDE.md | 2 + .../voice/api/v1/ApplicationsService.java | 68 ------ .../domains/voice/api/v1/CalloutsService.java | 57 ----- .../domains/voice/api/v1/CallsService.java | 58 ----- .../voice/api/v1/ConferencesService.java | 63 ------ .../api/v1/adapters/ApplicationsService.java | 57 ----- .../api/v1/adapters/CalloutsService.java | 77 ------- .../voice/api/v1/adapters/CallsService.java | 59 ----- .../api/v1/adapters/ConferencesService.java | 53 ----- .../voice/api/v1/adapters/VoiceService.java | 39 +++- .../v1/adapters/ApplicationsServiceTest.java | 204 +++++++++++++----- .../api/v1/adapters/CalloutsServiceTest.java | 151 +++++++++---- .../api/v1/adapters/CallsServiceTest.java | 128 +++++++---- .../v1/adapters/ConferencesServiceTest.java | 191 +++++++++++----- .../domains/voice/v1/ApplicationsSteps.java | 80 +++---- .../java/voice/applications/ListNumbers.java | 6 +- .../response/OwnedNumbersResponseTest.java | 7 +- 17 files changed, 555 insertions(+), 745 deletions(-) delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ApplicationsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CalloutsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/CallsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/voice/api/v1/adapters/ConferencesService.java diff --git a/MIGRATION-GUIDE.md b/MIGRATION-GUIDE.md index cf8506e4e..59da845a4 100644 --- a/MIGRATION-GUIDE.md +++ b/MIGRATION-GUIDE.md @@ -241,6 +241,8 @@ 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 models | Old const | New const | 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/CalloutsService.java b/client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java deleted file mode 100644 index 12a71528f..000000000 --- a/client/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.sinch.sdk.domains.voice.api.v1; - -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; - -/** - * 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 - */ -public interface CalloutsService { - - /** - * The text-to-speech callout calls a phone number and plays a synthesized text messages or - * pre-recorded sound files. - * - * @param parameters Text to speech parameters - * @return The returned call identifier (callId) - * @since 1.4 - */ - String textToSpeech(CalloutRequestTTS parameters); - - /** - * The conference callout calls a phone number or a user. 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 conference(CalloutRequestConference parameters); - - /** - * The custom callout, the server initiates a call from the servers that can be controlled by - * specifying how the call should progress at each call event. - * - * @param parameters Custom parameters - * @return The returned call identifier (callId) - * @since 1.4 - */ - String custom(CalloutRequestCustom parameters); - - /** - * 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 parameters Callout type to be performed - * @return The returned call identifier (callId) - * @since 1.4 - */ - String call(CalloutRequest 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/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() { From 6ee9e64491aedb4e831599778927bf0125f8c705 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 18 Feb 2026 08:38:53 +0100 Subject: [PATCH 5/6] feat (Voice): openapi contracts sources --- .../voice/api/v1/ApplicationsService.java | 75 +++++ .../domains/voice/api/v1/CalloutsService.java | 61 ++++ .../domains/voice/api/v1/CallsService.java | 77 +++++ .../voice/api/v1/ConferencesService.java | 77 +++++ .../ApplicationsServiceImpl.java} | 211 ++++---------- .../CalloutsServiceImpl.java} | 61 ++-- .../CallsServiceImpl.java} | 110 +++----- .../ConferencesServiceImpl.java} | 266 +++++++----------- .../response/OwnedNumbersListResponse.java | 47 ++++ .../OwnedNumbersListResponseInternal.java} | 13 +- ...OwnedNumbersListResponseInternalImpl.java} | 23 +- 11 files changed, 592 insertions(+), 429 deletions(-) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ApplicationsService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CallsService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/ConferencesService.java rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/{internal/ApplicationsApi.java => adapters/ApplicationsServiceImpl.java} (58%) rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/{internal/CalloutsApi.java => adapters/CalloutsServiceImpl.java} (66%) rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/{internal/CallsApi.java => adapters/CallsServiceImpl.java} (58%) rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/{internal/ConferencesApi.java => adapters/ConferencesServiceImpl.java} (67%) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/OwnedNumbersListResponse.java rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/{OwnedNumbersResponse.java => internal/OwnedNumbersListResponseInternal.java} (72%) rename openapi-contracts/src/main/com/sinch/sdk/domains/voice/models/v1/applications/response/{OwnedNumbersResponseImpl.java => internal/OwnedNumbersListResponseInternalImpl.java} (73%) 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/openapi-contracts/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 new file mode 100644 index 000000000..ae6880aa9 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/voice/api/v1/CalloutsService.java @@ -0,0 +1,61 @@ +/* + * 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; +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; + +/** Callouts Service */ +public interface CalloutsService { + + /** + * The text-to-speech callout calls a phone number and plays a synthesized text messages or + * pre-recorded sound files. + * + * @param parameters Text to speech parameters + * @return The returned call identifier (callId) + * @since 1.4 + */ + String textToSpeech(CalloutRequestTTS parameters); + + /** + * The conference callout calls a phone number or a user. 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 conference(CalloutRequestConference parameters); + + /** + * The custom callout, the server initiates a call from the servers that can be controlled by + * specifying how the call should progress at each call event. + * + * @param parameters Custom parameters + * @return The returned call identifier (callId) + * @since 1.4 + */ + String custom(CalloutRequestCustom parameters); + + /** + * 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 parameters Callout type to be performed + * @return The returned call identifier (callId) + * @since 1.4 + */ + String call(CalloutRequest parameters); +} 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); } } } From 1ca303a2ab3d99b2d21f7dffe5001f2a862c1c61 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 20 Feb 2026 17:29:46 +0100 Subject: [PATCH 6/6] doc (Voice): Migration guide update --- MIGRATION-GUIDE.md | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/MIGRATION-GUIDE.md b/MIGRATION-GUIDE.md index 59da845a4..56635f13c 100644 --- a/MIGRATION-GUIDE.md +++ b/MIGRATION-GUIDE.md @@ -243,6 +243,18 @@ Use the new versioned API under `sms().v1()` to get access to [SMSService](https - `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 | @@ -263,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 | @@ -355,20 +367,6 @@ 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) | - -#### 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) | - - ### [`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