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