001/* 002 * Copyright (c) 2011-2018 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.ncco; 023 024import com.fasterxml.jackson.annotation.JsonInclude; 025 026/** 027 * Represents a phone endpoint used in a {@link ConnectAction} 028 */ 029@JsonInclude(value = JsonInclude.Include.NON_NULL) 030public class PhoneEndpoint implements Endpoint { 031 private static final String TYPE = "phone"; 032 033 private String number; 034 private String dtmfAnswer; 035 private OnAnswer onAnswer; 036 037 private PhoneEndpoint(Builder builder) { 038 this.number = builder.number; 039 this.dtmfAnswer = builder.dtmfAnswer; 040 this.onAnswer = (builder.onAnswerUrl != null) ? new OnAnswer(builder.onAnswerUrl, builder.onAnswerRingback) : null; 041 } 042 043 public String getType() { 044 return TYPE; 045 } 046 047 public String getNumber() { 048 return number; 049 } 050 051 public String getDtmfAnswer() { 052 return dtmfAnswer; 053 } 054 055 public OnAnswer getOnAnswer() { 056 return onAnswer; 057 } 058 059 public static Builder builder(String number) { 060 return new Builder(number); 061 } 062 063 public static class Builder { 064 private String number; 065 private String dtmfAnswer = null; 066 private String onAnswerUrl = null; 067 private String onAnswerRingback = null; 068 069 public Builder(String number) { 070 this.number = number; 071 } 072 073 public Builder number(String number) { 074 this.number = number; 075 return this; 076 } 077 078 public Builder dtmfAnswer(String dtmfAnswer) { 079 this.dtmfAnswer = dtmfAnswer; 080 return this; 081 } 082 083 public Builder onAnswer(String url) { 084 this.onAnswerUrl = url; 085 return this; 086 } 087 088 public Builder onAnswer(String url, String ringback) { 089 this.onAnswerUrl = url; 090 this.onAnswerRingback = ringback; 091 return this; 092 } 093 094 public PhoneEndpoint build() { 095 return new PhoneEndpoint(this); 096 } 097 } 098 099 @JsonInclude(value = JsonInclude.Include.NON_NULL) 100 private class OnAnswer { 101 private String url; 102 private String ringback; 103 104 private OnAnswer(String url) { 105 this.url = url; 106 } 107 108 private OnAnswer(String url, String ringback) { 109 this(url); 110 this.ringback = ringback; 111 } 112 113 public String getUrl() { 114 return this.url; 115 } 116 117 public String getRingback() { 118 return ringback; 119 } 120 } 121}