diff --git a/README.md b/README.md index 6d11cfcc..b1dd8ae6 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Sinch client provides access to the following Sinch products: - Numbers [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/numbers/package-summary.html) - SMS [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/sms/package-summary.html) - Verification [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/verification/package-summary.html) -- Voice _(WIP)_ +- Voice [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/package-summary.html) - additional products coming soon! ## Logging diff --git a/client/src/main/com/sinch/sdk/SinchClient.java b/client/src/main/com/sinch/sdk/SinchClient.java index cbff1744..5df9f5eb 100644 --- a/client/src/main/com/sinch/sdk/SinchClient.java +++ b/client/src/main/com/sinch/sdk/SinchClient.java @@ -124,11 +124,11 @@ private void handleDefaultVoiceSettings( // server is not defined: use the region to set to an existing one and use "global" as a default // fallback - if (StringUtil.isEmpty(builder.voiceUrl)) { + if (StringUtil.isEmpty(builder.getVoiceUrl())) { VoiceRegion region = - StringUtil.isEmpty(builder.voiceRegion.value()) + StringUtil.isEmpty(builder.getVoiceRegion().value()) ? VoiceRegion.GLOBAL - : builder.voiceRegion; + : builder.getVoiceRegion(); builder.setVoiceUrl(props.getProperty(String.format("voice-server-%s", region.value()))); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/StatusService.java b/client/src/main/com/sinch/sdk/domains/verification/StatusService.java index 88f2042e..a6215a3f 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/StatusService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/StatusService.java @@ -1,6 +1,6 @@ package com.sinch.sdk.domains.verification; -import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationId; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; @@ -22,12 +22,13 @@ public interface StatusService { * 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 Only number identity is supported + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported * @param method Method used for verification * @return Verification report response * @since 1.0 */ - VerificationReport get(Identity identity, VerificationMethodType method); + VerificationReport get(NumberIdentity identity, VerificationMethodType method); /** * Queries the verification result by sending the verification ID. With this query you can get the diff --git a/client/src/main/com/sinch/sdk/domains/verification/VerificationService.java b/client/src/main/com/sinch/sdk/domains/verification/VerificationService.java index 0032a844..5071b82c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/VerificationService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/VerificationService.java @@ -1,10 +1,10 @@ package com.sinch.sdk.domains.verification; /** - * Verification Service + * Verification Domain Level Service * * @see https://developers.sinch.com/docs/verification// + * href="https://developers.sinch.com/docs/verification">https://developers.sinch.com/docs/verification * @since 1.0 */ public interface VerificationService { @@ -13,6 +13,8 @@ public interface VerificationService { * Verifications Service instance * * @return service instance for project + * @see Documentation * @since 1.0 */ VerificationsService verifications(); @@ -21,6 +23,8 @@ public interface VerificationService { * Status Service instance * * @return service instance for project + * @see Documentation * @since 1.0 */ StatusService status(); @@ -29,6 +33,8 @@ public interface VerificationService { * Webhooks helpers instance * * @return instance service related to webhooks helpers + * @see Documentation * @since 1.0 */ WebHooksService webhooks(); diff --git a/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java b/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java index b04f7dab..1aebf1ed 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java @@ -1,6 +1,6 @@ package com.sinch.sdk.domains.verification; -import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationId; import com.sinch.sdk.domains.verification.models.VerificationReport; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; @@ -37,12 +37,14 @@ public interface VerificationsService { * cases, the phone number). For an SMS PIN verification or Phone Call verification, this is the * OTP code. For flashcalls, this is the CLI. * - * @param identity Only number identity is supported + * @param identity Currently Only {@link + * com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported * @param parameters Parameters to be used to get report * @return Verification report response * @since 1.0 */ - VerificationReport report(Identity identity, VerificationReportRequestParameters parameters); + VerificationReport report( + NumberIdentity identity, VerificationReportRequestParameters parameters); /** * Report the received verification code to verify it, using the Verification ID of the diff --git a/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java index 70e29d48..167f4a6a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java @@ -35,7 +35,7 @@ public interface WebHooksService { * href="https://developers.sinch.com/docs/verification/api-reference/authentication/callback-signed-request">https://developers.sinch.com/docs/verification/api-reference/authentication/callback-signed-request * @since 1.0 */ - boolean validateAuthenticatedRequest( + boolean validateAuthenticationHeader( String method, String path, Map headers, String jsonPayload); /** @@ -48,7 +48,7 @@ boolean validateAuthenticatedRequest( * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/">https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/ * @since 1.0 */ - VerificationEvent unserializeVerificationEvent(String jsonPayload) throws ApiMappingException; + VerificationEvent parseEvent(String jsonPayload) throws ApiMappingException; /** * This function can be called to serialize a verification response to be sent as JSON @@ -59,5 +59,5 @@ boolean validateAuthenticatedRequest( * href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/">https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/ * @since 1.0 */ - String serializeVerificationResponse(VerificationResponse response) throws ApiMappingException; + String serializeResponse(VerificationResponse response) throws ApiMappingException; } diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/StatusService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/StatusService.java index 4e693f6a..2f63021a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/StatusService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/StatusService.java @@ -1,12 +1,10 @@ package com.sinch.sdk.domains.verification.adapters; -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.HttpMapper; import com.sinch.sdk.domains.verification.adapters.api.v1.QueryVerificationsApi; import com.sinch.sdk.domains.verification.adapters.converters.VerificationsDtoConverter; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationId; import com.sinch.sdk.domains.verification.models.VerificationMethodType; @@ -30,16 +28,10 @@ protected QueryVerificationsApi getApi() { return this.api; } - public VerificationReport get(Identity identity, VerificationMethodType method) { - if (!(identity instanceof NumberIdentity)) { - throw new ApiException("Unexpected entity: " + identity); - } - NumberIdentity numberIdentity = (NumberIdentity) identity; + public VerificationReport get(NumberIdentity identity, VerificationMethodType method) { return VerificationsDtoConverter.convert( - getApi() - .verificationStatusByIdentity( - numberIdentity.getType(), numberIdentity.getEndpoint(), method.value())); + getApi().verificationStatusByIdentity("number", identity.getEndpoint(), method.value())); } public VerificationReport get(VerificationId id) { diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java index ae118703..46b5244b 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java @@ -1,12 +1,10 @@ package com.sinch.sdk.domains.verification.adapters; -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.HttpMapper; import com.sinch.sdk.domains.verification.adapters.api.v1.SendingAndReportingVerificationsApi; import com.sinch.sdk.domains.verification.adapters.converters.VerificationsDtoConverter; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationId; import com.sinch.sdk.domains.verification.models.VerificationReport; @@ -38,18 +36,12 @@ public StartVerificationResponse start(StartVerificationRequestParameters parame } public VerificationReport report( - Identity identity, VerificationReportRequestParameters parameters) { - if (!(identity instanceof NumberIdentity)) { - throw new ApiException("Unexpected entity: " + identity); - } - NumberIdentity numberIdentity = (NumberIdentity) identity; + NumberIdentity identity, VerificationReportRequestParameters parameters) { return VerificationsDtoConverter.convert( getApi() .reportVerificationByIdentity( - numberIdentity.getType(), - numberIdentity.getEndpoint(), - VerificationsDtoConverter.convert(parameters))); + "number", identity.getEndpoint(), VerificationsDtoConverter.convert(parameters))); } public VerificationReport report( diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/WebHooksService.java index d68bdbc2..6d420091 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/WebHooksService.java @@ -20,7 +20,7 @@ public WebHooksService(Map authManagers) { this.authManagers = authManagers; } - public boolean validateAuthenticatedRequest( + public boolean validateAuthenticationHeader( String method, String path, Map headers, String jsonPayload) { // convert header keys to use case-insensitive map keys @@ -48,8 +48,7 @@ public boolean validateAuthenticatedRequest( } @Override - public VerificationEvent unserializeVerificationEvent(String jsonPayload) - throws ApiMappingException { + public VerificationEvent parseEvent(String jsonPayload) throws ApiMappingException { try { return Mapper.getInstance().readValue(jsonPayload, VerificationEvent.class); } catch (JsonProcessingException e) { @@ -58,8 +57,7 @@ public VerificationEvent unserializeVerificationEvent(String jsonPayload) } @Override - public String serializeVerificationResponse(VerificationResponse response) - throws ApiMappingException { + public String serializeResponse(VerificationResponse response) throws ApiMappingException { try { return Mapper.getInstance().writeValueAsString(response); } catch (JsonProcessingException e) { diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java index a0632042..e93b8315 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java @@ -56,8 +56,8 @@ public class VerificationsDtoConverter { public static InitiateVerificationResourceDto convert(StartVerificationRequestParameters client) { InitiateVerificationResourceDto dto = new InitiateVerificationResourceDto(); + dto.method(convert(client.getMethod())); client.getIdentity().ifPresent(f -> dto.identity(convert(f))); - client.getMethod().ifPresent(f -> dto.method(convert(f))); client.getReference().ifPresent(f -> dto.reference(f.getReference())); client.getCustom().ifPresent(dto::custom); diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java b/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java index 244af02d..9363ad66 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java @@ -1,11 +1,16 @@ package com.sinch.sdk.domains.verification.models; -/** Base class for Identity based objects */ +/** Base class for Identity objects */ public abstract class Identity { - public final String type; + private final String type; - public Identity(String type) { + /** + * Create an instance of identity with type + * + * @param type Identity type + */ + protected Identity(String type) { this.type = type; } @@ -13,8 +18,4 @@ public Identity(String type) { public String toString() { return "Identity{" + "type='" + type + '\'' + '}'; } - - public String getType() { - return type; - } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/Link.java b/client/src/main/com/sinch/sdk/domains/verification/models/Link.java index 959e8a2c..1f717c9c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/Link.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/Link.java @@ -2,45 +2,74 @@ import com.sinch.sdk.core.http.HttpMethod; -/** Available methods and actions which can be done after a successful Verification */ +/** + * Available methods and actions which can be done after a successful Verification + * + * @since 1.0 + */ public class Link { private final LinkRelType rel; private final String href; private final HttpMethod method; - /** - * @param rel The related action that can be performed on the initiated Verification - * @param href The complete URL to perform the specified action, localized to the DataCenter which - * handled the original Verification request - * @param method The HTTP method to use when performing the action using the linked localized URL - */ - public Link(LinkRelType rel, String href, HttpMethod method) { + private Link(LinkRelType rel, String href, HttpMethod method) { this.rel = rel; this.href = href; this.method = method; } + /** + * The related action that can be performed on the initiated Verification + * + * @return Related type + * @since 1.0 + */ public LinkRelType getRel() { return rel; } + /** + * The complete URL to perform the specified action, localized to the DataCenter which handled the + * original Verification request + * + * @return URL value + * @since 1.0 + */ public String getHref() { return href; } + /** + * The HTTP method to use when performing the action using the linked localized URL + * + * @return HTTP method + * @since 1.0 + */ public HttpMethod getMethod() { return method; } + /** {@inheritDoc} */ @Override public String toString() { return "Link{" + "rel='" + rel + '\'' + ", href='" + href + '\'' + ", method=" + method + '}'; } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder { LinkRelType rel; @@ -49,21 +78,48 @@ public static class Builder { private Builder() {} + /** + * Setter + * + * @param rel See {@link #getRel()} getter + * @return Current builder + * @since 1.0 + */ public Builder setRel(LinkRelType rel) { this.rel = rel; return this; } + /** + * Setter + * + * @param href See {@link #getHref()} getter + * @return Current builder + * @since 1.0 + */ public Builder setHref(String href) { this.href = href; return this; } + /** + * Setter + * + * @param method See {@link #getMethod()} getter + * @return Current builder + * @since 1.0 + */ public Builder setMethod(HttpMethod method) { this.method = method; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public Link build() { return new Link(rel, href, method); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java b/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java index 8dd32002..86773710 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java @@ -25,14 +25,31 @@ private LinkRelType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static LinkRelType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(LinkRelType e) { return ENUM_SUPPORT.valueOf(e); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java b/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java index dff579c0..f73c36f7 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java @@ -1,10 +1,19 @@ package com.sinch.sdk.domains.verification.models; -/** Identity based onto a number */ +import com.sinch.sdk.models.E164PhoneNumber; + +/** Identity based onto a phone number */ public class NumberIdentity extends Identity { private final String endpoint; + /** + * Get related endpoint + * + *

