001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.verify; 023 024 025import java.util.Date; 026import java.util.List; 027 028/** 029 * Verification search result. 030 * 031 * @author Daniele Ricci 032 */ 033public class SearchResult extends BaseResult { 034 private final String requestId; 035 private final String accountId; 036 private final VerificationStatus verificationStatus; 037 private final String number; 038 private final float price; 039 private final String currency; 040 private final String senderId; 041 private final Date dateSubmitted; 042 private final Date dateFinalized; 043 private final Date firstEventDate; 044 private final Date lastEventDate; 045 private final List<VerifyCheck> checks; 046 047 /** Used to define a verify check attempt. */ 048 public static class VerifyCheck implements java.io.Serializable { 049 050 private static final long serialVersionUID = -5933303841261513099L; 051 052 public enum Status { 053 VALID, 054 INVALID, 055 } 056 057 private final Date date; 058 private final String code; 059 private final Status status; 060 private final String ipAddress; 061 062 public VerifyCheck(Date date, 063 String code, 064 Status status, 065 String ipAddress) { 066 this.date = date; 067 this.code = code; 068 this.status = status; 069 this.ipAddress = ipAddress; 070 } 071 072 public Date getDate() { 073 return this.date; 074 } 075 076 public String getCode() { 077 return this.code; 078 } 079 080 public Status getStatus() { 081 return this.status; 082 } 083 084 public String getIpAddress() { 085 return this.ipAddress; 086 } 087 088 @Override 089 public String toString() { 090 return "VerifyCheck [status=" + this.status + ", code=" + this.code + ", date=" + this.date + "]"; 091 } 092 093 } 094 095 public enum VerificationStatus { 096 097 IN_PROGRESS("IN PROGRESS"), 098 SUCCESS, 099 FAILED, 100 EXPIRED; 101 102 private final String name; 103 104 VerificationStatus() { 105 this(null); 106 } 107 108 VerificationStatus(String name) { 109 this.name = name; 110 } 111 112 public String getName() { 113 return this.name != null ? this.name : name(); 114 } 115 116 @Override 117 public String toString() { 118 return getName(); 119 } 120 121 } 122 123 public SearchResult(final int status, 124 final String requestId, 125 final String accountId, 126 final VerificationStatus verificationStatus, 127 final String number, 128 final float price, 129 final String currency, 130 final String senderId, 131 final Date dateSubmitted, 132 final Date dateFinalized, 133 final Date firstEventDate, 134 final Date lastEventDate, 135 final List<VerifyCheck> checks, 136 final String errorText, 137 final boolean temporaryError) { 138 super(status, errorText, temporaryError); 139 this.requestId = requestId; 140 this.accountId = accountId; 141 this.verificationStatus = verificationStatus; 142 this.number = number; 143 this.price = price; 144 this.currency = currency; 145 this.senderId = senderId; 146 this.dateSubmitted = dateSubmitted; 147 this.dateFinalized = dateFinalized; 148 this.firstEventDate = firstEventDate; 149 this.lastEventDate = lastEventDate; 150 this.checks = checks; 151 } 152 153 public String getRequestId() { 154 return this.requestId; 155 } 156 157 public String getAccountId() { 158 return this.accountId; 159 } 160 161 public VerificationStatus getVerificationStatus() { 162 return this.verificationStatus; 163 } 164 165 public String getNumber() { 166 return this.number; 167 } 168 169 public float getPrice() { 170 return this.price; 171 } 172 173 public String getCurrency() { 174 return this.currency; 175 } 176 177 public String getSenderId() { 178 return this.senderId; 179 } 180 181 public Date getDateSubmitted() { 182 return this.dateSubmitted; 183 } 184 185 public Date getDateFinalized() { 186 return this.dateFinalized; 187 } 188 189 public Date getFirstEventDate() { 190 return this.firstEventDate; 191 } 192 193 public Date getLastEventDate() { 194 return this.lastEventDate; 195 } 196 197 public List<VerifyCheck> getChecks() { 198 return this.checks; 199 } 200 201 @Override 202 public String toString() { 203 return "SearchResult [status=" + getStatus() + ", requestId=" + this.requestId + ", verificationStatus=" + this.verificationStatus + "]"; 204 } 205 206}