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.insight; 023 024import com.fasterxml.jackson.annotation.JsonCreator; 025import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 026import com.fasterxml.jackson.annotation.JsonProperty; 027import com.fasterxml.jackson.databind.ObjectMapper; 028import com.nexmo.client.NexmoUnexpectedException; 029 030import java.io.IOException; 031import java.util.HashMap; 032import java.util.Map; 033 034@JsonIgnoreProperties(ignoreUnknown = true) 035public class AdvancedInsightResponse extends StandardInsightResponse { 036 private Validity validNumber; 037 private Reachability reachability; 038 private PortedStatus ported; 039 private Integer lookupOutcome; 040 private String lookupOutcomeMessage; 041 private RoamingDetails roaming; 042 private String callerName; 043 private String firstName; 044 private String lastName; 045 private CallerType callerType; 046 047 048 public static AdvancedInsightResponse fromJson(String json) { 049 try { 050 ObjectMapper mapper = new ObjectMapper(); 051 return mapper.readValue(json, AdvancedInsightResponse.class); 052 } catch (IOException jpe) { 053 throw new NexmoUnexpectedException("Failed to produce AdvancedInsightResponse from json.", jpe); 054 } 055 } 056 057 @JsonProperty("valid_number") 058 public Validity getValidNumber() { 059 return validNumber; 060 } 061 062 @JsonProperty("reachable") 063 public Reachability getReachability() { 064 return reachability; 065 } 066 067 public PortedStatus getPorted() { 068 return ported; 069 } 070 071 @JsonProperty("lookup_outcome") 072 public Integer getLookupOutcome() { 073 return lookupOutcome; 074 } 075 076 @JsonProperty("lookup_outcome_message") 077 public String getLookupOutcomeMessage() { 078 return lookupOutcomeMessage; 079 } 080 081 public RoamingDetails getRoaming() { 082 return roaming; 083 } 084 085 @JsonProperty("caller_name") 086 public String getCallerName() { 087 return callerName; 088 } 089 090 @JsonProperty("first_name") 091 public String getFirstName() { 092 return firstName; 093 } 094 095 @JsonProperty("last_name") 096 public String getLastName() { 097 return lastName; 098 } 099 100 @JsonProperty("caller_type") 101 public CallerType getCallerType() { 102 return callerType; 103 } 104 105 public enum PortedStatus { 106 UNKNOWN, PORTED, NOT_PORTED, ASSUMED_NOT_PORTED, ASSUMED_PORTED; 107 108 private static final Map<String, PortedStatus> PORTED_STATUS_INDEX = new HashMap<>(); 109 110 static { 111 for (PortedStatus portedStatus : PortedStatus.values()) { 112 PORTED_STATUS_INDEX.put(portedStatus.name(), portedStatus); 113 } 114 } 115 116 @JsonCreator 117 public static PortedStatus fromString(String name) { 118 PortedStatus foundPortedStatus = PORTED_STATUS_INDEX.get(name.toUpperCase()); 119 return (foundPortedStatus != null) ? foundPortedStatus : UNKNOWN; 120 } 121 122 } 123 124 public enum Validity { 125 UNKNOWN, VALID, NOT_VALID; 126 127 private static final Map<String, Validity> VALIDITY_INDEX = new HashMap<>(); 128 129 static { 130 for (Validity validity : Validity.values()) { 131 VALIDITY_INDEX.put(validity.name(), validity); 132 } 133 } 134 135 @JsonCreator 136 public static Validity fromString(String name) { 137 Validity foundValidity = VALIDITY_INDEX.get(name.toUpperCase()); 138 return (foundValidity != null) ? foundValidity : Validity.UNKNOWN; 139 } 140 } 141 142 public enum Reachability { 143 UNKNOWN, REACHABLE, UNDELIVERABLE, ABSENT, BAD_NUMBER, BLACKLISTED; 144 145 private static final Map<String, Reachability> REACHABILITY_INDEX = new HashMap<>(); 146 147 static { 148 for (Reachability reachability : Reachability.values()) { 149 REACHABILITY_INDEX.put(reachability.name(), reachability); 150 } 151 } 152 153 @JsonCreator 154 public static Reachability fromString(String name) { 155 Reachability foundReachability = REACHABILITY_INDEX.get(name.toUpperCase()); 156 return (foundReachability != null) ? foundReachability : UNKNOWN; 157 } 158 } 159}