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.messages.CaptionMediaMessageRequest; 020import com.vonage.client.messages.MessageType; 021import java.util.Objects; 022 023/** 024 * @since 7.2.0 025 */ 026public final class ViberVideoRequest extends ViberRequest implements CaptionMediaMessageRequest { 027 final Video video; 028 029 ViberVideoRequest(Builder builder) { 030 super(builder, MessageType.VIDEO); 031 Objects.requireNonNull(builder.duration, "Duration is required."); 032 Objects.requireNonNull(builder.fileSize, "File size is required."); 033 video = new Video(media.getUrl().toString(), builder.thumbUrl, media.getCaption()); 034 } 035 036 @JsonProperty("video") 037 public Video getVideo() { 038 return video; 039 } 040 041 public static Builder builder() { 042 return new Builder(); 043 } 044 045 public static final class Builder extends ViberRequest.Builder<ViberVideoRequest, Builder> implements CaptionMediaMessageRequest.Builder<Builder> { 046 String thumbUrl; 047 048 Builder() {} 049 050 /** 051 * (REQUIRED) 052 * Sets the URL of the video attachment. Supports only {@code .mp4} and {@code .3gpp} file extensions. 053 * Note: Video codec must be H.264 and audio codec AAC. 054 * 055 * @param url The video URL as a string. 056 * @return This builder. 057 */ 058 @Override 059 public Builder url(String url) { 060 return super.url(url); 061 } 062 063 /** 064 * (REQUIRED) 065 * URL to an image file (.jpg) for a thumbnail preview of the video. 066 * 067 * @param thumbUrl The thumbnail image URL as a string. 068 * @return This builder. 069 */ 070 public Builder thumbUrl(String thumbUrl) { 071 this.thumbUrl = thumbUrl; 072 return this; 073 } 074 075 /** 076 * (REQUIRED) 077 * Length of the video in seconds. Must be between 1 and 600. 078 * 079 * @param duration The video duration as an integer. 080 * @return This builder. 081 */ 082 public Builder duration(int duration) { 083 this.duration = duration; 084 return this; 085 } 086 087 /** 088 * (REQUIRED) 089 * The video file size in megabytes. Must be between 1 and 200. 090 * 091 * @param fileSize The file size as an integer. 092 * @return This builder. 093 */ 094 public Builder fileSize(int fileSize) { 095 this.fileSize = fileSize; 096 return this; 097 } 098 099 /** 100 * (OPTIONAL) 101 * Additional text to accompany the video. 102 * 103 * @param caption The caption string. 104 * @return This builder. 105 */ 106 @Override 107 public Builder caption(String caption) { 108 return super.caption(caption); 109 } 110 111 @Override 112 public ViberVideoRequest build() { 113 return new ViberVideoRequest(this); 114 } 115 } 116}