Skip to content

Commit

Permalink
feat: Start verification
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Nov 23, 2023
1 parent 08cae0d commit 7c3ae1c
Show file tree
Hide file tree
Showing 38 changed files with 1,333 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public static class Builder extends BaseBatch.Builder<String, Builder> {
private Integer fromNpi;
private String udh;

private Builder() {}
private Builder() {
super();
}

public Builder setFlashMessage(boolean flashMessage) {
this.flashMessage = flashMessage;
Expand Down Expand Up @@ -158,6 +160,7 @@ public Builder setUdh(String udh) {
return this;
}

@Override
public SendSmsBatchBinaryRequest build() {
return new SendSmsBatchBinaryRequest(
to,
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.domains.verification.models.requests.StartVerificationRequestParameters;
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse;

/**
* Verifications Service
Expand All @@ -17,11 +18,11 @@ public interface VerificationsService {
* Start verification
*
* <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 an request.
* also be used to request a verification from your backend, by making a request.
*
* @param parameters Parameters to be used to start verification return service instance for
* project
* @param parameters Parameters to be used to start verification
* @return Verification response
* @since 1.0
*/
void start(StartVerificationRequestParameters parameters);
StartVerificationResponse start(StartVerificationRequestParameters parameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.requests.StartVerificationRequestParameters;
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Map;

Expand All @@ -27,7 +28,8 @@ private SendingAndReportingVerificationsApi getApi() {
return this.api;
}

public void start(StartVerificationRequestParameters parameters) {
getApi().startVerification(VerificationsDtoConverter.convert(parameters));
public StartVerificationResponse start(StartVerificationRequestParameters parameters) {
return VerificationsDtoConverter.convert(
getApi().startVerification(VerificationsDtoConverter.convert(parameters)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sinch.sdk.domains.verification.adapters.converters;

import com.sinch.sdk.core.http.HttpMethod;
import com.sinch.sdk.domains.verification.models.Link;
import com.sinch.sdk.domains.verification.models.LinkRelType;
import com.sinch.sdk.domains.verification.models.dto.v1.VerificationResourceLinkDto;
import java.util.Collection;
import java.util.stream.Collectors;

public class LinkDtoConverter {

public static Collection<Link> convert(Collection<VerificationResourceLinkDto> dto) {
return dto.stream().map(LinkDtoConverter::convert).collect(Collectors.toList());
}

public static Link convert(VerificationResourceLinkDto dto) {
return Link.builder()
.setRel(LinkRelType.from(dto.getRel()))
.setHref(dto.getHref())
.setMethod(HttpMethod.valueOf(dto.getMethod()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
import com.sinch.sdk.domains.verification.models.Identity;
import com.sinch.sdk.domains.verification.models.NumberIdentity;
import com.sinch.sdk.domains.verification.models.VerificationMethod;
import com.sinch.sdk.domains.verification.models.dto.v1.FlashCallInitiateVerificationResponseDto;
import com.sinch.sdk.domains.verification.models.dto.v1.FlashcallOptionsDto;
import com.sinch.sdk.domains.verification.models.dto.v1.IdentityDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceFlashCallOptionsDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceIdentityDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceMethodDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseFlashCallDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseSeamlessDto;
import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseSmsDto;
import com.sinch.sdk.domains.verification.models.dto.v1.SeamlessInitiateVerificationResponseDto;
import com.sinch.sdk.domains.verification.models.dto.v1.SmsInitiateVerificationResponseDto;
import com.sinch.sdk.domains.verification.models.dto.v1.VerificationMethodDto;
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.response.StartVerificationResponse;
import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseCallout;
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;

public class VerificationsDtoConverter {

Expand Down Expand Up @@ -52,4 +64,64 @@ public static InitiateVerificationResourceMethodDto convert(VerificationMethod c
VerificationMethodDto dto = VerificationMethodDto.fromValue(client.value());
return new InitiateVerificationResourceMethodDto(dto);
}

public static StartVerificationResponse convert(InitiateVerificationResponseDto dto) {
StartVerificationResponse.Builder<?> builder;
switch (dto.getMethod()) {
case SMS:
{
StartVerificationResponseSMS.Builder aBuilder = StartVerificationResponseSMS.builder();
InitiateVerificationResponseSmsDto aresponse = dto.getSms();
if (null != aresponse) {
SmsInitiateVerificationResponseDto response =
aresponse.getSmsInitiateVerificationResponseDto();
aBuilder
.setTemplate(response.getTemplate())
.setInterceptionTimeOut(response.getInterceptionTimeout());
}
builder = aBuilder;
break;
}
case FLASHCALL:
{
StartVerificationResponseFlashCall.Builder aBuilder =
StartVerificationResponseFlashCall.builder();
InitiateVerificationResponseFlashCallDto aresponse = dto.getFlashCall();
if (null != aresponse) {
FlashCallInitiateVerificationResponseDto response =
aresponse.getFlashCallInitiateVerificationResponseDto();
aBuilder
.setCliFilter(response.getCliFilter())
.setInterceptionTimeOut(response.getInterceptionTimeout())
.setReportTimeout(response.getReportTimeout())
.setDenyCallAfter(response.getDenyCallAfter());
}
builder = aBuilder;
break;
}
case CALLOUT:
{
// noop: no specific parameters for callout but we create a specific builder for trace
// purpose
builder = StartVerificationResponseCallout.builder();
break;
}
case SEAMLESS:
{
StartVerificationResponseSeamless.Builder aBuilder =
StartVerificationResponseSeamless.builder();
InitiateVerificationResponseSeamlessDto aresponse = dto.getSeamless();
if (null != aresponse) {
SeamlessInitiateVerificationResponseDto response =
aresponse.getSeamlessInitiateVerificationResponseDto();
aBuilder.setTargetUri(response.getTargetUri());
}
builder = aBuilder;
break;
}
default:
builder = StartVerificationResponse.builder();
}
return builder.setId(dto.getId()).setLinks(LinkDtoConverter.convert(dto.getLinks())).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package com.sinch.sdk.domains.verification.models;

public abstract class Identity {}
/** Base class for Identity based objects */
public abstract class Identity {

@Override
public String toString() {
return "Identity{}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.sinch.sdk.domains.verification.models;

import com.sinch.sdk.core.http.HttpMethod;

/** Available methods and actions which can be done after a successful Verification */
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) {
this.rel = rel;
this.href = href;
this.method = method;
}

public LinkRelType getRel() {
return rel;
}

public String getHref() {
return href;
}

public HttpMethod getMethod() {
return method;
}

@Override
public String toString() {
return "Link{" + "rel='" + rel + '\'' + ", href='" + href + '\'' + ", method=" + method + '}';
}

public static Builder builder() {
return new Builder();
}

public static class Builder {

LinkRelType rel;
String href;
HttpMethod method;

private Builder() {}

public Builder setRel(LinkRelType rel) {
this.rel = rel;
return this;
}

public Builder setHref(String href) {
this.href = href;
return this;
}

public Builder setMethod(HttpMethod method) {
this.method = method;
return this;
}

public Link build() {
return new Link(rel, href, method);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sinch.sdk.domains.verification.models;

import com.sinch.sdk.core.utils.EnumDynamic;
import com.sinch.sdk.core.utils.EnumSupportDynamic;
import java.util.Arrays;
import java.util.stream.Stream;

/**
* Link rel authorized values
*
* @since 1.0
*/
public class LinkRelType extends EnumDynamic<String, LinkRelType> {

/** Get the status of a Verification. */
public static final LinkRelType STATUS = new LinkRelType("status");
/** Report a verification */
public static final LinkRelType REPORT = new LinkRelType("report");

private static final EnumSupportDynamic<String, LinkRelType> ENUM_SUPPORT =
new EnumSupportDynamic<>(LinkRelType.class, LinkRelType::new, Arrays.asList(STATUS, REPORT));

private LinkRelType(String value) {
super(value);
}

public static Stream<LinkRelType> values() {
return ENUM_SUPPORT.values();
}

public static LinkRelType from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(LinkRelType e) {
return ENUM_SUPPORT.valueOf(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.sinch.sdk.domains.verification.models;

import com.sinch.sdk.domains.sms.models.Group.Builder;

/** Identity based onto a number */
public class NumberIdentity extends Identity {
private final String endpoint;

public String getEndpoint() {
return endpoint;
}

/** @param endpoint An E.164-compatible phone number. */
public NumberIdentity(String endpoint) {
this.endpoint = endpoint;
}
Expand All @@ -27,7 +27,6 @@ public static class Builder {
String endpoint;

private Builder() {}
;

public Builder setEndpoint(String endpoint) {
this.endpoint = endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class VerificationMethod extends EnumDynamic<String, VerificationMethod>
* Verification by placing a flashcall (missed call) and detecting the incoming calling number
* (CLI).
*/
public static final VerificationMethod FLASH_CALL = new VerificationMethod("flashCall");
public static final VerificationMethod FLASH_CALL = new VerificationMethod("flashcall");
/**
* Verification by placing a PSTN call to the user's phone and playing an announcement, asking the
* user to press a particular digit to verify the phone number.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.sinch.sdk.domains.verification.models.requests;

import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest.Builder;
import com.sinch.sdk.domains.verification.models.Identity;
import com.sinch.sdk.domains.verification.models.VerificationMethod;
import java.util.Optional;

/** Dedicated request parameters to be use for a flash call verification */
public class StartVerificationFlashCallRequestParameters
extends StartVerificationRequestParameters {

private final Integer dialTimeOut;

/**
* @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 Used to pass your own reference in the request for tracking purposes.
* @param custom Can be used to pass custom data in the request.
* @param dialTimeOut The dial timeout in seconds.
*/
public StartVerificationFlashCallRequestParameters(
Identity identity,
VerificationMethod method,
String reference,
String custom,
Integer dialTimeOut) {
super(identity, method, reference, custom);
Identity identity, String reference, String custom, Integer dialTimeOut) {
super(identity, VerificationMethod.FLASH_CALL, reference, custom);
this.dialTimeOut = dialTimeOut;
}

Expand All @@ -36,18 +41,28 @@ public static Builder builder() {
return new Builder();
}

public static class Builder extends StartVerificationRequestParameters.Builder {
public static class Builder extends StartVerificationRequestParameters.Builder<Builder> {

Integer dialTimeOut;

public Builder() {
super(VerificationMethod.FLASH_CALL);
}

public Builder setDialTimeOut(Integer dialTimeOut) {
this.dialTimeOut = dialTimeOut;
return this;
}

@Override
public StartVerificationFlashCallRequestParameters build() {
return new StartVerificationFlashCallRequestParameters(
identity, method, reference, custom, dialTimeOut);
identity, reference, custom, dialTimeOut);
}

@Override
protected Builder self() {
return this;
}
}
}
Loading

0 comments on commit 7c3ae1c

Please sign in to comment.