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.voice;
023
024
025import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
026import com.fasterxml.jackson.annotation.JsonInclude;
027import com.fasterxml.jackson.annotation.JsonProperty;
028import com.fasterxml.jackson.databind.ObjectMapper;
029import com.fasterxml.jackson.databind.SerializationFeature;
030import com.nexmo.client.NexmoUnexpectedException;
031
032import java.io.IOException;
033import java.util.Date;
034
035/**
036 * CallInfo holds the information related to a call. It is obtained using {@link VoiceClient#listCalls}
037 */
038@JsonInclude(value = JsonInclude.Include.NON_NULL)
039@JsonIgnoreProperties(value = { "_links" }, ignoreUnknown = true)
040public class CallInfo {
041    private Endpoint to;
042    private Endpoint from;
043
044    private String conversationUuid = null;
045    private CallDirection direction = null;
046    private Integer duration = null;
047    private Date endTime = null;
048    private String network = null;
049    private String price = null;
050    private String rate = null;
051    private Date startTime = null;
052    private CallStatus status = null;
053    private String uuid = null;
054
055    public CallInfo() {}
056
057    public CallInfo(String to, String from) {
058        this(new PhoneEndpoint(to), new PhoneEndpoint(from));
059    }
060
061    public CallInfo(Endpoint to, Endpoint from) {
062        this.to = to;
063        this.from = from;
064    }
065
066    public Endpoint getTo() {
067        return to;
068    }
069
070    public void setTo(Endpoint to) {
071        this.to = to;
072    }
073
074    public Endpoint getFrom() {
075        return from;
076    }
077
078    public void setFrom(Endpoint from) {
079        this.from = from;
080    }
081
082    public String getUuid() {
083        return uuid;
084    }
085
086    public void setUuid(String uuid) {
087        this.uuid = uuid;
088    }
089
090    @JsonProperty("conversation_uuid")
091    public String getConversationUuid() {
092        return conversationUuid;
093    }
094
095    public void setConversationUuid(String conversationUuid) {
096        this.conversationUuid = conversationUuid;
097    }
098
099    public Integer getDuration() {
100        return duration;
101    }
102
103    public void setDuration(Integer duration) {
104        this.duration = duration;
105    }
106
107    @JsonProperty("end_time")
108    public Date getEndTime() {
109        return endTime;
110    }
111
112    public void setEndTime(Date endTime) {
113        this.endTime = endTime;
114    }
115
116    public String getPrice() {
117        return price;
118    }
119
120    public void setPrice(String price) {
121        this.price = price;
122    }
123
124    public String getRate() {
125        return rate;
126    }
127
128    public void setRate(String rate) {
129        this.rate = rate;
130    }
131
132    @JsonProperty("start_time")
133    public Date getStartTime() {
134        return this.startTime;
135    }
136
137    public void setStartTime(Date startTime) {
138        this.startTime = startTime;
139    }
140
141    public CallStatus getStatus() {
142        return status;
143    }
144
145    public void setStatus(CallStatus status) {
146        this.status = status;
147    }
148
149    public CallDirection getDirection() {
150        return direction;
151    }
152
153    public void setDirection(CallDirection direction) {
154        this.direction = direction;
155    }
156
157    public String getNetwork() {
158        return network;
159    }
160
161    public void setNetwork(String network) {
162        this.network = network;
163    }
164
165    public String toString() {
166        return new StringBuilder()
167                .append("<CallInfo ")
168                .append("ID: ").append(this.getUuid()).append(", ")
169                .append("From: ").append(this.getFrom().toLog()).append(", ")
170                .append("To: ").append(this.getTo().toLog()).append(", ")
171                .append("Status: ").append(this.getStatus())
172                .append(">")
173                .toString();
174    }
175
176    public static CallInfo fromJson(String json) {
177        try {
178            ObjectMapper mapper = new ObjectMapper();
179            mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
180            return mapper.readValue(json, CallInfo.class);
181        } catch (IOException jpe) {
182            throw new NexmoUnexpectedException("Failed to produce json from CallInfo object.", jpe);
183        }
184    }
185}