Skip to content

Commit

Permalink
Verification 2.0.1 planned for next 1.1 release (#95)
Browse files Browse the repository at this point in the history
feature: Sync with `Verification 2.0.1` API and use versioned service implementation
  • Loading branch information
JPPortier authored Jun 28, 2024
1 parent b21702b commit 6853d8d
Show file tree
Hide file tree
Showing 326 changed files with 22,120 additions and 17,902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@
public interface VerificationService {

/**
* Verifications Service instance
* Verifications Service V1
*
* @return V1 service instance for project
* @see <a
* href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications/">Documentation</a>
* @since 1.1
*/
com.sinch.sdk.domains.verification.api.v1.VerificationService v1();

/**
* Non versioned Verifications Service instance
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationService#verificationStart()} or
* {@link com.sinch.sdk.domains.verification.api.v1.VerificationService#verificationReport()}
* @return service instance for project
* @see <a
* href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verifications/">Documentation</a>
Expand All @@ -20,8 +33,10 @@ public interface VerificationService {
VerificationsService verifications();

/**
* Status Service instance
* Non versioned Status Service instance
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationService#verificationStatus()}
* @return service instance for project
* @see <a
* href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-status/">Documentation</a>
Expand All @@ -30,8 +45,10 @@ public interface VerificationService {
VerificationStatusService verificationStatus();

/**
* Webhooks helpers instance
* Non versioned Webhooks helpers instance
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationService#webhooks()}
* @return instance service related to webhooks helpers
* @see <a
* href="https://developers.sinch.com/docs/verification/api-reference/verification/tag/Verification-callbacks/">Documentation</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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.VerificationReport;
import com.sinch.sdk.domains.verification.models.VerificationStatus;
import com.sinch.sdk.domains.verification.models.v1.VerificationMethod;

/**
* Get the status of specific verification requests in the verification process. Returns the status
Expand All @@ -22,31 +23,38 @@ public interface VerificationStatusService {
* Queries the verification result by sending the verification Identity (usually a phone number)
* and its method. With this query you can get the result of a verification.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStatusService#getByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,
* VerificationMethod)}
* @param identity Currently <b>Only</b> {@link
* com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported
* @param method Method used for verification
* @return Verification report response
* @return Verification status response
* @since 1.0
*/
VerificationReport getByIdentity(NumberIdentity identity, VerificationMethodType method);
VerificationStatus getByIdentity(NumberIdentity identity, VerificationMethodType method);

/**
* Queries the verification result by sending the verification ID. With this query you can get the
* result of a verification.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStatusService#getById(String)}
* @param id The ID of the verification
* @return Verification report response
* @return Verification status response
* @since 1.0
*/
VerificationReport getById(VerificationId id);
VerificationStatus getById(VerificationId id);

/**
* Queries the verification result by sending the verification Reference. With this query you can
* get the result of a verification
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStatusService#getByReference(String)}
* @param reference The custom reference of the verification
* @return Verification report response
* @return Verification status response
* @since 1.0
*/
VerificationReport getByReference(VerificationReference reference);
VerificationStatus getByReference(VerificationReference reference);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseFlashCall;
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSMS;
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSeamless;
import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall;
import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall;
import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms;
import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData;
import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall;
import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall;
import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms;

/**
* Verifications Service
Expand All @@ -35,6 +42,8 @@ public interface VerificationsService {
* <p>This method is used by the mobile and web Verification SDKs to start a verification. It can
* also be used to request a verification from your backend, by making a request.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStartService#startSms(VerificationStartRequestSms)}
* @param parameters Parameters to be used to start verification
* @return Verification response
* @since 1.0
Expand All @@ -48,6 +57,8 @@ public interface VerificationsService {
* <p>This method is used by the mobile and web Verification SDKs to start a verification. It can
* also be used to request a verification from your backend, by making a request.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStartService#startFlashCall(VerificationStartRequestFlashCall)}
* @param parameters Parameters to be used to start verification
* @return Verification response
* @since 1.0
Expand All @@ -62,6 +73,8 @@ StartVerificationResponseFlashCall startFlashCall(
* <p>This method is used by the mobile and web Verification SDKs to start a verification. It can
* also be used to request a verification from your backend, by making a request.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStartService#startPhoneCall(VerificationStartRequestPhoneCall)}
* @param parameters Parameters to be used to start verification
* @return Verification response
* @since 1.0
Expand All @@ -76,6 +89,8 @@ StartVerificationResponseCallout startCallout(
* <p>This method is used by the mobile and web Verification SDKs to start a verification. It can
* also be used to request a verification from your backend, by making a request.
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationStartService#startData(VerificationStartRequestData)}
* @param parameters Parameters to be used to start verification
* @return Verification response
* @since 1.0
Expand All @@ -89,6 +104,9 @@ StartVerificationResponseSeamless startSeamless(
*
* <p>Report the received verification code to verify it, using the identity of the user
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportSmsByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,
* VerificationReportRequestSms)}
* @param identity Currently <b>Only</b> {@link
* com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported
* @param parameters Parameters to be used to get report
Expand All @@ -105,6 +123,9 @@ VerificationReportSMS reportSmsByIdentity(
*
* <p>Report the received verification code to verify it, using the identity of the user
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportFlashCallByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,
* VerificationReportRequestFlashCall)}
* @param identity Currently <b>Only</b> {@link
* com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported
* @param parameters Parameters to be used to get report
Expand All @@ -121,6 +142,9 @@ VerificationReportFlashCall reportFlashCallByIdentity(
*
* <p>Report the received verification code to verify it, using the identity of the user
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportPhoneCallByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,
* VerificationReportRequestPhoneCall)}
* @param identity Currently <b>Only</b> {@link
* com.sinch.sdk.domains.verification.models.NumberIdentity NumberIdentity} is supported
* @param parameters Parameters to be used to get report
Expand All @@ -134,6 +158,9 @@ VerificationReportCallout reportCalloutByIdentity(
* Report the received verification code to verify it, using the Verification ID of the {@link
* com.sinch.sdk.domains.verification.models.VerificationMethodType#SMS SMS} Verification request
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportSmsById(String,
* VerificationReportRequestSms)}
* @param id ID returned from start verification
* @param parameters Parameters to be used to get report
* @return Verification report response
Expand All @@ -147,6 +174,9 @@ VerificationReportSMS reportSmsById(
* com.sinch.sdk.domains.verification.models.VerificationMethodType#FLASH_CALL FLASH_CALL}
* Verification request
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportFlashCallById(String,
* VerificationReportRequestFlashCall)}
* @param id ID returned from start verification
* @param parameters Parameters to be used to get report
* @return Verification report response
Expand All @@ -160,6 +190,9 @@ VerificationReportFlashCall reportFlashCallById(
* com.sinch.sdk.domains.verification.models.VerificationMethodType#CALLOUT CALLOUT} Verification
* request
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.VerificationReportService#reportPhoneCallById(String,
* VerificationReportRequestPhoneCall)}
* @param id ID returned from start verification
* @param parameters Parameters to be used to get report
* @return Verification report response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sinch.sdk.domains.verification;

import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.domains.verification.models.v1.webhooks.VerificationRequestEventResponse;
import com.sinch.sdk.domains.verification.models.webhooks.VerificationEvent;
import com.sinch.sdk.domains.verification.models.webhooks.VerificationResponse;
import java.util.Map;
Expand All @@ -26,6 +27,9 @@ public interface WebHooksService {
* <p>By using following function, you can ensure authentication according to received payload
* from your backend
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.WebHooksService#validateAuthenticationHeader(String,
* String, Map, String)}
* @param method The HTTP method used ot handle the callback
* @param path The path to you backend endpoint used for callback
* @param headers Received headers
Expand All @@ -42,6 +46,8 @@ boolean validateAuthenticationHeader(
* This function can be called to deserialize received payload onto callback onto proper java
* verification event class
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.WebHooksService#parseEvent(String)}
* @param jsonPayload Received payload to be deserialized
* @return The verification event instance class
* <p>see <a
Expand All @@ -53,6 +59,8 @@ boolean validateAuthenticationHeader(
/**
* This function can be called to serialize a verification response to be sent as JSON
*
* @apiNote This version is no longer updated, to get updates use V1 version: {@link
* com.sinch.sdk.domains.verification.api.v1.WebHooksService#serializeResponse(VerificationRequestEventResponse)}
* @param response The response to be serialized
* @return The JSON string to be sent
* <p>see <a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.sinch.sdk.domains.verification.adapters;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.verification.models.v1.Identity;
import com.sinch.sdk.domains.verification.models.v1.NumberIdentity;
import com.sinch.sdk.domains.verification.models.v1.internal.IdentityInternal;
import com.sinch.sdk.domains.verification.models.v1.internal.IdentityInternal.TypeEnum;
import java.io.IOException;
import java.util.logging.Logger;

public class IdentityMapper {
private static final Logger LOGGER = Logger.getLogger(IdentityMapper.class.getName());

public static void initMapper() {
SimpleModule module =
new SimpleModule()
.addSerializer(Identity.class, new Serializer())
.addDeserializer(Identity.class, new IdentityDeserializer());
Mapper.getInstance().registerModule(module);
}

static class Serializer extends StdSerializer<Identity> {

public Serializer() {
this(null);
}

public Serializer(Class<Identity> t) {
super(t);
}

@Override
public void serialize(Identity raw, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
if (!(raw instanceof NumberIdentity)) {
// avoid exception
LOGGER.severe("Unexpected type'" + raw + "'");
return;
}
NumberIdentity identity = (NumberIdentity) raw;
IdentityInternal.Builder internal =
IdentityInternal.builder().setType(TypeEnum.NUMBER).setEndpoint(identity.getEndpoint());

jgen.writeObject(internal.build());
}
}

static final class IdentityDeserializer extends StdDeserializer<Identity> {

private static final long serialVersionUID = 1L;

public IdentityDeserializer() {
this(Identity.class);
}

public IdentityDeserializer(Class<?> vc) {
super(vc);
}

@Override
public Identity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

IdentityInternal internal = Mapper.getInstance().readValue(jp, IdentityInternal.class);
if (!internal.getType().equals(TypeEnum.NUMBER)) {
// avoid exception
LOGGER.severe("Unexpected type'" + internal + "'");
return NumberIdentity.valueOf("");
}
return NumberIdentity.valueOf(internal.getEndpoint());
}
}
}
Loading

0 comments on commit 6853d8d

Please sign in to comment.