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.sms.messages;
017
018
019import org.apache.http.client.methods.RequestBuilder;
020
021/**
022 * Represents the details of a wap-push message that is to be submitted via the Vonage REST api.
023 *
024 * @author Paul Cook
025 */
026public class WapPushMessage extends Message {
027    private final String url;
028    private final String title;
029    private Integer validity;
030
031    /**
032     * Instantiate a new wap-push message request, to submit a browsable / downloadable URL to the handset
033     *
034     * @param from  the 'from' address that will be seen on the handset when this message arrives,
035     *              typically either a valid short-code / long code that can be replied to, or a short text description of the application sending the message (Max 11 chars)
036     * @param to    the phone number of the handset that you wish to send the message to
037     * @param url   This is the url that will be submitted to the handset and will appear as a browsable message in the Inbox.
038     * @param title This is the title that will be associated with the url being submitted to the handset
039     */
040    public WapPushMessage(final String from,
041                          final String to,
042                          final String url,
043                          final String title) {
044        super(MessageType.WAPPUSH, from, to);
045
046        this.url = url;
047        this.title = title;
048    }
049
050    /**
051     * @return String This is the url that will be submitted to the handset and will appear as a browsable message in the Inbox.
052     */
053    public String getUrl() {
054        return this.url;
055    }
056
057    /**
058     * @return String This is the title that will be associated with the url being submitted to the handset
059     */
060    public String getTitle() {
061        return this.title;
062    }
063
064    /**
065     * @return Integer This is the length of time (in seconds) that the message will be available for once delivered to
066     * the handset.
067     * Once this time has expired, the url will no longer be visible on the handset to be browsed (Subject to handset compatibility)
068     */
069    public Integer getValidity() {
070        return this.validity;
071    }
072
073    public void setValidity(Integer validity) {
074        this.validity = validity;
075    }
076
077    @Override
078    public void addParams(RequestBuilder request) {
079        super.addParams(request);
080        request.addParameter("title", title)
081                .addParameter("url", url);
082        if (validity != null) {
083            request.addParameter("validity", validity.toString());
084        }
085    }
086}