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.ObjectMapper; 022import com.vonage.client.VonageUnexpectedException; 023 024import java.io.IOException; 025 026@JsonIgnoreProperties(ignoreUnknown = true) 027public class ControlResponse { 028 private final String status; 029 private final VerifyControlCommand command; 030 private String errorText; 031 032 @JsonCreator 033 public ControlResponse( 034 @JsonProperty("status") String status, 035 @JsonProperty("command") VerifyControlCommand command) { 036 this.status = status; 037 this.command = command; 038 this.errorText = null; 039 } 040 041 @JsonProperty 042 public String getStatus() { 043 return status; 044 } 045 046 @JsonProperty 047 public VerifyControlCommand getCommand() { 048 return command; 049 } 050 051 @JsonProperty("error_text") 052 public String getErrorText() { 053 return this.errorText; 054 } 055 056 public static ControlResponse fromJson(String json) { 057 try { 058 ObjectMapper mapper = new ObjectMapper(); 059 return mapper.readValue(json, ControlResponse.class); 060 } catch (IOException jpe) { 061 throw new VonageUnexpectedException("Failed to produce ControlResponse from json.", jpe); 062 } 063 } 064}