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