001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.numberinsight2; 017 018import com.vonage.client.DynamicEndpoint; 019import com.vonage.client.HttpWrapper; 020import com.vonage.client.RestEndpoint; 021import com.vonage.client.VonageClient; 022import com.vonage.client.auth.ApiKeyHeaderAuthMethod; 023import com.vonage.client.common.HttpMethod; 024 025/** 026 * A client for talking to the Vonage NumberInsight2Client API. The standard way to obtain an instance of this class is to use 027 * {@link VonageClient#getNumberInsight2Client()}. 028 */ 029public class NumberInsight2Client { 030 final RestEndpoint<FraudCheckRequest, FraudCheckResponse> fraudCheck; 031 032 /** 033 * Constructor. 034 * 035 * @param wrapper (REQUIRED) shared HTTP wrapper object used for making REST calls. 036 */ 037 public NumberInsight2Client(HttpWrapper wrapper) { 038 @SuppressWarnings("unchecked") 039 final class Endpoint<T, R> extends DynamicEndpoint<T, R> { 040 Endpoint(R... type) { 041 super(DynamicEndpoint.<T, R> builder(type) 042 .authMethod(ApiKeyHeaderAuthMethod.class) 043 .responseExceptionType(NumberInsight2ResponseException.class) 044 .requestMethod(HttpMethod.POST).wrapper(wrapper).pathGetter((de, req) -> 045 de.getHttpWrapper().getHttpConfig().getApiBaseUri() + "/v2/ni" 046 ) 047 ); 048 } 049 } 050 051 fraudCheck = new Endpoint<>(); 052 } 053 054 /** 055 * Make fraud check requests with a phone number by looking up fraud score and/or by checking SIM swap status. 056 * 057 * @param phoneNumber The phone number to run the check on, in E.164 format. 058 * @param insight The insight service type to request. 059 * @param additional Optional additional insight(s) to send in the request. 060 * 061 * @return Results of the fraud check. 062 */ 063 public FraudCheckResponse fraudCheck(String phoneNumber, Insight insight, Insight... additional) { 064 return fraudCheck.execute(new FraudCheckRequest(phoneNumber, insight, additional)); 065 } 066}