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.core.JsonProcessingException; 019import com.fasterxml.jackson.databind.ObjectMapper; 020import com.vonage.client.VonageUnexpectedException; 021 022/** 023 * The request object to send DTMF tones. 024 * <p> 025 * Contains the {@code uuid} of the {@link Call} and the {@link DtmfPayload} to be sent in the request. 026 */ 027 028public class DtmfRequest { 029 private String uuid; 030 private DtmfPayload payload; 031 032 public DtmfRequest(String uuid, String digits) { 033 this.uuid = uuid; 034 this.payload = new DtmfPayload(digits); 035 } 036 037 public String getUuid() { 038 return uuid; 039 } 040 041 public String getDigits() { 042 return payload.getDigits(); 043 } 044 045 public void setUuid(String uuid) { 046 this.uuid = uuid; 047 } 048 049 public void setDigits(String digits) { 050 this.payload.setDigits(digits); 051 } 052 053 public String toJson() { 054 try { 055 ObjectMapper mapper = new ObjectMapper(); 056 return mapper.writeValueAsString(this.payload); 057 } catch (JsonProcessingException jpe) { 058 throw new VonageUnexpectedException("Failed to produce json from DtmfRequest object.", jpe); 059 } 060 } 061}