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