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.JsonProperty;
020import com.fasterxml.jackson.databind.JsonMappingException;
021import com.fasterxml.jackson.databind.ObjectMapper;
022import com.vonage.client.VonageResponseParseException;
023import com.vonage.client.VonageUnexpectedException;
024
025import java.io.IOException;
026
027public class VerifyResponse {
028    private String requestId;
029    private VerifyStatus status;
030    private String errorText;
031
032    @JsonCreator
033    public VerifyResponse(@JsonProperty(value = "status", required = true) VerifyStatus status) {
034        this.status = status;
035    }
036
037    @JsonProperty("request_id")
038    public String getRequestId() {
039        return this.requestId;
040    }
041
042    public VerifyStatus getStatus() {
043        return this.status;
044    }
045
046    @JsonProperty("error_text")
047    public String getErrorText() {
048        return this.errorText;
049    }
050
051    public static VerifyResponse fromJson(String json) {
052        try {
053            ObjectMapper mapper = new ObjectMapper();
054            return mapper.readValue(json, VerifyResponse.class);
055        } catch (JsonMappingException jme) {
056            throw new VonageResponseParseException("Failed to produce VerifyResponse from json.", jme);
057        } catch (IOException jpe) {
058            throw new VonageUnexpectedException("Failed to produce VerifyResponse from json.", jpe);
059        }
060    }
061}