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.verify;
023
024import java.util.Locale;
025
026/**
027 * Describes a Verify request when passed to
028 * {@link com.nexmo.client.verify.VerifyEndpoint})}.
029 */
030public class VerifyRequest {
031    // Compulsory attrs:
032    private final String number;
033    private final String brand;
034
035    private String from = null;     // sender_id
036    private int length = -1;        // code_length
037    private Locale locale = null;   // lg
038    private LineType type = null;   // require_type
039
040    private String country = null;
041    private Integer pinExpiry = null;
042    private Integer nextEventWait = null;
043
044
045    /**
046     * Constructor.
047     *
048     * @param number (required) The recipient's phone number in <a href="https://en.wikipedia.org/wiki/E.164">E.164</a>
049     *               format.
050     * @param brand  (required) The name of the company or app to be verified for. Must not be longer than 18
051     *               characters.
052     */
053    public VerifyRequest(final String number, final String brand) {
054        this(number, brand, null, -1, null, null);
055    }
056
057    /**
058     * Constructor.
059     *
060     * @param number (required) The recipient's phone number in <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
061     * @param brand  (required) The name of the company or app you are verifying for. Must not be longer than 18
062     *               characters.
063     * @param from   (optional The Nexmo number to use as the sender for the verification SMS message and calls, in
064     *               <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
065     */
066    public VerifyRequest(final String number, final String brand, final String from) {
067        this(number, brand, from, -1, null, null);
068    }
069
070    /**
071     * Constructor.
072     *
073     * @param number (required) The recipient's phone number in <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
074     * @param brand  (required) The name of the company or app you are verifying for. Must not be longer than 18
075     *               characters.
076     * @param from   (optional The Nexmo number to use as the sender for the verification SMS message and calls, in
077     *               <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
078     * @param length (optional) The length of the verification code to be sent to the user. Must be either 4 or 6. Use
079     *               -1 to use the default value.
080     * @param locale (optional) Override the default locale used for verification. By default the locale is determined
081     *               from the country code included in {@code number}
082     */
083    public VerifyRequest(final String number, final String brand, final String from, final int length, final Locale locale) {
084        this(number, brand, from, length, locale, null);
085    }
086
087    /**
088     * Constructor.
089     *
090     * @param number (required) The recipient's phone number in <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
091     * @param brand  (required) The name of the company or app you are verifying for. Must not be longer than 18
092     *               characters.
093     * @param from   (optional A short alphanumeric string to specify the SenderID for SMS sent by Verify.
094     *               Depending on the destination of the phone number you are applying, restrictions may apply.
095     *               By default, sender_id is {@code VERIFY}. Must be 11 characters or fewer.
096     * @param length (optional) The length of the verification code to be sent to the user. Must be either 4 or 6. Use
097     *               -1 to use the default value.
098     * @param locale (optional) Override the default locale used for verification. By default the locale is determined
099     *               from the country code included in {@code number}
100     * @param type   (optional) If provided, restrict the verification to the specified network type. Contact
101     *               support@nexmo.com to enable this feature.
102     */
103    public VerifyRequest(final String number, final String brand, final String from, final int length, final Locale locale, final LineType type) {
104        if (number == null || brand == null)
105            throw new IllegalArgumentException("Number and brand parameters cannot be null.");
106        if (length > 0 && length != 4 && length != 6) throw new IllegalArgumentException("Code length must be 4 or 6.");
107
108        this.number = number;
109        this.brand = brand;
110        this.from = from;
111        this.length = length;
112        this.locale = locale;
113        this.type = type;
114    }
115
116    /**
117     * @return the recipient's phone number provided in the constructor, in
118     *         <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format.
119     */
120    public String getNumber() {
121        return number;
122    }
123
124    /**
125     * @return the name of the company or app to be verified for.
126     */
127    public String getBrand() {
128        return brand;
129    }
130
131    /**
132     * @return the short alphanumeric string to specify the SenderID for SMS sent by Verify, or {@code null} if one was
133     *         not provided. This value is specified in some {@link VerifyRequest} constructors.
134     *         <p>
135     *         If this value is {@code null</tt>, the sender_id used will be <tt>VERIFY}.
136     */
137    public String getFrom() {
138        return from;
139    }
140
141    public void setFrom(String from) {
142        this.from = from;
143    }
144
145    /**
146     * @return the length of the verification code to be sent to the user, specified in some {@link VerifyRequest}
147     *         constructors. {@code -1} indicates the default length will be used.
148     */
149    public int getLength() {
150        return length;
151    }
152
153    public void setLength(int length) {
154        this.length = length;
155    }
156
157    /**
158     * @return the default locale used for verification. If this value is {@code null}, the locale will be determined
159     *         from the country code included in {@code number}
160     */
161    public Locale getLocale() {
162        return locale;
163    }
164
165
166    public void setLocale(Locale locale) {
167        this.locale = locale;
168    }
169
170    /**
171     * @return the type of network the verification will be restricted to. This value has no effect unless it has been
172     *         enabled by contacting {@code support@nexmo.com}.
173     */
174    public LineType getType() {
175        return type;
176    }
177
178
179    public void setType(LineType type) {
180        this.type = type;
181    }
182
183    /**
184     * The country for the destination phone number.
185     *
186     * @return a String containing a 2-character country code
187     */
188    public String getCountry() {
189        return country;
190    }
191
192    /**
193     * The country for the destination phone number.
194     * <p>
195     * If you wish to used localised number formats or you are not sure if number is correctly formatted, set this to
196     * a two-character country code. For example, GB, US. Verify will work out the international phone number for you.
197     *
198     * @param country a String containing a 2-character country code
199     */
200    public void setCountry(String country) {
201        this.country = country;
202    }
203
204    /**
205     * Get the PIN validity time from generation, in seconds, or null if this has not been set.
206     */
207    public Integer getPinExpiry() {
208        return pinExpiry;
209    }
210
211    /**
212     * Set the PIN validity time from generation, in seconds. The default (null) is 300 seconds.
213     */
214    public void setPinExpiry(Integer pinExpiry) {
215        this.pinExpiry = pinExpiry;
216    }
217
218    /**
219     * Get the wait time between attempts to deliver the PIN.
220     *
221     * @return An Integer between 600-900, or null.
222     */
223    public Integer getNextEventWait() {
224        return nextEventWait;
225    }
226
227    /**
228     * Set the wait time between attempts to deliver the PIN.
229     *
230     * @param nextEventWait An Integer value between 60 and 900 seconds, or null to use the default duration.
231     */
232    public void setNextEventWait(Integer nextEventWait) {
233        this.nextEventWait = nextEventWait;
234    }
235
236    /**
237     * Types of phone line to be specified for {@link VerifyRequest#type}.
238     */
239    public enum LineType {
240        ALL, MOBILE, LANDLINE,
241    }
242}