001/* 002 * Copyright 2024 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.messages.viber; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.JsonableBaseObject; 020import java.net.URI; 021 022/** 023 * @since 7.2.0 024 */ 025public final class Action extends JsonableBaseObject { 026 private final URI url; 027 private final String text; 028 029 private Action(String url, String text) { 030 this.url = URI.create(url); 031 this.text = text; 032 } 033 034 static Action construct(String url, String text) { 035 boolean noUrl = url == null || url.isEmpty(), noText = text == null || text.isEmpty(); 036 if (noUrl && noText) { 037 return null; 038 } 039 else if (noUrl || noText) { 040 throw new IllegalStateException("Both URL and text are required for Action."); 041 } 042 else { 043 return new Action(url, text); 044 } 045 } 046 047 @JsonProperty("url") 048 public URI getUrl() { 049 return url; 050 } 051 052 @JsonProperty("text") 053 public String getText() { 054 return text; 055 } 056}