001/* 002 * Copyright 2020 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.verify; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 020import com.fasterxml.jackson.annotation.JsonProperty; 021import com.fasterxml.jackson.databind.JsonMappingException; 022import com.fasterxml.jackson.databind.ObjectMapper; 023import com.fasterxml.jackson.databind.module.SimpleModule; 024import com.vonage.client.VonageResponseParseException; 025import com.vonage.client.VonageUnexpectedException; 026 027import java.io.IOException; 028import java.text.SimpleDateFormat; 029import java.util.ArrayList; 030import java.util.List; 031 032@JsonIgnoreProperties(ignoreUnknown = true) 033public class SearchVerifyResponse { 034 private VerifyStatus status; 035 private List<VerifyDetails> verificationRequests = new ArrayList<>(); 036 private String errorText; 037 038 @JsonCreator 039 SearchVerifyResponse() { 040 this.status = VerifyStatus.OK; 041 } 042 043 SearchVerifyResponse(List<VerifyDetails> verificationRequests) { 044 this.status = VerifyStatus.OK; 045 this.verificationRequests = verificationRequests; 046 } 047 048 SearchVerifyResponse(VerifyStatus status, String errorText) { 049 this.status = status; 050 this.errorText = errorText; 051 } 052 053 public VerifyStatus getStatus() { 054 return this.status; 055 } 056 057 @JsonProperty("verification_requests") 058 public List<VerifyDetails> getVerificationRequests() { 059 return this.verificationRequests; 060 } 061 062 @JsonProperty("error_text") 063 public String getErrorText() { 064 return this.errorText; 065 } 066 067 public static SearchVerifyResponse fromJson(String json) { 068 try { 069 ObjectMapper mapper = new ObjectMapper(); 070 mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 071 SimpleModule module = new SimpleModule(); 072 module.addDeserializer(SearchVerifyResponse.class, new SearchVerifyResponseDeserializer()); 073 mapper.registerModule(module); 074 075 return mapper.readValue(json, SearchVerifyResponse.class); 076 } catch (JsonMappingException jme) { 077 throw new VonageResponseParseException("Failed to produce SearchVerifyResponse from json.", jme); 078 } catch (IOException jpe) { 079 throw new VonageUnexpectedException("Failed to produce SearchVerifyResponse from json.", jpe); 080 } 081 } 082}