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.voice; 017 018import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 019import com.fasterxml.jackson.annotation.JsonProperty; 020import com.fasterxml.jackson.databind.ObjectMapper; 021import com.fasterxml.jackson.databind.SerializationFeature; 022import com.fasterxml.jackson.databind.util.ArrayIterator; 023import com.vonage.client.VonageUnexpectedException; 024 025import java.io.IOException; 026import java.util.Iterator; 027 028@JsonIgnoreProperties(ignoreUnknown = true) 029public class CallInfoPage implements Iterable<CallInfo> { 030 private int count; 031 private int pageSize; 032 private int recordIndex; 033 034 private PageLinks links; 035 private EmbeddedCalls embedded; 036 037 public int getCount() { 038 return count; 039 } 040 041 @JsonProperty("page_size") 042 public int getPageSize() { 043 return pageSize; 044 } 045 046 @JsonProperty("record_index") 047 public int getRecordIndex() { 048 return recordIndex; 049 } 050 051 @JsonProperty("_links") 052 public PageLinks getLinks() { 053 return links; 054 } 055 056 @JsonProperty("_embedded") 057 public EmbeddedCalls getEmbedded() { 058 return embedded; 059 } 060 061 @Override 062 public Iterator<CallInfo> iterator() { 063 return new ArrayIterator<>(embedded.getCallInfos()); 064 } 065 066 public static CallInfoPage fromJson(String json) { 067 try { 068 ObjectMapper mapper = new ObjectMapper(); 069 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 070 return mapper.readValue(json, CallInfoPage.class); 071 } catch (IOException jpe) { 072 throw new VonageUnexpectedException("Failed to produce json from Call object.", jpe); 073 } 074 } 075}