See {@link Builder#setEndpoint(String)} setter + * + * @return Phone number value + */ public String getEndpoint() { return endpoint; } @@ -12,7 +21,7 @@ public String getEndpoint() { /** * @param endpoint An E.164-compatible phone number. */ - public NumberIdentity(String endpoint) { + private NumberIdentity(String endpoint) { super("number"); this.endpoint = endpoint; } @@ -22,21 +31,60 @@ public String toString() { return "NumberIdentity{" + "endpoint='" + endpoint + '\'' + "} " + super.toString(); } + /** + * Create a NumberIdentity from a phone number as a String + * + * @param phoneNumber String representation of phone number + * @return Instance of NumberIdentity + * @since 1.0 + */ + public static NumberIdentity valueOf(String phoneNumber) { + return builder().setEndpoint(phoneNumber).build(); + } + + /** + * Create a NumberIdentity from a phone number as a E164PhoneNumber + * + * @param phoneNumber E164PhoneNumber representation of phone number + * @return Instance of NumberIdentity + * @since 1.0 + */ + public static NumberIdentity valueOf(E164PhoneNumber phoneNumber) { + return builder().setEndpoint(phoneNumber.stringValue()).build(); + } + + /** + * Getting Builder + * + * @return New Builder instance + */ public static Builder builder() { return new Builder(); } + /** Dedicated Builder */ public static class Builder { String endpoint; private Builder() {} + /** + * Endpoint to be used for number identity (the phone number) + * + * @param endpoint Phone number value + * @return Current builder + */ public Builder setEndpoint(String endpoint) { this.endpoint = endpoint; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + */ public NumberIdentity build() { return new NumberIdentity(endpoint); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/Price.java b/client/src/main/com/sinch/sdk/domains/verification/models/Price.java index 64fe5e98..6e7f163e 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/Price.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/Price.java @@ -1,35 +1,56 @@ package com.sinch.sdk.domains.verification.models; +/** Price object representation */ public class Price { private final String currencyId; private final Float amount; - /** - * @param currencyId ISO 4217 currency code - * @param amount The amount - */ - public Price(String currencyId, Float amount) { + private Price(String currencyId, Float amount) { this.currencyId = currencyId; this.amount = amount; } + /** + * ISO 4217 currency code + * + * @return Currency value + * @since 1.0 + */ public String getCurrencyId() { return currencyId; } + /** + * Amount value + * + * @return The amount + * @since 1.0 + */ public Float getAmount() { return amount; } + /** {@inheritDoc} */ @Override public String toString() { return "Price{" + "currencyId='" + currencyId + '\'' + ", amount=" + amount + '}'; } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder { String currencyId; @@ -37,16 +58,36 @@ public static class Builder { private Builder() {} + /** + * Setter + * + * @param currencyId See {@link Price#getCurrencyId()} getter + * @return Current builder + * @since 1.0 + */ public Builder setCurrencyId(String currencyId) { this.currencyId = currencyId; return this; } + /** + * Setter + * + * @param amount See {@link Price#getAmount()} getter + * @return Current builder + * @since 1.0 + */ public Builder setAmount(Float amount) { this.amount = amount; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public Price build() { return new Price(currencyId, amount); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationId.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationId.java index 7293dc2b..e3a105b0 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationId.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationId.java @@ -1,22 +1,44 @@ package com.sinch.sdk.domains.verification.models; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; + +/** + * Verification ID related to a Verification request + * + *

Verification ID a returned by {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters)}} + */ public class VerificationId { - public final String id; + private final String id; - public VerificationId(String id) { + private VerificationId(String id) { this.id = id; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationId{" + "id='" + id + '\'' + '}'; } + /** + * Get the verification Id value + * + * @return Id Value + * @since 1.0 + */ public String getId() { return id; } + /** + * Create a new verification id from a String + * + * @param id The id value + * @return The newly created VerificationId instance + * @since 1.0 + */ public static VerificationId valueOf(String id) { return new VerificationId(id); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethodType.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethodType.java index 65c3add9..38e9bf5a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethodType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethodType.java @@ -44,14 +44,31 @@ private VerificationMethodType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VerificationMethodType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VerificationMethodType e) { return ENUM_SUPPORT.valueOf(e); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReference.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReference.java index f1f9ec63..0189f3a1 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReference.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReference.java @@ -1,22 +1,44 @@ package com.sinch.sdk.domains.verification.models; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; + +/** + * Verification reference related to a Verification request + * + *

Verification reference value have to be set when starting a verification with {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters)}} + */ public class VerificationReference { - public final String reference; + private final String reference; - public VerificationReference(String reference) { + private VerificationReference(String reference) { this.reference = reference; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationReference{" + "reference='" + reference + '\'' + '}'; } + /** + * Get the verification reference value + * + * @return reference Value + * @since 1.0 + */ public String getReference() { return reference; } + /** + * Create a new verification reference from a String + * + * @param reference The id value + * @return The newly created VerificationReference instance + * @since 1.0 + */ public static VerificationReference valueOf(String reference) { return new VerificationReference(reference); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReport.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReport.java index 5fc2aff9..d35edf3a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReport.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReport.java @@ -1,6 +1,10 @@ package com.sinch.sdk.domains.verification.models; -/** Comme class to all verification report responses */ +/** + * Common class to all verification report responses + * + * @since 1.0 + */ public class VerificationReport { private final VerificationId id; @@ -8,7 +12,7 @@ public class VerificationReport { private final VerificationReportReasonType reason; private final VerificationReference reference; - public VerificationReport( + protected VerificationReport( VerificationId id, VerificationReportStatusType status, VerificationReportReasonType reason, @@ -19,22 +23,48 @@ public VerificationReport( this.reference = reference; } + /** + * ID related to verification request + * + * @return Verification ID + * @since 1.0 + */ public VerificationId getId() { return id; } + /** + * Current verification status + * + * @return The status value + * @since 1.0 + */ public VerificationReportStatusType getStatus() { return status; } + /** + * The reason why a verification has {@link VerificationReportStatusType#FAIL FAIL}, was {@link + * VerificationReportStatusType#DENIED DENIED}, or was {@link VerificationReportStatusType#ABORTED + * ABORTED}. + * + * @return The reason value + * @since 1.0 + */ public VerificationReportReasonType getReason() { return reason; } + /** + * The reference value that was optionally passed together with the verification request. + * + * @return The reference value + */ public VerificationReference getReference() { return reference; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationReport{" @@ -51,10 +81,16 @@ public String toString() { + '}'; } - public static Builder builder() { + protected static Builder builder() { return new Builder<>(); } + /** + * Dedicated Builder + * + * @param Builder + * @since 1.0 + */ public static class Builder> { VerificationId id; @@ -62,26 +98,70 @@ public static class Builder> { VerificationReportReasonType reason; VerificationReference reference; + protected Builder() {} + + /** + * Setter + * + *

See {@link VerificationReport#getId()} getter + * + * @param id See getter + * @return Current builder + * @since 1.0 + */ public B setId(VerificationId id) { this.id = id; return self(); } + /** + * Setter + * + *

See {@link VerificationReport#getStatus()} getter + * + * @param status See getter + * @return Current builder + * @since 1.0 + */ public B setStatus(VerificationReportStatusType status) { this.status = status; return self(); } + /** + * Setter + * + *

See {@link VerificationReport#getReason()} getter + * + * @param reason See getter + * @return Current builder + * @since 1.0 + */ public B setReason(VerificationReportReasonType reason) { this.reason = reason; return self(); } + /** + * Setter + * + *

See {@link VerificationReport#getReference()} getter + * + * @param reference See getter + * @return Current builder + * @since 1.0 + */ public B setReference(VerificationReference reference) { this.reference = reference; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReport build() { return new VerificationReport(id, status, reason, reference); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportCallout.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportCallout.java index 356efef8..2cd08558 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportCallout.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportCallout.java @@ -1,5 +1,17 @@ package com.sinch.sdk.domains.verification.models; +import com.sinch.sdk.domains.verification.models.NumberIdentity.Builder; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; + +/** + * Verification report related to a {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} of type {@link + * com.sinch.sdk.domains.verification.models.requests.VerificationReportCalloutRequestParameters + * VerificationReportCalloutRequestParameters} + * + * @since 1.0 + */ public class VerificationReportCallout extends VerificationReport { private final Price verificationPrice; @@ -7,26 +19,7 @@ public class VerificationReportCallout extends VerificationReport { private final Integer billableDuration; private final Boolean callComplete; - /** - * @param id The unique ID of the verification request - * @param status The status of the verification request - * @param reason Displays the reason why a verification has FAILED, was DENIED, or was ABORTED - * @param reference The reference that was optionally passed together with the verification - * request - * @param verificationPrice The maximum price charged for this verification process. This property - * will appear in the body of the response with a delay. It will become visible only when the - * verification status is other than PENDING - * @param terminationPrice The maximum cost of the call made during this verification process. - * Present only when termination debiting is enabled (disabled by default). This property will - * appear in the body of the response with a delay. It will become visible only after the call - * is completed, when its cost is known to Sinch - * @param billableDuration The time of the call for which the fee was charged. Present only when - * termination debiting is enabled (disabled by default). Depending on the type of rounding - * used, the value is the actual call time rounded to the nearest second, minute or other - * value. - * @param callComplete Shows whether the call is complete or not. - */ - public VerificationReportCallout( + private VerificationReportCallout( VerificationId id, VerificationReportStatusType status, VerificationReportReasonType reason, @@ -42,22 +35,61 @@ public VerificationReportCallout( this.callComplete = callComplete; } + /** + * The maximum price charged for this verification process. + * + *

This property will appear in the body of the response with a delay. It will become visible + * only when the verification status is other than {@link VerificationReportStatusType#PENDING + * PENDING} + * + * @return Verification price object + * @since 1.0 + */ public Price getVerificationPrice() { return verificationPrice; } + /** + * The maximum cost of the call made during this verification process. + * + *

Present only when termination debiting is enabled (disabled by default). + * + *

This property will appear in the body of the response with a delay. It will become visible + * only after the call is completed, when its cost is known to Sinch. + * + * @return The termination price object + * @since 1.0 + */ public Price getTerminationPrice() { return terminationPrice; } + /** + * The time of the call for which the fee was charged. + * + *

Present only when termination debiting is enabled (disabled by default). + * + *

Depending on the type of rounding used, the value is the actual call time rounded to the + * nearest second, minute or other value. + * + * @return The billable price object + * @since 1.0 + */ public Integer getBillableDuration() { return billableDuration; } + /** + * Shows whether the call is complete or not. + * + * @return TRUE.FALSE + * @since 1.0 + */ public Boolean getCallComplete() { return callComplete; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationReportCallout{" @@ -73,10 +105,17 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** Dedicated Builder */ public static class Builder extends VerificationReport.Builder { Price verificationPrice; @@ -84,26 +123,62 @@ public static class Builder extends VerificationReport.Builder { Integer billableDuration; Boolean callComplete; + private Builder() {} + + /** + * See {@link VerificationReportCallout#getVerificationPrice()} getter + * + * @param verificationPrice See getter + * @return Current builder + * @since 1.0 + */ public Builder setVerificationPrice(Price verificationPrice) { this.verificationPrice = verificationPrice; return this; } + /** + * See {@link VerificationReportCallout#getTerminationPrice()} getter + * + * @param terminationPrice See getter + * @return Current builder + * @since 1.0 + */ public Builder setTerminationPrice(Price terminationPrice) { this.terminationPrice = terminationPrice; return this; } + /** + * See {@link VerificationReportCallout#getBillableDuration()} getter + * + * @param billableDuration See getter + * @return Current builder + * @since 1.0 + */ public Builder setBillableDuration(Integer billableDuration) { this.billableDuration = billableDuration; return this; } + /** + * See {@link VerificationReportCallout#getCallComplete()} getter + * + * @param callComplete See getter + * @return Current builder + * @since 1.0 + */ public Builder setCallComplete(Boolean callComplete) { this.callComplete = callComplete; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportCallout build() { return new VerificationReportCallout( id, diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportFlashCall.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportFlashCall.java index 8a228e13..f31f6ac0 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportFlashCall.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportFlashCall.java @@ -1,5 +1,16 @@ package com.sinch.sdk.domains.verification.models; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; + +/** + * Verification report related to a {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} of type {@link + * com.sinch.sdk.domains.verification.models.requests.VerificationReportFlashCallRequestParameters + * VerificationReportFlashCallRequestParameters} + * + * @since 1.0 + */ public class VerificationReportFlashCall extends VerificationReport { private final Price verificationPrice; @@ -7,26 +18,7 @@ public class VerificationReportFlashCall extends VerificationReport { private final Integer billableDuration; private final VerificationSourceType source; - /** - * @param id The unique ID of the verification request - * @param status The status of the verification request - * @param reason Displays the reason why a verification has FAILED, was DENIED, or was ABORTED - * @param reference The reference that was optionally passed together with the verification - * request - * @param verificationPrice The maximum price charged for this verification process. This property - * will appear in the body of the response with a delay. It will become visible only when the - * verification status is other than PENDING - * @param terminationPrice The maximum cost of the call made during this verification process. - * Present only when termination debiting is enabled (disabled by default). This property will - * appear in the body of the response with a delay. It will become visible only after the call - * is completed, when its cost is known to Sinch - * @param billableDuration The time of the call for which the fee was charged. Present only when - * termination debiting is enabled (disabled by default). Depending on the type of rounding - * used, the value is the actual call time rounded to the nearest second, minute or other - * value. - * @param source Used to show if the call was intercepted or not - */ - public VerificationReportFlashCall( + private VerificationReportFlashCall( VerificationId id, VerificationReportStatusType status, VerificationReportReasonType reason, @@ -42,22 +34,60 @@ public VerificationReportFlashCall( this.source = source; } + /** + * The maximum price charged for this verification process. + * + *

This property will appear in the body of the response with a delay. It will become visible + * only when the verification status is other than {@link VerificationReportStatusType#PENDING + * PENDING} + * + * @return Verification price object + * @since 1.0 + */ public Price getVerificationPrice() { return verificationPrice; } + /** + * The maximum cost of the call made during this verification process. + * + *

Present only when termination debiting is enabled (disabled by default). + * + *

This property will appear in the body of the response with a delay. It will become visible + * only after the call is completed, when its cost is known to Sinch. + * + * @return The termination price object + * @since 1.0 + */ public Price getTerminationPrice() { return terminationPrice; } + /** + * The time of the call for which the fee was charged. + * + *

Present only when termination debiting is enabled (disabled by default). + * + *

Depending on the type of rounding used, the value is the actual call time rounded to the + * nearest second, minute or other value. + * + * @return The billable price object + * @since 1.0 + */ public Integer getBillableDuration() { return billableDuration; } + /** + * Free text that the client is sending, used to show if the call/SMS was intercepted or not. + * + * @return source value + */ public VerificationSourceType getSource() { return source; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationReportFlashCall{" @@ -74,10 +104,17 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** Dedicated Builder */ public static class Builder extends VerificationReport.Builder { Price verificationPrice; @@ -85,26 +122,62 @@ public static class Builder extends VerificationReport.Builder { Integer billableDuration; VerificationSourceType source; + private Builder() {} + + /** + * See {@link VerificationReportFlashCall#getVerificationPrice()} getter + * + * @param verificationPrice See getter + * @return Current builder + * @since 1.0 + */ public Builder setVerificationPrice(Price verificationPrice) { this.verificationPrice = verificationPrice; return this; } + /** + * See {@link VerificationReportFlashCall#getTerminationPrice()} getter + * + * @param terminationPrice See getter + * @return Current builder + * @since 1.0 + */ public Builder setTerminationPrice(Price terminationPrice) { this.terminationPrice = terminationPrice; return this; } + /** + * See {@link VerificationReportFlashCall#getBillableDuration()} getter + * + * @param billableDuration See getter + * @return Current builder + * @since 1.0 + */ public Builder setBillableDuration(Integer billableDuration) { this.billableDuration = billableDuration; return this; } + /** + * See {@link VerificationReportFlashCall#getSource()} getter + * + * @param source See getter + * @return Current builder + * @since 1.0 + */ public Builder setSource(VerificationSourceType source) { this.source = source; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportFlashCall build() { return new VerificationReportFlashCall( id, diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportReasonType.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportReasonType.java index c023d599..f2ffb193 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportReasonType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportReasonType.java @@ -13,32 +13,59 @@ public class VerificationReportReasonType extends EnumDynamic { + /** {@hidden} */ public static final VerificationReportReasonType FRAUD = new VerificationReportReasonType("Fraud"); + + /** {@hidden} */ public static final VerificationReportReasonType NOT_ENOUGH_CREDIT = new VerificationReportReasonType("Not enough credit"); + + /** {@hidden} */ public static final VerificationReportReasonType BLOCKED = new VerificationReportReasonType("Blocked"); + + /** {@hidden} */ public static final VerificationReportReasonType DENIED_BY_CALLBACK = new VerificationReportReasonType("Denied by callback"); + + /** {@hidden} */ public static final VerificationReportReasonType INVALID_CALLBACK = new VerificationReportReasonType("Invalid callback"); + + /** {@hidden} */ public static final VerificationReportReasonType INTERNAL_ERROR = new VerificationReportReasonType("Internal error"); + + /** {@hidden} */ public static final VerificationReportReasonType DESTINATION_DENIED = new VerificationReportReasonType("Destination denied"); + + /** {@hidden} */ public static final VerificationReportReasonType NETWORK_ERROR_OR_NUMBER_UNREACHABLE = new VerificationReportReasonType("Network error or number unreachable"); + + /** {@hidden} */ public static final VerificationReportReasonType FAILED_PENDING = new VerificationReportReasonType("Failed pending"); + + /** {@hidden} */ public static final VerificationReportReasonType SMS_DELIVERY_FAILURE = new VerificationReportReasonType("SMS delivery failure"); + + /** {@hidden} */ public static final VerificationReportReasonType INVALID_CLI = new VerificationReportReasonType("Invalid CLI"); + + /** {@hidden} */ public static final VerificationReportReasonType INVALID_CODE = new VerificationReportReasonType("Invalid code"); + + /** {@hidden} */ public static final VerificationReportReasonType EXPIRED = new VerificationReportReasonType("Expired"); + + /** {@hidden} */ public static final VerificationReportReasonType HUNG_UP_WITHOUT_ENTERING_VALID_CODE = new VerificationReportReasonType("Hung up without entering valid code"); @@ -66,14 +93,31 @@ private VerificationReportReasonType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VerificationReportReasonType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VerificationReportReasonType e) { return ENUM_SUPPORT.valueOf(e); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportSMS.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportSMS.java index eee8ac97..3ae9302b 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportSMS.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportSMS.java @@ -1,22 +1,20 @@ package com.sinch.sdk.domains.verification.models; +/** + * Verification report related to a {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} of type {@link + * com.sinch.sdk.domains.verification.models.requests.VerificationReportSMSRequestParameters + * VerificationReportSMSRequestParameters} + * + * @since 1.0 + */ public class VerificationReportSMS extends VerificationReport { private final Price verificationPrice; private final VerificationSourceType source; - /** - * @param id The unique ID of the verification request - * @param status The status of the verification request - * @param reason Displays the reason why a verification has FAILED, was DENIED, or was ABORTED - * @param reference The reference that was optionally passed together with the verification - * request - * @param verificationPrice The maximum price charged for this verification process. This property - * will appear in the body of the response with a delay. It will become visible only when the - * verification status is other than PENDING - * @param source Used to show if the SMS was intercepted or not - */ - public VerificationReportSMS( + private VerificationReportSMS( VerificationId id, VerificationReportStatusType status, VerificationReportReasonType reason, @@ -28,14 +26,31 @@ public VerificationReportSMS( this.source = source; } + /** + * The maximum price charged for this verification process. + * + *

This property will appear in the body of the response with a delay. It will become visible + * only when the verification status is other than {@link VerificationReportStatusType#PENDING + * PENDING} + * + * @return Verification price object + * @since 1.0 + */ public Price getVerificationPrice() { return verificationPrice; } + /** + * Used to show if the SMS was intercepted or not + * + * @return Source type value + * @since 1.0 + */ public VerificationSourceType getSource() { return source; } + /** {@inheritDoc} */ @Override public String toString() { return "VerificationReportSMS{" @@ -48,25 +63,54 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** Dedicated Builder */ public static class Builder extends VerificationReport.Builder { Price verificationPrice; VerificationSourceType source; + private Builder() {} + + /** + * See {@link VerificationReportSMS#getVerificationPrice() getter} + * + * @param verificationPrice Price object value + * @return Current builder + * @since 1.0 + */ public Builder setVerificationPrice(Price verificationPrice) { this.verificationPrice = verificationPrice; return this; } + /** + * See {@link VerificationReportSMS#getSource() getter} + * + * @param source Source to be set + * @return Current builder + * @since 1.0 + */ public Builder setSource(VerificationSourceType source) { this.source = source; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportSMS build() { return new VerificationReportSMS(id, status, reason, reference, verificationPrice, source); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportStatusType.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportStatusType.java index fee92099..e36dcc98 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportStatusType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationReportStatusType.java @@ -48,14 +48,31 @@ private VerificationReportStatusType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VerificationReportStatusType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VerificationReportStatusType e) { return ENUM_SUPPORT.valueOf(e); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationSourceType.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationSourceType.java index ebf84349..244d327c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationSourceType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationSourceType.java @@ -12,9 +12,11 @@ */ public class VerificationSourceType extends EnumDynamic { + /** Show if the call/SMS was intercepted or not. */ public static final VerificationSourceType INTERCEPTED = new VerificationSourceType("intercepted"); + /** Show if the call/SMS was intercepted or not. */ public static final VerificationSourceType MANUAL = new VerificationSourceType("manual"); /** */ @@ -28,14 +30,31 @@ private VerificationSourceType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VerificationSourceType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VerificationSourceType e) { return ENUM_SUPPORT.valueOf(e); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParameters.java new file mode 100644 index 00000000..acf2d8e0 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParameters.java @@ -0,0 +1,62 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.VerificationReference; + +/** + * Dedicated request parameters to be used for a CALLOUT verification + * + * @since 1.0 + */ +public class StartVerificationCalloutRequestParameters extends StartVerificationRequestParameters { + + private StartVerificationCalloutRequestParameters( + OptionalValue identity, + OptionalValue reference, + OptionalValue custom) { + super(identity, VerificationMethodType.CALLOUT, reference, custom); + } + + @Override + public String toString() { + return "StartVerificationCalloutRequestParameters{} " + super.toString(); + } + + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Dedicated Builder + * + * @since 1.0 + */ + public static class Builder extends StartVerificationRequestParameters.Builder { + + private Builder() {} + + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ + @Override + public StartVerificationCalloutRequestParameters build() { + return new StartVerificationCalloutRequestParameters(identity, reference, custom); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java index 13b52118..e59570ca 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java @@ -5,7 +5,11 @@ import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; -/** Dedicated request parameters to be used for a flash call verification */ +/** + * Dedicated request parameters to be used for a FLASH_CALL verification + * + * @since 1.0 + */ public class StartVerificationFlashCallRequestParameters extends StartVerificationRequestParameters { @@ -16,10 +20,17 @@ private StartVerificationFlashCallRequestParameters( OptionalValue reference, OptionalValue custom, OptionalValue dialTimeOut) { - super(identity, OptionalValue.of(VerificationMethodType.FLASH_CALL), reference, custom); + super(identity, VerificationMethodType.FLASH_CALL, reference, custom); this.dialTimeOut = dialTimeOut; } + /** + * See {@link StartVerificationFlashCallRequestParameters.Builder#setDialTimeOut(Integer) builder + * setter} + * + * @return Dial Time Out value + * @since 1.0 + */ public OptionalValue getDialTimeOut() { return dialTimeOut; } @@ -33,27 +44,45 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends StartVerificationRequestParameters.Builder { OptionalValue dialTimeOut = OptionalValue.empty(); - public Builder() { - super(VerificationMethodType.FLASH_CALL); - } + private Builder() {} /** + * Set the dial timeout + * * @param dialTimeOut The dial timeout in seconds. * @return current builder + * @since 1.0 */ public Builder setDialTimeOut(Integer dialTimeOut) { this.dialTimeOut = OptionalValue.of(dialTimeOut); return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ @Override public StartVerificationFlashCallRequestParameters build() { return new StartVerificationFlashCallRequestParameters( diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java index dfda6605..0678bf7e 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java @@ -2,6 +2,7 @@ import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; @@ -10,16 +11,16 @@ * * @since 1.0 */ -public class StartVerificationRequestParameters { +public abstract class StartVerificationRequestParameters { + private final VerificationMethodType method; private final OptionalValue identity; - private final OptionalValue method; private final OptionalValue reference; private final OptionalValue custom; protected StartVerificationRequestParameters( OptionalValue identity, - OptionalValue method, + VerificationMethodType method, OptionalValue reference, OptionalValue custom) { this.identity = identity; @@ -28,18 +29,44 @@ protected StartVerificationRequestParameters( this.custom = custom; } + /** + * See {@link StartVerificationRequestParameters.Builder#setIdentity(NumberIdentity) builder + * setter} + * + * @return The reference value + * @since 1.0 + */ public OptionalValue getIdentity() { return identity; } - public OptionalValue getMethod() { + /** + * The type of the verification request. + * + * @return The method value + * @since 1.0 + */ + public VerificationMethodType getMethod() { return method; } + /** + * See {@link StartVerificationRequestParameters.Builder#setReference(VerificationReference) + * builder setter} + * + * @return The reference value + * @since 1.0 + */ public OptionalValue getReference() { return reference; } + /** + * See {@link StartVerificationRequestParameters.Builder#setCustom(String) builder setter} + * + * @return The custom value + * @since 1.0 + */ public OptionalValue getCustom() { return custom; } @@ -47,10 +74,10 @@ public OptionalValue getCustom() { @Override public String toString() { return "StartVerificationRequestParameters{" - + "identity=" - + identity - + ", method=" + + "method=" + method + + ", identity=" + + identity + ", reference='" + reference + '\'' @@ -60,52 +87,38 @@ public String toString() { + '}'; } - public static Builder builder() { - return new Builder<>(); - } - - public static Builder builder(VerificationMethodType method) { - return new Builder<>(method); - } - - public static class Builder> { + /** + * Dedicated Builder + * + * @param Builder + * @since 1.0 + */ + public abstract static class Builder> { OptionalValue identity = OptionalValue.empty(); - OptionalValue method = OptionalValue.empty(); OptionalValue reference = OptionalValue.empty(); OptionalValue custom = OptionalValue.empty(); - public Builder() {} - - /** - * @param method The type of the verification request - */ - public Builder(VerificationMethodType method) { - this.method = OptionalValue.of(method); - } - /** + * Specifies the type of endpoint that will be verified and the particular endpoint. + * NumberIdentity is currently the only supported endpoint type + * * @param identity Specifies the type of endpoint that will be verified and the particular * endpoint. number is currently the only supported endpoint type * @return current builder + * @since 1.0 */ - public B setIdentity(Identity identity) { + public B setIdentity(NumberIdentity identity) { this.identity = OptionalValue.of(identity); return self(); } /** - * @param method The type of the verification request. - * @return current builder - */ - protected B setMethod(VerificationMethodType method) { - this.method = OptionalValue.of(method); - return self(); - } - - /** - * @param reference Used to pass your own reference in the request for tracking purposes. + * Used to pass your own reference in the request for tracking purposes + * + * @param reference your own reference to be used * @return current builder + * @since 1.0 */ public B setReference(VerificationReference reference) { this.reference = OptionalValue.of(reference); @@ -113,17 +126,24 @@ public B setReference(VerificationReference reference) { } /** - * @param custom Can be used to pass custom data in the request. + * Pass custom data in the request + * + * @param custom custom data * @return current builder + * @since 1.0 */ public B setCustom(String custom) { this.custom = OptionalValue.of(custom); return self(); } - public StartVerificationRequestParameters build() { - return new StartVerificationRequestParameters(identity, method, reference, custom); - } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ + public abstract StartVerificationRequestParameters build(); @SuppressWarnings("unchecked") protected B self() { diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParameters.java new file mode 100644 index 00000000..9b13d434 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParameters.java @@ -0,0 +1,62 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.VerificationReference; + +/** + * Dedicated request parameters to be used for an SMS verification + * + * @since 1.0 + */ +public class StartVerificationSMSRequestParameters extends StartVerificationRequestParameters { + + private StartVerificationSMSRequestParameters( + OptionalValue identity, + OptionalValue reference, + OptionalValue custom) { + super(identity, VerificationMethodType.SMS, reference, custom); + } + + @Override + public String toString() { + return "StartVerificationSMSRequestParameters{} " + super.toString(); + } + + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Dedicated Builder + * + * @since 1.0 + */ + public static class Builder extends StartVerificationRequestParameters.Builder { + + private Builder() {} + + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ + @Override + public StartVerificationSMSRequestParameters build() { + return new StartVerificationSMSRequestParameters(identity, reference, custom); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParameters.java new file mode 100644 index 00000000..b11e623f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParameters.java @@ -0,0 +1,62 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.VerificationReference; + +/** + * Dedicated request parameters to be used for a SEAMLESS verification + * + * @since 1.0 + */ +public class StartVerificationSeamlessRequestParameters extends StartVerificationRequestParameters { + + private StartVerificationSeamlessRequestParameters( + OptionalValue identity, + OptionalValue reference, + OptionalValue custom) { + super(identity, VerificationMethodType.SEAMLESS, reference, custom); + } + + @Override + public String toString() { + return "StartVerificationSeamlessRequestParameters{} " + super.toString(); + } + + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Dedicated Builder + * + * @since 1.0 + */ + public static class Builder extends StartVerificationRequestParameters.Builder { + + private Builder() {} + + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ + @Override + public StartVerificationSeamlessRequestParameters build() { + return new StartVerificationSeamlessRequestParameters(identity, reference, custom); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportCalloutRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportCalloutRequestParameters.java index 06dde1b8..fde2660e 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportCalloutRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportCalloutRequestParameters.java @@ -3,6 +3,12 @@ import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.verification.models.VerificationMethodType; +/** + * Dedicated request parameters to be used to start a verification report by callout (Verification + * by placing a PSTN call to the user's phone) + * + * @since 1.0 + */ public class VerificationReportCalloutRequestParameters extends VerificationReportRequestParameters { @@ -13,6 +19,12 @@ private VerificationReportCalloutRequestParameters(OptionalValue code) { this.code = code; } + /** + * See {@link VerificationReportCalloutRequestParameters.Builder#setCode(String) builder setter} + * + * @return Code value + * @since 1.0 + */ public OptionalValue getCode() { return code; } @@ -27,19 +39,32 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationReportRequestParameters.Builder { OptionalValue code = OptionalValue.empty(); - public Builder() { + protected Builder() { super(VerificationMethodType.CALLOUT); } /** + * The code which was received by the user submitting the SMS verification. + * * @param code The code which was received by the user submitting the Phone Call verification. * @return current builder */ @@ -48,7 +73,12 @@ public Builder setCode(String code) { return this; } - @Override + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportCalloutRequestParameters build() { return new VerificationReportCalloutRequestParameters(code); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportFlashCallRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportFlashCallRequestParameters.java index d02142f1..2a76d317 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportFlashCallRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportFlashCallRequestParameters.java @@ -3,6 +3,12 @@ import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.verification.models.VerificationMethodType; +/** + * Dedicated request parameters to be used to start a verification report by flash call (missed + * call) + * + * @since 1.0 + */ public class VerificationReportFlashCallRequestParameters extends VerificationReportRequestParameters { @@ -13,6 +19,12 @@ private VerificationReportFlashCallRequestParameters(OptionalValue cli) this.cli = cli; } + /** + * See {@link VerificationReportFlashCallRequestParameters.Builder#setCli(String) builder setter} + * + * @return CLI value + * @since 1.0 + */ public OptionalValue getCli() { return cli; } @@ -27,28 +39,47 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationReportRequestParameters.Builder { OptionalValue cli = OptionalValue.empty(); - public Builder() { + protected Builder() { super(VerificationMethodType.FLASH_CALL); } /** - * @param cli The caller ID of the FlashCall + * The caller ID of the FlashCall + * + * @param cli The caller ID value * @return current builder + * @since 1.0 */ public Builder setCli(String cli) { this.cli = OptionalValue.of(cli); return this; } - @Override + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportFlashCallRequestParameters build() { return new VerificationReportFlashCallRequestParameters(cli); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParameters.java index 92e81ebf..3cecabcf 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParameters.java @@ -3,6 +3,11 @@ import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.verification.models.VerificationMethodType; +/** + * Base class for verification report request parameters + * + * @since 1.0 + */ public class VerificationReportRequestParameters { private final OptionalValue method; @@ -11,6 +16,12 @@ protected VerificationReportRequestParameters(OptionalValue getMethod() { return method; } @@ -20,29 +31,32 @@ public String toString() { return "VerificationReportRequestParameters{" + "method=" + method + '}'; } - public static Builder builder() { + protected static Builder builder() { return new Builder<>(); } + /** + * Dedicated Builder + * + * @param Builder + * @since 1.0 + */ public static class Builder> { OptionalValue method; - public Builder() {} + protected Builder() {} - public Builder(VerificationMethodType method) { + protected Builder(VerificationMethodType method) { this.method = OptionalValue.of(method); } /** - * @param method The type of the verification request. - * @return current builder + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 */ - protected B setMethod(VerificationMethodType method) { - this.method = OptionalValue.of(method); - return self(); - } - public VerificationReportRequestParameters build() { return new VerificationReportRequestParameters(method); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportSMSRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportSMSRequestParameters.java index e4d78898..07f0a01f 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportSMSRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/VerificationReportSMSRequestParameters.java @@ -3,6 +3,11 @@ import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.verification.models.VerificationMethodType; +/** + * Dedicated request parameters to be used to start a verification report by SMS + * + * @since 1.0 + */ public class VerificationReportSMSRequestParameters extends VerificationReportRequestParameters { private final OptionalValue code; @@ -15,10 +20,22 @@ private VerificationReportSMSRequestParameters( this.cli = cli; } + /** + * See {@link VerificationReportSMSRequestParameters.Builder#setCode(String) builder setter} + * + * @return Code value + * @since 1.0 + */ public OptionalValue getCode() { return code; } + /** + * See {@link VerificationReportSMSRequestParameters.Builder#setCli(String) builder setter} + * + * @return CLI value + * @since 1.0 + */ public OptionalValue getCli() { return cli; } @@ -36,22 +53,36 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationReportRequestParameters.Builder { OptionalValue code = OptionalValue.empty(); OptionalValue cli = OptionalValue.empty(); - public Builder() { + protected Builder() { super(VerificationMethodType.SMS); } /** - * @param code The code which was received by the user submitting the SMS verification. + * The code which was received by the user submitting the SMS verification. + * + * @param code The code value * @return current builder + * @since 1.0 */ public Builder setCode(String code) { this.code = OptionalValue.of(code); @@ -59,15 +90,23 @@ public Builder setCode(String code) { } /** - * @param cli The sender ID of the SMS. + * The sender ID of the SMS. + * + * @param cli The sender ID value * @return current builder + * @since 1.0 */ public Builder setCli(String cli) { this.cli = OptionalValue.of(cli); return this; } - @Override + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationReportSMSRequestParameters build() { return new VerificationReportSMSRequestParameters(code, cli); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java index c547e3de..06f1ba45 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java @@ -4,25 +4,37 @@ import com.sinch.sdk.domains.verification.models.VerificationId; import java.util.Collection; -/** Comme class to all Start verification requests */ +/** + * Base class to all Start verification requests + * + * @since 1.0 + */ public class StartVerificationResponse { private final VerificationId id; private final Collection links; - /** - * @param id Verification identifier used to query for status. - * @param links Available methods and actions which can be done after a successful Verification - */ - public StartVerificationResponse(VerificationId id, Collection links) { + protected StartVerificationResponse(VerificationId id, Collection links) { this.id = id; this.links = links; } + /** + * Verification identifier used to query for status. + * + * @return Id value + * @since 1.0 + */ public VerificationId getId() { return id; } + /** + * Available methods and actions which can be done after a successful Verification + * + * @return Links value + * @since 1.0 + */ public Collection getLinks() { return links; } @@ -32,25 +44,60 @@ public String toString() { return "StartVerificationResponse{" + "id='" + id + '\'' + ", links=" + links + '}'; } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder<>(); } + /** + * Dedicated Builder + * + * @param Builder + * @since 1.0 + */ public static class Builder> { VerificationId id; Collection links; + protected Builder() {} + ; + + /** + * See {@link StartVerificationResponse#getId() getter} + * + * @param id see getter + * @return The current builder + * @since 1.0 + */ public B setId(VerificationId id) { this.id = id; return self(); } + /** + * See {@link StartVerificationResponse#getLinks() getter} + * + * @param links see getter + * @return The current builder + * @since 1.0 + */ public B setLinks(Collection links) { this.links = links; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public StartVerificationResponse build() { return new StartVerificationResponse(id, links); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java index b7649db5..d13b6613 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java @@ -4,14 +4,21 @@ import com.sinch.sdk.domains.verification.models.VerificationId; import java.util.Collection; -/** Dedicated response type for a callout verification */ +/** + * Dedicated response type for a callout verification started with {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} initiated wit method {@link + * com.sinch.sdk.domains.verification.models.VerificationMethodType#CALLOUT CALLOUT} + * + * @since 1.0 + */ public class StartVerificationResponseCallout extends StartVerificationResponse { /** * @param id Verification identifier used to query for status. * @param links Available methods and actions which can be done after a successful Verification */ - public StartVerificationResponseCallout(VerificationId id, Collection links) { + private StartVerificationResponseCallout(VerificationId id, Collection links) { super(id, links); } @@ -20,12 +27,33 @@ public String toString() { return "StartVerificationResponseCallout{} " + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends StartVerificationResponse.Builder { + private Builder() { + super(); + } + + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public StartVerificationResponseCallout build() { return new StartVerificationResponseCallout(id, links); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java index 7cdb59f6..c34c648c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java @@ -4,7 +4,14 @@ import com.sinch.sdk.domains.verification.models.VerificationId; import java.util.Collection; -/** Dedicated response type for a flashcall verification */ +/** + * Dedicated response type for a flash call verification started with {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} initiated wit method {@link + * com.sinch.sdk.domains.verification.models.VerificationMethodType#FLASH_CALL FLASH_CALL} + * + * @since 1.0 + */ public class StartVerificationResponseFlashCall extends StartVerificationResponse { private final String cliFilter; @@ -12,17 +19,7 @@ public class StartVerificationResponseFlashCall extends StartVerificationRespons private final Integer reportTimeout; private final Integer denyCallAfter; - /** - * @param id Verification identifier used to query for status. - * @param links Available methods and actions which can be done after a successful Verification - * @param cliFilter Filter that should be applied for incoming calls to intercept the Flashcall. - * @param interceptionTimeOut Amount of seconds client should wait for the Flashcall. - * @param reportTimeout The time in seconds allowed for reporting the code after which the - * verification will expire. - * @param denyCallAfter Used by the SDKs, this setting makes the handset deny the flashcall after - * the set time in seconds. - */ - public StartVerificationResponseFlashCall( + private StartVerificationResponseFlashCall( VerificationId id, Collection links, String cliFilter, @@ -36,18 +33,43 @@ public StartVerificationResponseFlashCall( this.denyCallAfter = denyCallAfter; } + /** + * Filter that should be applied for incoming calls to intercept the Flashcall. + * + * @return Filter value + * @since 1.0 + */ public String getCliFilter() { return cliFilter; } + /** + * Amount of seconds client should wait for the Flashcall. + * + * @return time out value + * @since 1.0 + */ public Integer getInterceptionTimeOut() { return interceptionTimeOut; } + /** + * The time in seconds allowed for reporting the code after which the verification will expire. + * + * @return time out value + * @since 1.0 + */ public Integer getReportTimeout() { return reportTimeout; } + /** + * Used by the SDKs, this setting makes the handset deny the flashcall after the set time in + * seconds. + * + * @return Deny value + * @since 1.0 + */ public Integer getDenyCallAfter() { return denyCallAfter; } @@ -68,10 +90,21 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends StartVerificationResponse.Builder { String cliFilter; @@ -79,26 +112,64 @@ public static class Builder extends StartVerificationResponse.Builder { Integer reportTimeout; Integer denyCallAfter; + private Builder() { + super(); + } + + /** + * See {@link StartVerificationResponseFlashCall#getCliFilter() getter} + * + * @param cliFilter see getter + * @return The current builder + * @since 1.0 + */ public Builder setCliFilter(String cliFilter) { this.cliFilter = cliFilter; return self(); } + /** + * See {@link StartVerificationResponseFlashCall#getInterceptionTimeOut() getter} + * + * @param interceptionTimeOut see getter + * @return The current builder + * @since 1.0 + */ public Builder setInterceptionTimeOut(Integer interceptionTimeOut) { this.interceptionTimeOut = interceptionTimeOut; return self(); } + /** + * See {@link StartVerificationResponseFlashCall#getReportTimeout() getter} + * + * @param reportTimeout see getter + * @return The current builder + * @since 1.0 + */ public Builder setReportTimeout(Integer reportTimeout) { this.reportTimeout = reportTimeout; return self(); } + /** + * See {@link StartVerificationResponseFlashCall#getDenyCallAfter() getter} + * + * @param denyCallAfter see getter + * @return The current builder + * @since 1.0 + */ public Builder setDenyCallAfter(Integer denyCallAfter) { this.denyCallAfter = denyCallAfter; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public StartVerificationResponseFlashCall build() { return new StartVerificationResponseFlashCall( id, links, cliFilter, interceptionTimeOut, reportTimeout, denyCallAfter); diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java index 5e652285..bc6f44b0 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java @@ -4,30 +4,42 @@ import com.sinch.sdk.domains.verification.models.VerificationId; import java.util.Collection; -/** Dedicated response type for a sms verification */ +/** + * Dedicated response type for a SMS call verification started with {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} initiated wit method {@link + * com.sinch.sdk.domains.verification.models.VerificationMethodType#SMS SMS} + * + * @since 1.0 + */ public class StartVerificationResponseSMS extends StartVerificationResponse { private final String template; private final Integer interceptionTimeOut; - /** - * @param id Verification identifier used to query for status. - * @param links Available methods and actions which can be done after a successful Verification - * @param template The expected template for the SMS response - * @param interceptionTimeOut The amount of time in seconds that the client should wait for the - * SMS. - */ - public StartVerificationResponseSMS( + private StartVerificationResponseSMS( VerificationId id, Collection links, String template, Integer interceptionTimeOut) { super(id, links); this.template = template; this.interceptionTimeOut = interceptionTimeOut; } + /** + * The expected template for the SMS response + * + * @return Template value + * @since 1.0 + */ public String getTemplate() { return template; } + /** + * The amount of time in seconds that the client should wait for the SMS. + * + * @return Timeout value + * @since 1.0 + */ public Integer getInterceptionTimeOut() { return interceptionTimeOut; } @@ -44,25 +56,60 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends StartVerificationResponse.Builder { String template; Integer interceptionTimeOut; + private Builder() { + super(); + } + + /** + * See {@link StartVerificationResponseSMS#getTemplate() getter} + * + * @param template see getter + * @return The current builder + * @since 1.0 + */ public Builder setTemplate(String template) { this.template = template; return this; } + /** + * See {@link StartVerificationResponseSMS#getInterceptionTimeOut() getter} + * + * @param interceptionTimeOut see getter + * @return The current builder + * @since 1.0 + */ public Builder setInterceptionTimeOut(Integer interceptionTimeOut) { this.interceptionTimeOut = interceptionTimeOut; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public StartVerificationResponseSMS build() { return new StartVerificationResponseSMS(id, links, template, interceptionTimeOut); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java index 173d7279..a22d2ebc 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java @@ -4,22 +4,30 @@ import com.sinch.sdk.domains.verification.models.VerificationId; import java.util.Collection; -/** Dedicated response type for a seamless verification */ +/** + * Dedicated response type for a seamless call verification started with {@link + * com.sinch.sdk.domains.verification.VerificationsService#start(StartVerificationRequestParameters) + * VerificationsService#start()} initiated wit method {@link + * com.sinch.sdk.domains.verification.models.VerificationMethodType#SEAMLESS SEAMLESS} + * + * @since 1.0 + */ public class StartVerificationResponseSeamless extends StartVerificationResponse { private final String targetUri; - /** - * @param id Verification identifier used to query for status. - * @param links Available methods and actions which can be done after a successful Verification - * @param targetUri The target URI - */ - public StartVerificationResponseSeamless( + private StartVerificationResponseSeamless( VerificationId id, Collection links, String targetUri) { super(id, links); this.targetUri = targetUri; } + /** + * The target URI + * + * @return The target URI + * @since 1.0 + */ public String getTargetUri() { return targetUri; } @@ -34,19 +42,47 @@ public String toString() { + super.toString(); } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends StartVerificationResponse.Builder { String targetUri; + private Builder() { + super(); + } + + /** + * See {@link StartVerificationResponseSeamless#getLinks() getter} + * + * @param targetUri see getter + * @return The current builder + * @since 1.0 + */ public Builder setTargetUri(String targetUri) { this.targetUri = targetUri; return this; } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public StartVerificationResponseSeamless build() { return new StartVerificationResponseSeamless(id, links, targetUri); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationEvent.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationEvent.java index cba0266d..61d49302 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationEvent.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationEvent.java @@ -11,6 +11,12 @@ import com.sinch.sdk.domains.verification.models.VerificationReference; import java.util.Optional; +/** + * Base class for received Verification Events onto webhooks callback + * + * @see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks + */ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, @@ -21,7 +27,6 @@ @JsonSubTypes.Type(value = VerificationResultEvent.class, name = "VerificationResultEvent") }) public class VerificationEvent { - private final VerificationId id; private final String event; private final VerificationMethodType method; @@ -29,20 +34,6 @@ public class VerificationEvent { private final VerificationReference reference; private final String custom; - /** - * Base class for verification event - * - * @param id The ID of the verification request. - * @param event The type of the event. - * @param method The verification method - * @param identity Specifies the type of endpoint that will be verified and the particular - * endpoint. number is currently the only supported endpoint type - * @param reference The reference ID that was optionally passed together with the verification - * request - * @param custom A custom string that can be provided during a verification request. see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/ - * @since 1.0 - */ @JsonCreator VerificationEvent( @JsonProperty("id") String id, @@ -63,26 +54,63 @@ public class VerificationEvent { this.custom = custom; } + /** + * The ID of the verification request. + * + * @return Id value + * @since 1.0 + */ public VerificationId getId() { return id; } + /** + * The type of the event + * + * @return event value + * @since 1.0 + */ public String getEvent() { return event; } + /** + * The verification method + * + * @return The method value + * @since 1.0 + */ public VerificationMethodType getMethod() { return method; } + /** + * Specifies the type of endpoint that will be verified and the particular endpoint. {@link + * NumberIdentity} is currently the only supported endpoint type + * + * @return identity + * @since 1.0 + */ public Identity getIdentity() { return identity; } + /** + * The reference that was optionally passed together with the verification request + * + * @return Reference value + * @since 1.0 + */ public Optional getReference() { return Optional.ofNullable(reference); } + /** + * A custom string that can be provided during a verification request + * + * @return The custom value + * @since 1.0 + */ public Optional getCustom() { return Optional.ofNullable(custom); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationRequestEvent.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationRequestEvent.java index 6fa3e1c2..70b8f56a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationRequestEvent.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationRequestEvent.java @@ -6,34 +6,17 @@ import java.util.Collection; import java.util.Optional; +/** + * This event is received onto a POST request to the specified verification callback URL and is + * triggered when a new verification request is made from the SDK client or the Verification Request + * API. This callback event is only triggered when a verification callback URL is specified in your + * dashboard. + */ public class VerificationRequestEvent extends VerificationEvent { private final Price price; private final Collection acceptLanguage; - /** - * This event is a POST request to the specified verification callback URL and is triggered when a - * new verification request is made from the SDK client or the Verification Request API. This - * callback event is only triggered when a verification callback URL is specified in your - * dashboard. - * - * @param id The ID of the verification request. - * @param event The type of the event. - * @param method The verification method - * @param identity Specifies the type of endpoint that will be verified and the particular - * endpoint. number is currently the only supported endpoint type - * @param reference The reference ID that was optionally passed together with the verification - * request - * @param custom A custom string that can be provided during a verification request. - * @param price The amount of money and currency of the verification request - * @param acceptLanguage Allows you to set or override if provided in the API request, the SMS - * verification content language. Only used with the SMS verification method. The content - * language specified in the API request or in the callback can be overridden by carrier - * provider specific templates, due to compliance and legal requirements, such as US shortcode - * requirements see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/#tag/Verification-callbacks/paths/VerificationRequestEvent/post - * @since 1.0 - */ @JsonCreator VerificationRequestEvent( @JsonProperty("id") String id, @@ -54,10 +37,26 @@ public class VerificationRequestEvent extends VerificationEvent { this.acceptLanguage = acceptLanguage; } + /** + * The amount of money and currency of the verification request + * + * @return Price value + * @since 1.0 + */ public Optional getPrice() { return Optional.ofNullable(price); } + /** + * Allows you to set or override if provided in the API request, the SMS verification content + * language. Only used with the SMS verification method. The content language specified in the API + * request or in the callback can be overridden by carrier provider specific templates, due to + * compliance and legal requirements, such as US shortcode requirements see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/#tag/Verification-callbacks/paths/VerificationRequestEvent/post + * + * @return Values collection list + * @since 1.0 + */ public Optional> getAcceptLanguage() { return Optional.ofNullable(acceptLanguage); } @@ -74,8 +73,8 @@ public String toString() { } static class jsonPrice { - Float amount; - String currencyId; + private final Float amount; + private final String currencyId; @JsonCreator public jsonPrice( diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponse.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponse.java index 93eafbe5..4715af86 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponse.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponse.java @@ -12,13 +12,16 @@ public class VerificationResponse { @JsonProperty("action") private final VerificationResponseActionType action; - /** - * @param action Determines whether the verification can be executed - */ VerificationResponse(VerificationResponseActionType action) { this.action = action; } + /** + * Determines whether the verification can be executed + * + * @return action type to be performed + * @since 1.0 + */ public VerificationResponseActionType getAction() { return action; } @@ -28,19 +31,48 @@ public String toString() { return "VerificationResponse{" + "action=" + action + '}'; } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder<>(); } + /** + * Dedicated Builder + * + * @param Builder + * @since 1.0 + */ public static class Builder> { VerificationResponseActionType action; + protected Builder() { + super(); + } + + /** + * See {@link VerificationResponse#getAction() getter} + * + * @param action see getter + * @return The current builder + * @since 1.0 + */ public B setAction(VerificationResponseActionType action) { this.action = action; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationResponse build() { return new VerificationResponse(action); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseActionType.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseActionType.java index 4fed3ce5..84929f3c 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseActionType.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseActionType.java @@ -16,9 +16,11 @@ public class VerificationResponseActionType extends EnumDynamic { + /** Action is allowed */ public static final VerificationResponseActionType ALLOW = new VerificationResponseActionType("allow"); + /** >Action is denied */ public static final VerificationResponseActionType DENY = new VerificationResponseActionType("deny"); @@ -33,18 +35,40 @@ private VerificationResponseActionType(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VerificationResponseActionType from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param e The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VerificationResponseActionType e) { return ENUM_SUPPORT.valueOf(e); } + /** + * Value of the enum as String + * + * @return String identifier of the enum value # @since 1.0 + */ @JsonValue public String getValue() { return this.value(); diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseCallout.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseCallout.java index ba1d749f..cbb3f2b2 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseCallout.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseCallout.java @@ -17,6 +17,12 @@ public class VerificationResponseCallout extends VerificationResponse { this.callout = callout; } + /** + * Call out related information + * + * @return Call out related information + * @since 1.0 + */ public CalloutResponse getCallout() { return callout; } @@ -27,7 +33,7 @@ public String toString() { } /** - * Call out related information for call out verification callback See callout * response documentation * @@ -42,7 +48,9 @@ public static class CalloutResponse { private final SpeechResponse speech; /** - * @param code The Phone Call PIN that should be entered by the user. Sinch servers + * Construct a CalloutResponse instance + * + * @param code The Phone Call PIN that should be entered by the user. Sinch's servers * automatically generate PIN codes for Phone Call verification. If you want to set your own * code, you can specify it in the response to the Verification Request Event. * @param speech An object defining various properties for the text-to-speech message. @@ -52,10 +60,22 @@ public CalloutResponse(Integer code, SpeechResponse speech) { this.speech = speech; } + /** + * see CalloutResponse Constructor + * + * @return see {@link CalloutResponse#CalloutResponse(Integer, SpeechResponse) constructor} + * @since 1.0 + */ public Integer getCode() { return code; } + /** + * see CalloutResponse Constructor + * + * @return see {@link CalloutResponse#CalloutResponse(Integer, SpeechResponse) constructor} + * @since 1.0 + */ public SpeechResponse getSpeech() { return speech; } @@ -67,7 +87,7 @@ public String toString() { } /** - * Speech related information for SMS verification callback See speech * response documentation * @@ -79,13 +99,21 @@ public static class SpeechResponse { private final String locale; /** - * @param locale Indicates the language that should be used for the text-to-speech message. - * Currently, only en-US is supported. + * Indicates the language that should be used for the text-to-speech message. Currently, only + * en-US is supported. + * + * @param locale Locale value */ public SpeechResponse(String locale) { this.locale = locale; } + /** + * see SpeechResponse Constructor + * + * @return see {@link SpeechResponse#SpeechResponse(String) constructor} + * @since 1.0 + */ public String getLocale() { return locale; } @@ -96,26 +124,59 @@ public String toString() { } } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationResponse.Builder { Integer code; String locale; + private Builder() {} + + /** + * See {@link CalloutResponse#CalloutResponse(Integer, SpeechResponse) constructor} + * + * @param code see constructor + * @return The current builder + * @since 1.0 + */ public Builder setCode(Integer code) { this.code = code; return self(); } + /** + * See {@link SpeechResponse#SpeechResponse(String) constructor} + * + * @param locale see constructor + * @return The current builder + * @since 1.0 + */ public Builder setLocale(String locale) { this.locale = locale; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationResponseCallout build() { return new VerificationResponseCallout( action, new CalloutResponse(code, new SpeechResponse(locale))); diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseFlashCall.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseFlashCall.java index 8a096de6..f8eedb3a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseFlashCall.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseFlashCall.java @@ -18,6 +18,12 @@ public class VerificationResponseFlashCall extends VerificationResponse { this.flashCall = flashCall; } + /** + * Flash call Response related information + * + * @return Flash call related information + * @since 1.0 + */ public FlashCallResponse getFlashCall() { return flashCall; } @@ -43,6 +49,8 @@ public static class FlashCallResponse { private final Integer dialTimeout; /** + * Flash call response related information + * * @param cli The phone number that will be displayed to the user when the flashcall is received * on the user's phone. By default, the Sinch dashboard will randomly select the CLI that * will be displayed during a flashcall from a pool of numbers. If you want to set your own @@ -58,10 +66,22 @@ public FlashCallResponse(String cli, Integer dialTimeout) { this.dialTimeout = dialTimeout; } + /** + * See constructor + * + * @return See {@link FlashCallResponse#FlashCallResponse(String, Integer) FlashCallResponse} + * @since 1.0 + */ public String getCli() { return cli; } + /** + * See constructor + * + * @return See {@link FlashCallResponse#FlashCallResponse(String, Integer) FlashCallResponse} + * @since 1.0 + */ public Integer getDialTimeout() { return dialTimeout; } @@ -72,26 +92,63 @@ public String toString() { } } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationResponse.Builder { String cli; Integer dialTimeout; + private Builder() {} + + /** + * See {@link + * VerificationResponseFlashCall#VerificationResponseFlashCall(VerificationResponseActionType, + * FlashCallResponse) constructor} + * + * @param cli see constructor + * @return The current builder + * @since 1.0 + */ public Builder setCli(String cli) { this.cli = cli; return self(); } + /** + * See {@link + * VerificationResponseFlashCall#VerificationResponseFlashCall(VerificationResponseActionType, + * FlashCallResponse) constructor} + * + * @param dialTimeout see constructor + * @return The current builder + * @since 1.0 + */ public Builder setDialTimeout(Integer dialTimeout) { this.dialTimeout = dialTimeout; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationResponseFlashCall build() { return new VerificationResponseFlashCall(action, new FlashCallResponse(cli, dialTimeout)); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseSMS.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseSMS.java index 7622ce72..2d86e10d 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseSMS.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResponseSMS.java @@ -18,6 +18,12 @@ public class VerificationResponseSMS extends VerificationResponse { this.sms = sms; } + /** + * SMS Response related information + * + * @return SMS related information + * @since 1.0 + */ public SMSResponse getSms() { return sms; } @@ -42,6 +48,8 @@ public static class SMSResponse { private final Collection acceptLanguage; /** + * SMS response related information + * * @param code The SMS PIN that should be used. By default, the Sinch dashboard will * automatically generate PIN codes for SMS verification. If you want to set your own PIN, * you can specify it in the response to the Verification Request Event. @@ -58,25 +66,58 @@ public String toString() { } } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder extends VerificationResponse.Builder { Integer code; Collection acceptLanguage; + private Builder() {} + + /** + * See {@link SMSResponse#SMSResponse(Integer, Collection) constructor} + * + * @param code see constructor + * @return The current builder + * @since 1.0 + */ public Builder setCode(Integer code) { this.code = code; return self(); } + /** + * See {@link SMSResponse#SMSResponse(Integer, Collection) constructor} + * + * @param acceptLanguage see constructor + * @return The current builder + * @since 1.0 + */ public Builder setAcceptLanguage(Collection acceptLanguage) { this.acceptLanguage = acceptLanguage; return self(); } + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ public VerificationResponseSMS build() { return new VerificationResponseSMS(action, new SMSResponse(code, acceptLanguage)); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResultEvent.java b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResultEvent.java index 9a033fa4..7ec1d304 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResultEvent.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/webhooks/VerificationResultEvent.java @@ -7,33 +7,18 @@ import com.sinch.sdk.domains.verification.models.VerificationSourceType; import java.util.Optional; +/** + * This event is received onto a POST request to the specified verification callback URL and + * triggered when a verification has been completed and the result is known. It's used to report the + * verification result to the developer's backend application. This callback event is only triggered + * when the verification callback URL is specified in your dashboard. + */ public class VerificationResultEvent extends VerificationEvent { private final VerificationReportStatusType status; private final VerificationReportReasonType reason; private final VerificationSourceType source; - /** - * This event is a POST request to the specified verification callback URL and triggered when a - * verification has been completed and the result is known. It's used to report the verification - * result to the developer's backend application. This callback event is only triggered when the - * verification callback URL is specified in your dashboard. - * - * @param id The ID of the verification request. - * @param event The type of the event. - * @param method The verification method - * @param identity Specifies the type of endpoint that will be verified and the particular - * endpoint. number is currently the only supported endpoint type - * @param reference The reference ID that was optionally passed together with the verification - * request - * @param custom A custom string that can be provided during a verification request. - * @param status The status of the verification request - * @param reason Displays the reason why a verification has FAILED, was DENIED, or was ABORTED - * @param source Free text that the client is sending, used to show if the call/SMS was - * intercepted or not. see https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/#tag/Verification-callbacks/paths/VerificationResultEvent/post - * @since 1.0 - */ @JsonCreator VerificationResultEvent( @JsonProperty("id") String id, @@ -52,14 +37,32 @@ public class VerificationResultEvent extends VerificationEvent { this.source = null != source ? VerificationSourceType.from(source) : null; } + /** + * The status of the verification request + * + * @return Status value + * @since 1.0 + */ public VerificationReportStatusType getStatus() { return status; } + /** + * Displays the reason why a verification has FAILED, was DENIED, or was ABORTED + * + * @return reason value + * @since 1.0 + */ public Optional getReason() { return Optional.ofNullable(reason); } + /** + * Used to show if the call/SMS was intercepted or not + * + * @return Type value + * @since 1.0 + */ public Optional getSource() { return Optional.ofNullable(source); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/package-info.java b/client/src/main/com/sinch/sdk/domains/verification/package-info.java index bd726f72..20f607c8 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/package-info.java +++ b/client/src/main/com/sinch/sdk/domains/verification/package-info.java @@ -1,6 +1,8 @@ /** * Verification API interface * + * @see https://developers.sinch.com/docs/verification * @since 1.0 */ package com.sinch.sdk.domains.verification; diff --git a/client/src/main/com/sinch/sdk/models/Configuration.java b/client/src/main/com/sinch/sdk/models/Configuration.java index 72f7bf8b..0f351bcc 100644 --- a/client/src/main/com/sinch/sdk/models/Configuration.java +++ b/client/src/main/com/sinch/sdk/models/Configuration.java @@ -284,30 +284,47 @@ public String getApplicationSecret() { return applicationSecret; } + /** + * Getting Builder + * + * @return New Builder instance + * @since 1.0 + */ public static Builder builder() { return new Builder(); } + /** + * Getting Builder + * + * @param configuration Source configuration to fill initial builder state + * @return New Builder instance + * @since 1.0 + */ public static Builder builder(Configuration configuration) { return new Builder(configuration); } - /** Configuration builder */ + /** + * Dedicated Builder + * + * @since 1.0 + */ public static class Builder { - public String keyId; - public String keySecret; - public String projectId; - public String oauthUrl; - public String numbersUrl; - public SMSRegion smsRegion; - public String smsUrl; - public String verificationUrl; - public String applicationKey; - public String applicationSecret; - public VoiceRegion voiceRegion; - public String voiceUrl; - public String voiceApplicationMngmtUrl; + String keyId; + String keySecret; + String projectId; + String oauthUrl; + String numbersUrl; + SMSRegion smsRegion; + String smsUrl; + String verificationUrl; + String applicationKey; + String applicationSecret; + VoiceRegion voiceRegion; + String voiceUrl; + String voiceApplicationMngmtUrl; protected Builder() {} @@ -333,29 +350,6 @@ protected Builder(Configuration configuration) { this.voiceApplicationMngmtUrl = configuration.getVoiceApplicationManagementUrl(); } - /** - * Build a Configuration instance from builder current state - * - * @return Configuration instance build from current builder state - * @since 1.0 - */ - public Configuration build() { - return new Configuration( - keyId, - keySecret, - projectId, - oauthUrl, - numbersUrl, - smsRegion, - smsUrl, - verificationUrl, - voiceRegion, - voiceUrl, - voiceApplicationMngmtUrl, - applicationKey, - applicationSecret); - } - /** * Set key ID * @@ -511,5 +505,52 @@ public Builder setApplicationSecret(String applicationSecret) { this.applicationSecret = applicationSecret; return this; } + + /** + * Setter + * + *

See {@link Configuration#getVoiceRegion()} getter + * + * @return Current builder + * @since 1.0 + */ + public VoiceRegion getVoiceRegion() { + return voiceRegion; + } + + /** + * Setter + * + *

See {@link Configuration#getVoiceUrl()} getter + * + * @return Current builder + * @since 1.0 + */ + public String getVoiceUrl() { + return voiceUrl; + } + + /** + * Create instance + * + * @return The instance build with current builder values + * @since 1.0 + */ + public Configuration build() { + return new Configuration( + keyId, + keySecret, + projectId, + oauthUrl, + numbersUrl, + smsRegion, + smsUrl, + verificationUrl, + voiceRegion, + voiceUrl, + voiceApplicationMngmtUrl, + applicationKey, + applicationSecret); + } } } diff --git a/client/src/main/com/sinch/sdk/models/E164PhoneNumber.java b/client/src/main/com/sinch/sdk/models/E164PhoneNumber.java index 829ea00e..728736d5 100644 --- a/client/src/main/com/sinch/sdk/models/E164PhoneNumber.java +++ b/client/src/main/com/sinch/sdk/models/E164PhoneNumber.java @@ -6,6 +6,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** E164 Phone Number representation class helper */ public class E164PhoneNumber { private static final Logger LOGGER = Logger.getLogger(E164PhoneNumber.class.getName()); @@ -28,7 +29,12 @@ public class E164PhoneNumber { private static final AtomicBoolean STRICT = new AtomicBoolean(false); private final String number; - public E164PhoneNumber(String number) { + /** + * Create a new instance + * + * @param number Phone number value + */ + private E164PhoneNumber(String number) { if (!validate(number)) { String message = String.format("Invalid E164 format for '%s' number", number); @@ -40,11 +46,26 @@ public E164PhoneNumber(String number) { this.number = number; } + /** + * Create a new instance + * + * @param value Phone number value + * @return The newly created E164 instance + */ public static E164PhoneNumber valueOf(String value) { return new E164PhoneNumber(value); } + /** + * Validate value against E164 representation pattern, + * + * @param value String value representation to be checked + * @return TRUE/FALSE + */ public static boolean validate(String value) { + if (null == value) { + return false; + } // don't worry about spaces Matcher matcher = PATTERN.matcher(value.replaceAll("\\s+", "")); return matcher.matches(); @@ -59,6 +80,11 @@ public static void setStrict(boolean strict) { E164PhoneNumber.STRICT.set(strict); } + /** + * Get current value as a String + * + * @return The value + */ public String stringValue() { return number; } diff --git a/client/src/main/com/sinch/sdk/models/VoiceRegion.java b/client/src/main/com/sinch/sdk/models/VoiceRegion.java index b6ccd81f..48751878 100644 --- a/client/src/main/com/sinch/sdk/models/VoiceRegion.java +++ b/client/src/main/com/sinch/sdk/models/VoiceRegion.java @@ -11,6 +11,10 @@ *

When using methods concerning individual calls, you can define what regional endpoint you want * to use for the call. The following regional endpoints are available: * + *

For cases where the call is the result of an incoming PSTN, SIP or data call, the endpoint to + * use for managing that call is supplied in the ICE event. ICE callbacks will also provide + * region-specific URLs in the callResourceUrl property. + * * @see endpoints * description */ @@ -19,10 +23,19 @@ public class VoiceRegion extends EnumDynamic { /** Global - redirected by Sinch to the closest region */ public static final VoiceRegion GLOBAL = new VoiceRegion("global"); + /** Europe */ public static final VoiceRegion EUROPE = new VoiceRegion("europe"); + + /** North America */ public static final VoiceRegion NORTH_AMERICA = new VoiceRegion("north-america"); + + /** South America */ public static final VoiceRegion SOUTH_AMERICA = new VoiceRegion("south-america"); + + /** South East Asia 1 */ public static final VoiceRegion SOUTH_EAST_ASIA1 = new VoiceRegion("south-east-asia1"); + + /** South East Asia 2 */ public static final VoiceRegion SOUTH_EAST_ASIA2 = new VoiceRegion("south-east-asia2"); private static final EnumSupportDynamic ENUM_SUPPORT = @@ -36,14 +49,31 @@ private VoiceRegion(String value) { super(value); } + /** + * Get declared values + * + * @return Stream of values + */ public static Stream values() { return ENUM_SUPPORT.values(); } + /** + * Get value from a string + * + * @param value String identifier + * @return Dynamic enum from value. A new enum is created if value is not yet registered + */ public static VoiceRegion from(String value) { return ENUM_SUPPORT.from(value); } + /** + * Value of the enum as String + * + * @param value The enum identifier + * @return String identifier of the enum value + */ public static String valueOf(VoiceRegion value) { return ENUM_SUPPORT.valueOf(value); } diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/WebhooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/WebhooksServiceTest.java index f7c3bb9f..2027bb25 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/WebhooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/WebhooksServiceTest.java @@ -36,7 +36,7 @@ void checkApplicationAuthentication() throws ApiException { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); boolean authenticationResult = - webHooksService.validateAuthenticatedRequest( + webHooksService.validateAuthenticationHeader( "POST", "/VerificationRequestEvent", headers, request); Assertions.assertThat(authenticationResult).isEqualTo(true); diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java index 73920436..b2704aab 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java @@ -4,7 +4,6 @@ import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.Price; import com.sinch.sdk.domains.verification.models.VerificationId; -import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; import com.sinch.sdk.domains.verification.models.VerificationReportCallout; import com.sinch.sdk.domains.verification.models.VerificationReportFlashCall; @@ -16,8 +15,11 @@ import com.sinch.sdk.domains.verification.models.dto.v1.StartVerificationResponseDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.VerificationReportDtoTest; import com.sinch.sdk.domains.verification.models.dto.v1.VerificationReportRequestDtoTest; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationCalloutRequestParameters; import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationSMSRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationSeamlessRequestParameters; import com.sinch.sdk.domains.verification.models.requests.VerificationReportCalloutRequestParameters; import com.sinch.sdk.domains.verification.models.requests.VerificationReportFlashCallRequestParameters; import com.sinch.sdk.domains.verification.models.requests.VerificationReportSMSRequestParameters; @@ -31,7 +33,7 @@ public class VerificationsDtoConverterTest extends BaseTest { public static StartVerificationRequestParameters startVerificationCalloutRequest = - StartVerificationRequestParameters.builder(VerificationMethodType.CALLOUT) + StartVerificationCalloutRequestParameters.builder() .setCustom("a custom") .setReference(VerificationReference.valueOf("a reference")) .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) @@ -60,7 +62,7 @@ public class VerificationsDtoConverterTest extends BaseTest { .setDenyCallAfter(0) .build(); public static StartVerificationRequestParameters startVerificationSeamlessRequest = - StartVerificationRequestParameters.builder(VerificationMethodType.SEAMLESS) + StartVerificationSeamlessRequestParameters.builder() .setCustom("a custom") .setReference(VerificationReference.valueOf("a reference")) .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) @@ -72,7 +74,7 @@ public class VerificationsDtoConverterTest extends BaseTest { .setTargetUri("target URI") .build(); public static StartVerificationRequestParameters startVerificationSMSRequest = - StartVerificationRequestParameters.builder(VerificationMethodType.SMS) + StartVerificationSMSRequestParameters.builder() .setCustom("a custom") .setReference(VerificationReference.valueOf("a reference")) .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParametersTest.java similarity index 72% rename from client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java rename to client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParametersTest.java index cb953a3f..dbaac6bb 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationCalloutRequestParametersTest.java @@ -1,23 +1,21 @@ package com.sinch.sdk.domains.verification.models.requests; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -class StartVerificationRequestParametersTest { +class StartVerificationCalloutRequestParametersTest { - final Identity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final NumberIdentity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); final VerificationMethodType method = VerificationMethodType.CALLOUT; final String reference = "foo reference"; final String custom = "foo custom"; - final StartVerificationRequestParameters value = - StartVerificationRequestParameters.builder() + final StartVerificationCalloutRequestParameters value = + StartVerificationCalloutRequestParameters.builder() .setIdentity(identity) - .setMethod(method) .setReference(VerificationReference.valueOf(reference)) .setCustom(custom) .build(); @@ -29,7 +27,7 @@ void getIdentity() { @Test void getMethod() { - Assertions.assertThat(value.getMethod().get()).isEqualTo(method); + Assertions.assertThat(value.getMethod()).isEqualTo(method); } @Test diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java index aa9fa68c..72411f7c 100644 --- a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java @@ -1,6 +1,5 @@ package com.sinch.sdk.domains.verification.models.requests; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReference; @@ -9,7 +8,7 @@ class StartVerificationFlashCallRequestParametersTest { - final Identity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final NumberIdentity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); final VerificationMethodType method = VerificationMethodType.FLASH_CALL; final String reference = "foo reference"; final String custom = "foo custom"; @@ -30,7 +29,7 @@ void getIdentity() { @Test void getMethod() { - Assertions.assertThat(value.getMethod().get()).isEqualTo(method); + Assertions.assertThat(value.getMethod()).isEqualTo(method); } @Test diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParametersTest.java new file mode 100644 index 00000000..aa4b955b --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSMSRequestParametersTest.java @@ -0,0 +1,42 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.VerificationReference; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class StartVerificationSMSRequestParametersTest { + + final NumberIdentity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final VerificationMethodType method = VerificationMethodType.SMS; + final String reference = "foo reference"; + final String custom = "foo custom"; + + final StartVerificationSMSRequestParameters value = + StartVerificationSMSRequestParameters.builder() + .setIdentity(identity) + .setReference(VerificationReference.valueOf(reference)) + .setCustom(custom) + .build(); + + @Test + void getIdentity() { + Assertions.assertThat(value.getIdentity().get()).isEqualTo(identity); + } + + @Test + void getMethod() { + Assertions.assertThat(value.getMethod()).isEqualTo(method); + } + + @Test + void getReference() { + Assertions.assertThat(value.getReference().get().getReference()).isEqualTo(reference); + } + + @Test + void getCustom() { + Assertions.assertThat(value.getCustom().get()).isEqualTo(custom); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParametersTest.java new file mode 100644 index 00000000..3b121e28 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationSeamlessRequestParametersTest.java @@ -0,0 +1,42 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.VerificationReference; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class StartVerificationSeamlessRequestParametersTest { + + final NumberIdentity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final VerificationMethodType method = VerificationMethodType.SEAMLESS; + final String reference = "foo reference"; + final String custom = "foo custom"; + + final StartVerificationSeamlessRequestParameters value = + StartVerificationSeamlessRequestParameters.builder() + .setIdentity(identity) + .setReference(VerificationReference.valueOf(reference)) + .setCustom(custom) + .build(); + + @Test + void getIdentity() { + Assertions.assertThat(value.getIdentity().get()).isEqualTo(identity); + } + + @Test + void getMethod() { + Assertions.assertThat(value.getMethod()).isEqualTo(method); + } + + @Test + void getReference() { + Assertions.assertThat(value.getReference().get().getReference()).isEqualTo(reference); + } + + @Test + void getCustom() { + Assertions.assertThat(value.getCustom().get()).isEqualTo(custom); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParametersTest.java deleted file mode 100644 index 49599445..00000000 --- a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/VerificationReportRequestParametersTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.sinch.sdk.domains.verification.models.requests; - -import com.sinch.sdk.domains.verification.models.VerificationMethodType; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -class VerificationReportRequestParametersTest { - - final VerificationMethodType method = VerificationMethodType.CALLOUT; - - final VerificationReportRequestParameters value = - VerificationReportRequestParameters.builder().setMethod(method).build(); - - @Test - void getMethod() { - Assertions.assertThat(value.getMethod().get()).isEqualTo(method); - } -} diff --git a/client/src/test/java/com/sinch/sdk/domains/voice/adapters/VoiceServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/voice/adapters/VoiceServiceTest.java new file mode 100644 index 00000000..4668f2fe --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/voice/adapters/VoiceServiceTest.java @@ -0,0 +1,37 @@ +package com.sinch.sdk.domains.voice.adapters; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.verification.adapters.VerificationService; +import com.sinch.sdk.models.Configuration; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +class VoiceServiceTest { + + @Mock HttpClient httpClient; + + @Test + void doNotAcceptNullApplicationKey() { + Configuration configuration = + Configuration.builder().setApplicationKey(null).setApplicationSecret("foo secret").build(); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new VerificationService(configuration, httpClient)); + assertTrue(exception.getMessage().contains("applicationKey")); + } + + @Test + void doNotAcceptNullApplicationSecret() { + Configuration configuration = + Configuration.builder().setApplicationKey("foo key").setApplicationSecret(null).build(); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new VerificationService(configuration, httpClient)); + assertTrue(exception.getMessage().contains("applicationSecret")); + } +} diff --git a/client/src/test/java/com/sinch/sdk/models/E164PhoneNumberTest.java b/client/src/test/java/com/sinch/sdk/models/E164PhoneNumberTest.java index 5ce02892..f195d9ad 100644 --- a/client/src/test/java/com/sinch/sdk/models/E164PhoneNumberTest.java +++ b/client/src/test/java/com/sinch/sdk/models/E164PhoneNumberTest.java @@ -30,12 +30,7 @@ class E164PhoneNumberTest { @Test void stringValue() { - assertEquals(new E164PhoneNumber(phoneNumber).stringValue(), phoneNumber); - } - - @Test - void valueOf() { - assertEquals(E164PhoneNumber.valueOf(phoneNumber), new E164PhoneNumber(phoneNumber)); + assertEquals(E164PhoneNumber.valueOf(phoneNumber).stringValue(), phoneNumber); } @Test diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiAuthException.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiAuthException.java index 7f202431..e1159f81 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiAuthException.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiAuthException.java @@ -2,19 +2,36 @@ import com.sinch.sdk.core.http.HttpStatus; +/** + * Exception related to server authentication + * + * @since 1.0 + */ public class ApiAuthException extends ApiException { private static final long serialVersionUID = -1L; + /** + * Constructs a new exception with the specified cause and a detail message of (cause==null ? null + * : cause.toString()) (which typically contains the class and detail message of cause). This + * constructor is useful for exceptions that are little more than wrappers for other throwables + * + * @param throwable the cause (which is saved for later retrieval by the Throwable.getCause() + * method). (A null value is permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.0 + */ public ApiAuthException(Throwable throwable) { super(null, throwable, HttpStatus.UNAUTHORIZED); } + /** + * Constructs an ApiAuthException with the specified detail message. + * + * @param message the detail message. + * @since 1.0 + */ public ApiAuthException(String message) { super(message, null, HttpStatus.UNAUTHORIZED); } - - public ApiAuthException(int code, String message) { - super(message, null, code); - } } diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java index 883fb3fa..9e5ae274 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiException.java @@ -1,33 +1,65 @@ package com.sinch.sdk.core.exceptions; +/** Base Sinch Client API exception */ public class ApiException extends RuntimeException { private static final long serialVersionUID = -1L; - private int code = 0; + /** {@hidden} */ + private int code; + + /** Constructs an ApiException with no detail message. */ public ApiException() {} + /** + * Constructs a new exception with the specified cause and a detail message of (cause==null ? null + * : cause.toString()) (which typically contains the class and detail message of cause). This + * constructor is useful for exceptions that are little more than wrappers for other throwables + * + * @param throwable Cause + */ public ApiException(Throwable throwable) { super(throwable); } + /** + * Constructs an ApiException with the specified detail message. + * + * @param message the detail message. + * @since 1.0 + */ public ApiException(String message) { super(message); } + /** + * Constructs an ApiException with the specified detail message and with the specified cause + * + * @param message The detail message + * @param throwable Cause + */ public ApiException(String message, Throwable throwable) { super(message, throwable); } + /** + * Constructs an ApiException with the specified detail message, the specified cause and a code + * + * @param message The detail message + * @param throwable Cause + * @param code Code + */ public ApiException(String message, Throwable throwable, int code) { super(message, throwable); this.code = code; } - public ApiException(String message, int code) { - this(message, null, code); - } - + /** + * Constructs an ApiException with the specified detail message and a code + * + * @param code Code + * @param message The detail message + */ public ApiException(int code, String message) { this(message, null, code); } diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java index c437e0fc..76b2f3f9 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiExceptionBuilder.java @@ -3,12 +3,21 @@ import java.util.Map; import java.util.Optional; +/** APIException Builder helper to transform dedicated domains error response to Exception */ public class ApiExceptionBuilder { - public static ApiException build(String message, int code) { - return new ApiException(message, code); - } - + private ApiExceptionBuilder() {} + ; + + /** + * Consume Unqualified Map of fields received from an API error into a dedicated Exception + * + * @param message the detail message. + * @param code Code + * @param mappedResponse Map of fields (usually coming from a JSON representation) to be + * interpreted + * @return Dedicated ApiException + */ public static ApiException build(String message, int code, Map mappedResponse) { // Hardcoded Numbers API errors like format parsing @@ -17,13 +26,13 @@ public static ApiException build(String message, int code, Map mapped return exception.get(); } - exception = getExceptionFromSmsError(mappedResponse); + exception = getExceptionFromSmsError(code, mappedResponse); if (exception.isPresent()) { return exception.get(); } exception = getExceptionFromVerificationError(mappedResponse); - return exception.orElseGet(() -> new ApiException(message, code)); + return exception.orElseGet(() -> new ApiException(code, message)); } private static Optional getExceptionFromNumbersError(Map mappedResponse) { @@ -57,13 +66,14 @@ private static Optional getExceptionFromNumbersError(Map map } return Optional.of( - new ApiException(String.format("%s: %s", statusValue, messageValue), codeValue)); + new ApiException(codeValue, String.format("%s: %s", statusValue, messageValue))); } - private static Optional getExceptionFromSmsError(Map mappedResponse) { + private static Optional getExceptionFromSmsError( + int intCode, Map mappedResponse) { // excepted SMS API errors have following form - // "code": int, + // "code": string, // "text": string, // } @@ -78,7 +88,7 @@ private static Optional getExceptionFromSmsError(Map mappedR return Optional.empty(); } - return Optional.of(new ApiException(String.format("%s: %s", code, text))); + return Optional.of(new ApiException(intCode, String.format("%s: %s", code, text))); } private static Optional getExceptionFromVerificationError( @@ -106,6 +116,6 @@ private static Optional getExceptionFromVerificationError( return Optional.of( new ApiException( - String.format("%s (reference=%s)", messageValue, referenceValue), codeValue)); + codeValue, String.format("%s (reference=%s)", messageValue, referenceValue))); } } diff --git a/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java b/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java index 426aedcd..f9d4cafb 100644 --- a/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java +++ b/core/src/main/com/sinch/sdk/core/exceptions/ApiMappingException.java @@ -1,7 +1,14 @@ package com.sinch.sdk.core.exceptions; +/** Sinch Client exception related to payload parsing/mapping error */ public class ApiMappingException extends ApiException { + /** + * Exception throw when parsing a payload was causing an issue + * + * @param payload Payload causing error + * @param throwable Cause + */ public ApiMappingException(String payload, Throwable throwable) { super(String.format("Unable to map string '%s'", payload), throwable); } diff --git a/core/src/main/com/sinch/sdk/core/models/ServerConfiguration.java b/core/src/main/com/sinch/sdk/core/models/ServerConfiguration.java index 5a0dcbaa..fa8d2583 100644 --- a/core/src/main/com/sinch/sdk/core/models/ServerConfiguration.java +++ b/core/src/main/com/sinch/sdk/core/models/ServerConfiguration.java @@ -1,17 +1,24 @@ package com.sinch.sdk.core.models; -/** Representing a Server configuration. */ +/** Class used to store server related information and configuration */ public class ServerConfiguration { - public final String url; + private final String url; /** + * Create a server confiration from URL + * * @param url A URL to the target host. */ public ServerConfiguration(String url) { this.url = url; } + /** + * Get URL related to server + * + * @return The URL value + */ public String getUrl() { return url; } diff --git a/core/src/main/com/sinch/sdk/core/models/pagination/CursorPageNavigator.java b/core/src/main/com/sinch/sdk/core/models/pagination/CursorPageNavigator.java index bac2a6f3..82ed60d6 100644 --- a/core/src/main/com/sinch/sdk/core/models/pagination/CursorPageNavigator.java +++ b/core/src/main/com/sinch/sdk/core/models/pagination/CursorPageNavigator.java @@ -1,11 +1,19 @@ package com.sinch.sdk.core.models.pagination; +/** Cursor Based Page Navigator */ public class CursorPageNavigator extends PageNavigator { private final Integer currentPage; private final Integer pageSize; private final Long collectionSize; + /** + * Create new instance + * + * @param currentPage Current page value + * @param pageSize Page size + * @param collectionSize Size of collection + */ public CursorPageNavigator(Integer currentPage, Integer pageSize, Long collectionSize) { super(null); this.currentPage = currentPage; @@ -19,6 +27,7 @@ private Integer computeNextPageCursor() { return ((currentPage + 1) * Long.valueOf(pageSize)) >= collectionSize ? null : currentPage + 1; } + /** {@inheritDoc} */ @Override public Integer getToken() { return computeNextPageCursor(); diff --git a/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java b/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java index cb59dd4d..cdd8228b 100644 --- a/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java +++ b/core/src/main/com/sinch/sdk/core/models/pagination/ListResponse.java @@ -17,6 +17,8 @@ */ public abstract class ListResponse { + protected ListResponse() {} + /** * Indicate if another page response is available * diff --git a/core/src/main/com/sinch/sdk/core/models/pagination/PageNavigator.java b/core/src/main/com/sinch/sdk/core/models/pagination/PageNavigator.java index 7faa7ffa..933dfd38 100644 --- a/core/src/main/com/sinch/sdk/core/models/pagination/PageNavigator.java +++ b/core/src/main/com/sinch/sdk/core/models/pagination/PageNavigator.java @@ -1,12 +1,22 @@ package com.sinch.sdk.core.models.pagination; +/** + * Base class for PageNavigator + * + * @param Token type + */ public class PageNavigator { private final T token; - public PageNavigator(T token) { + protected PageNavigator(T token) { this.token = token; } + /** + * Get current page navigator token + * + * @return Token value + */ public T getToken() { return token; } diff --git a/core/src/main/com/sinch/sdk/core/models/pagination/TokenPageNavigator.java b/core/src/main/com/sinch/sdk/core/models/pagination/TokenPageNavigator.java index bce0f7db..e82fa8cd 100644 --- a/core/src/main/com/sinch/sdk/core/models/pagination/TokenPageNavigator.java +++ b/core/src/main/com/sinch/sdk/core/models/pagination/TokenPageNavigator.java @@ -1,7 +1,13 @@ package com.sinch.sdk.core.models.pagination; +/** Token Based Page Navigator */ public class TokenPageNavigator extends PageNavigator { + /** + * Create new instance + * + * @param token The token value + */ public TokenPageNavigator(String token) { super(token); } diff --git a/core/src/main/com/sinch/sdk/core/utils/DateUtil.java b/core/src/main/com/sinch/sdk/core/utils/DateUtil.java index 8d6c2a23..c09a7479 100644 --- a/core/src/main/com/sinch/sdk/core/utils/DateUtil.java +++ b/core/src/main/com/sinch/sdk/core/utils/DateUtil.java @@ -6,6 +6,9 @@ /** Utility class for Date */ public class DateUtil { + private DateUtil() {} + ; + /** * Convert an OffsetDateTime to Instant with null value protection * diff --git a/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java b/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java index bc2a6afb..964ecaaa 100644 --- a/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java +++ b/core/src/main/com/sinch/sdk/core/utils/EnumDynamic.java @@ -23,17 +23,24 @@ public T value() { return value; } + @Override public String toString() { return value().toString(); } - public boolean equals(E o) { + @Override + public boolean equals(Object o) { if (o == this) { return true; } - return java.util.Objects.equals(this.value, o.value()); + if (!(o instanceof EnumDynamic)) { + return false; + } + + return java.util.Objects.equals(this.value, ((EnumDynamic) o).value()); } + @Override public int hashCode() { return value.hashCode(); } diff --git a/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java b/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java index b8d25d46..e903cd75 100644 --- a/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java +++ b/core/src/main/com/sinch/sdk/core/utils/EnumSupportDynamic.java @@ -17,8 +17,9 @@ *

Typical use case: being able to send and/or receive values not yet defined at SDK version * release * - * @param Value type - * @param Value instance + * @param Value type associated to dynamic enum + * @param Dynamic enum class instance + * @since 1.0 */ public final class EnumSupportDynamic> { private static final Logger LOGGER = Logger.getLogger(EnumSupportDynamic.class.getName()); @@ -29,6 +30,14 @@ public final class EnumSupportDynamic> { private volatile List values; + /** + * Create a new instance of managing a dynamic enum + * + * @param aClass Related class stored with dynamic enum support + * @param surplusFactory Factory T function to create a new dynamic enum value + * @param values Values managed/stored by dynamic enum class + * @since 1.0 + */ public EnumSupportDynamic(Class aClass, Function surplusFactory, List values) { this.aClass = aClass; @@ -43,14 +52,32 @@ private static List createImmutableList(List values2, E newValue) { return Collections.unmodifiableList(newValues); } + /** + * Get known values + * + * @return Stream of values + * @since 1.0 + */ public Stream values() { return values.stream(); } + /** + * Returns the value used to create the enum + * + * @param e the enum + * @return Value associated to enum onto creation + */ public T valueOf(E e) { return e == null ? null : e.value(); } + /** + * Transform Collection to List + * + * @param values Collection of values to be transformed + * @return Created List + */ public List valuesOf(Collection values) { if (values == null) { return null; @@ -58,6 +85,12 @@ public List valuesOf(Collection values) { return values.stream().map(this::valueOf).collect(toList()); } + /** + * Get List of enum from Collection and create undefined Enum from the Collection if required + * + * @param values Collection of values to be used to fill returned List + * @return List of enum related to source Collection + */ public List fromValues(Collection values) { if (values == null) { return null; @@ -65,6 +98,15 @@ public List fromValues(Collection values) { return values.stream().map(this::from).collect(toList()); } + /** + * Get a dynamic enum from value + * + *

If no dynamic enum was already created with value param, a new value is created + * and returned + * + * @param value Value to be associated to newly create element + * @return Dynamic enum + */ public E from(T value) { if (value == null) { return null; @@ -94,13 +136,21 @@ public E from(T value) { } } + /** + * Compare two dynamic enum + * + * @param o1 the first object to compare + * @param o2 the second object to compare + * @return the value 0 if o1 == o2& a value less than 0 if o1 < o2; and a value greater + * than 0 if o1 > o2 + */ public int compare(Object o1, Object o2) { String v1 = toComparableValue(o1); String v2 = toComparableValue(o2); return Objects.compare(v1, v2, String::compareTo); } - public String toComparableValue(Object o) { + private String toComparableValue(Object o) { if (o == null) { return null; diff --git a/core/src/main/com/sinch/sdk/core/utils/StringUtil.java b/core/src/main/com/sinch/sdk/core/utils/StringUtil.java index cb9c2b88..26ab3900 100644 --- a/core/src/main/com/sinch/sdk/core/utils/StringUtil.java +++ b/core/src/main/com/sinch/sdk/core/utils/StringUtil.java @@ -3,6 +3,8 @@ /** Utility class for string */ public class StringUtil { + private StringUtil() {} + /** * Check if a string is empty * diff --git a/core/src/test/java/com/sinch/sdk/core/exceptions/ApiExceptionBuilderTest.java b/core/src/test/java/com/sinch/sdk/core/exceptions/ApiExceptionBuilderTest.java index c1e2643c..bdf43eef 100644 --- a/core/src/test/java/com/sinch/sdk/core/exceptions/ApiExceptionBuilderTest.java +++ b/core/src/test/java/com/sinch/sdk/core/exceptions/ApiExceptionBuilderTest.java @@ -2,37 +2,79 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.utils.databind.Mapper; import java.util.HashMap; import org.junit.jupiter.api.Test; -class ApiExceptionBuilderTest { +@TestWithResources +class ApiExceptionBuilderTest extends BaseTest { - private static final String numberErrorMocked = - "{ \"error\": {" - + "\"code\": 202," - + "\"message\": \"my error message\"," - + "\"status\": \"MY_STATUS\"" + private static final String unknownErrorMocked = + "{ \"foo\": {" + + "\"foo\": 202," + + "\"foo\": \"my error message\"," + + "\"foo\": \"MY_STATUS\"" + "}}"; + @GivenTextResource("/domains/numbers/v1/error-trial-account.json") + String numberError; + + @GivenTextResource("/domains/sms/v1/error-response.json") + String smsError; + + @GivenTextResource("/domains/verification/v1/error-response.json") + String verificationError; + @Test - void buildFromMessage() { - ApiException e = ApiExceptionBuilder.build("message", 202); + void buildFromObject() throws JsonProcessingException { + ApiException e = + ApiExceptionBuilder.build( + "message", + 202, + Mapper.getInstance() + .readValue(unknownErrorMocked, new TypeReference>() {})); assertEquals("message", e.getMessage()); assertEquals(202, e.getCode()); } @Test - void buildFromObject() throws JsonProcessingException { + void numbersError() throws JsonProcessingException { ApiException e = ApiExceptionBuilder.build( "message", 202, Mapper.getInstance() - .readValue(numberErrorMocked, new TypeReference>() {})); - assertEquals("MY_STATUS: my error message", e.getMessage()); + .readValue(numberError, new TypeReference>() {})); + assertEquals("PERMISSION_DENIED: Trial account is not enabled to rent number", e.getMessage()); + assertEquals(403, e.getCode()); + } + + @Test + void smsError() throws JsonProcessingException { + ApiException e = + ApiExceptionBuilder.build( + "message", + 202, + Mapper.getInstance().readValue(smsError, new TypeReference>() {})); + assertEquals( + "syntax_invalid_parameter_format: 'foo' is not a valid identifier", e.getMessage()); assertEquals(202, e.getCode()); } + + @Test + void verificationError() throws JsonProcessingException { + ApiException e = + ApiExceptionBuilder.build( + "message", + 202, + Mapper.getInstance() + .readValue(verificationError, new TypeReference>() {})); + assertEquals("Requested resource was not found. (reference=a reference)", e.getMessage()); + assertEquals(40400, e.getCode()); + } } diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/error-response.json b/openapi-contracts/src/test/resources/domains/sms/v1/error-response.json new file mode 100644 index 00000000..cdc8e327 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/error-response.json @@ -0,0 +1,4 @@ +{ + "code": "syntax_invalid_parameter_format", + "text": "'foo' is not a valid identifier" +} diff --git a/openapi-contracts/src/test/resources/domains/verification/v1/error-response.json b/openapi-contracts/src/test/resources/domains/verification/v1/error-response.json new file mode 100644 index 00000000..7034609a --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/verification/v1/error-response.json @@ -0,0 +1,5 @@ +{ + "errorCode": 40400, + "message": "Requested resource was not found.", + "reference": "a reference" +} diff --git a/sample-app/README.md b/sample-app/README.md index 46b0abe5..d77b27af 100644 --- a/sample-app/README.md +++ b/sample-app/README.md @@ -64,6 +64,7 @@ See https://developers.sinch.com for details about these parameters ### Full workflows - Numbers: A full application chaining calls to Numbers service to onboard onto Java SDK and Numbers: [NumbersSampleFlow](src/main/java/com/sinch/sample/numbers/NumbersSampleFlow.java) +- Verification: An interactive console application sending a SMS verification and returning the report result: [VerificationsSampleFlowInteractive](src/main/java/com/sinch/sample/verification/VerificationsSampleFlowInteractive.java) - Voice Conferences: A full application chaining calls to voice service to join and manage a conference: [ConferencesSampleFlow](src/main/java/com/sinch/sample/voice/ConferencesSampleFlow.java) ### Dedicated service feature samples diff --git a/sample-app/src/main/java/com/sinch/sample/verification/VerificationsSampleFlowInteractive.java b/sample-app/src/main/java/com/sinch/sample/verification/VerificationsSampleFlowInteractive.java new file mode 100644 index 00000000..fd14c020 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/verification/VerificationsSampleFlowInteractive.java @@ -0,0 +1,161 @@ +package com.sinch.sample.verification; + +import static com.sinch.sample.BaseApplication.PHONE_NUMBER_KEY; +import static com.sinch.sample.Utils.echo; + +import com.sinch.sample.Utils; +import com.sinch.sdk.SinchClient; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.utils.StringUtil; +import com.sinch.sdk.domains.verification.VerificationsService; +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationId; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationSMSRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.VerificationReportSMSRequestParameters; +import com.sinch.sdk.models.Configuration; +import com.sinch.sdk.models.E164PhoneNumber; +import java.util.Scanner; +import java.util.logging.Logger; + +public class VerificationsSampleFlowInteractive { + + private static final Logger LOGGER = + Utils.initializeLogger(VerificationsSampleFlowInteractive.class.getName()); + + public static void main(String[] args) { + + try { + var properties = Utils.loadProperties(LOGGER); + var configuration = Utils.loadConfiguration(LOGGER); + var phoneNumber = + null != System.getenv(PHONE_NUMBER_KEY) + ? System.getenv(PHONE_NUMBER_KEY) + : properties.getProperty(PHONE_NUMBER_KEY); + new VerificationsSampleFlowInteractive().run(configuration, phoneNumber); + } catch (ApiException apiException) { + LOGGER.severe(apiException.toString()); + System.exit(-1); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public void run(Configuration configuration, String phoneNumber) throws InterruptedException { + + VerificationsService service = new SinchClient(configuration).verification().verifications(); + + //noinspection InfiniteLoopStatement + do { + + E164PhoneNumber e164Number; + + // Console input for phone number if not set by default + if (StringUtil.isEmpty(phoneNumber)) { + e164Number = queryPhoneNumber(); + } else { + e164Number = E164PhoneNumber.valueOf(phoneNumber); + } + + try { + // Starting verification onto phone number + VerificationId id = startSmsVerification(service, e164Number); + + // Ask user for received code + String code = queryCode(); + + // Query report + reportSmsVerification(service, code, id); + phoneNumber = null; + } catch (ApiException e) { + echo("Error (%d): %s".formatted(e.getCode(), e.getMessage())); + } + } while (true); + } + + /** + * Will start an SMS verification onto specified phone number + * + * @param service Verification service + * @param phoneNumber Destination phone number + * @return Verification ID + */ + private VerificationId startSmsVerification( + VerificationsService service, E164PhoneNumber phoneNumber) { + + var parameters = + StartVerificationSMSRequestParameters.builder() + .setIdentity(NumberIdentity.valueOf(phoneNumber)) + .build(); + echo("Sending verification request onto '%s'".formatted(phoneNumber.stringValue())); + + var response = service.start(parameters); + echo("Verification started with ID '%s'".formatted(response.getId())); + return response.getId(); + } + + /** + * Will query for a verification report by ID + * + * @param service Verification service + * @param code Code received by SMS + * @param id Verification ID related to the verification + */ + private void reportSmsVerification(VerificationsService service, String code, VerificationId id) { + var parameters = VerificationReportSMSRequestParameters.builder().setCode(code).build(); + + echo("Requesting report for '%s'".formatted(id.getId())); + var response = service.report(id, parameters); + echo("Report response: %s".formatted(response)); + } + + /** + * Query user for a valid phone number + * + * @return Phone number value + */ + private E164PhoneNumber queryPhoneNumber() { + String input; + boolean valid; + do { + input = prompt("\nEnter a phone number to start verification"); + valid = E164PhoneNumber.validate(input); + if (!valid) { + echo("Invalid number '%s'".formatted(input)); + } + } while (!valid); + + return E164PhoneNumber.valueOf(input); + } + + /** + * Query user for a code + * + * @return Value entered by user + */ + private String queryCode() { + return prompt("Enter the verification code to report the verification"); + } + + /** + * Endless loop for user input until a valid string is entered or 'Q' to quit + * + * @param prompt Prompt to be used task user a value + * @return The entered text from user + */ + private String prompt(String prompt) { + + String input = null; + Scanner scanner = new Scanner(System.in); + + while (StringUtil.isEmpty(input)) { + System.out.println(prompt + " ([Q] to quit): "); + input = scanner.nextLine(); + } + + if ("Q".equalsIgnoreCase(input)) { + System.out.println("Quit application"); + System.exit(0); + } + return input.trim(); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/verification/status/GetByIdentity.java b/sample-app/src/main/java/com/sinch/sample/verification/status/GetByIdentity.java index 38a69cc2..c67f3844 100644 --- a/sample-app/src/main/java/com/sinch/sample/verification/status/GetByIdentity.java +++ b/sample-app/src/main/java/com/sinch/sample/verification/status/GetByIdentity.java @@ -1,7 +1,6 @@ package com.sinch.sample.verification.status; import com.sinch.sample.BaseApplication; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReport; @@ -25,7 +24,7 @@ public static void main(String[] args) { public void run() { - Identity identity = NumberIdentity.builder().setEndpoint(phoneNumber).build(); + var identity = NumberIdentity.builder().setEndpoint(phoneNumber).build(); LOGGER.info("Get status by identity for : " + identity); diff --git a/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportById.java b/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportById.java index f8e13c70..12605d37 100644 --- a/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportById.java +++ b/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportById.java @@ -43,7 +43,7 @@ public void run() { } else if (method == VerificationMethodType.CALLOUT) { builder = VerificationReportCalloutRequestParameters.builder().setCode("5762"); } else { - builder = VerificationReportRequestParameters.builder(); + throw new UnsupportedOperationException("Unknown method " + method); } VerificationReport response = client.verification().verifications().report(id, builder.build()); diff --git a/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportByIdentity.java b/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportByIdentity.java index c52f4e28..865da580 100644 --- a/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportByIdentity.java +++ b/sample-app/src/main/java/com/sinch/sample/verification/verifications/ReportByIdentity.java @@ -1,7 +1,6 @@ package com.sinch.sample.verification.verifications; import com.sinch.sample.BaseApplication; -import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; import com.sinch.sdk.domains.verification.models.VerificationReport; @@ -31,7 +30,7 @@ public void run() { LOGGER.info("Get report by identity for : " + phoneNumber); - Identity identity = NumberIdentity.builder().setEndpoint(phoneNumber).build(); + var identity = NumberIdentity.builder().setEndpoint(phoneNumber).build(); VerificationMethodType method = VerificationMethodType.SMS; @@ -40,11 +39,11 @@ public void run() { if (method == VerificationMethodType.FLASH_CALL) { builder = VerificationReportFlashCallRequestParameters.builder().setCli("+12098910108"); } else if (method == VerificationMethodType.SMS) { - builder = VerificationReportSMSRequestParameters.builder().setCode("0271"); + builder = VerificationReportSMSRequestParameters.builder().setCode("8448"); } else if (method == VerificationMethodType.CALLOUT) { builder = VerificationReportCalloutRequestParameters.builder().setCode("5762"); } else { - builder = VerificationReportRequestParameters.builder(); + throw new UnsupportedOperationException("Unknown method " + method); } VerificationReport response = diff --git a/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java b/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java index 6e46e76a..b9b4c8f6 100644 --- a/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java +++ b/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java @@ -3,8 +3,11 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethodType; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationCalloutRequestParameters; import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationSMSRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationSeamlessRequestParameters; import java.io.IOException; import java.util.logging.Logger; @@ -33,15 +36,16 @@ public void run() { StartVerificationRequestParameters.Builder builder; - if (method != VerificationMethodType.CALLOUT) { - builder = StartVerificationRequestParameters.builder(method); + if (method == VerificationMethodType.CALLOUT) { + builder = StartVerificationCalloutRequestParameters.builder(); + } else if (method == VerificationMethodType.SMS) { + builder = StartVerificationSMSRequestParameters.builder(); + } else if (method == VerificationMethodType.SEAMLESS) { + builder = StartVerificationSeamlessRequestParameters.builder(); + } else if (method == VerificationMethodType.FLASH_CALL) { + builder = StartVerificationFlashCallRequestParameters.builder().setDialTimeOut(17); } else { - // Dedicated flashcall builder usage do not require setting explicit verification method - // parameter - builder = - StartVerificationFlashCallRequestParameters.builder() - .setIdentity(identity) - .setDialTimeOut(17); + throw new IllegalArgumentException("Unexpected method type '%s'".formatted(method)); } // process common properties diff --git a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationController.java b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationController.java index 71ca00ed..ffe62671 100644 --- a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationController.java +++ b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationController.java @@ -42,7 +42,7 @@ public String VerificationEvent( sinchClient .verification() .webhooks() - .validateAuthenticatedRequest( + .validateAuthenticationHeader( // The HTTP verb this controller is managing "POST", // The URI this controller is managing @@ -58,7 +58,7 @@ public String VerificationEvent( } // decode the request payload - var event = sinchClient.verification().webhooks().unserializeVerificationEvent(body); + var event = sinchClient.verification().webhooks().parseEvent(body); // let business layer process the request var response = switch (event) { @@ -70,8 +70,12 @@ public String VerificationEvent( default -> throw new IllegalStateException("Unexpected value: " + event); }; - LOGGER.finest("response: " + response); + var serializedResponse =// null != response ? + sinchClient.verification().webhooks().serializeResponse(response); + // : ""; - return response; + LOGGER.finest("JSON response: " + serializedResponse); + + return serializedResponse; } } diff --git a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java index 771cacdb..421ed1f2 100644 --- a/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java +++ b/sample-app/src/main/java/com/sinch/sample/webhooks/verification/VerificationService.java @@ -26,7 +26,7 @@ public VerificationService(SinchClient sinchClient) { this.sinchClient = sinchClient; } - public String verificationEvent(VerificationRequestEvent event) { + public VerificationResponse verificationEvent(VerificationRequestEvent event) { LOGGER.info("decoded event :" + event); @@ -48,10 +48,8 @@ public String verificationEvent(VerificationRequestEvent event) { builder.setAction(VerificationResponseActionType.ALLOW); - var response = - sinchClient.verification().webhooks().serializeVerificationResponse(builder.build()); + var response = builder.build(); LOGGER.info("Response :" + response); - return response; } diff --git a/sample-app/src/main/java/com/sinch/sample/webhooks/voice/VoiceController.java b/sample-app/src/main/java/com/sinch/sample/webhooks/voice/VoiceController.java index 590306cb..593be285 100644 --- a/sample-app/src/main/java/com/sinch/sample/webhooks/voice/VoiceController.java +++ b/sample-app/src/main/java/com/sinch/sample/webhooks/voice/VoiceController.java @@ -34,7 +34,7 @@ public VoiceController(SinchClient sinchClient, VoiceService service) { value = "/VoiceEvent", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public String VerificationEvent( + public String VoiceEvent( @RequestHeader Map headers, @RequestBody String body) { LOGGER.finest("Received body:" + body); @@ -43,7 +43,7 @@ public String VerificationEvent( // ensure valid authentication to handle request var validAuth = sinchClient - .verification() + .voice() .webhooks() .validateAuthenticatedRequest( // The HTTP verb this controller is managing