|
15 | 15 | */ |
16 | 16 | package com.vonage.client.verify2; |
17 | 17 |
|
18 | | -import com.fasterxml.jackson.annotation.JsonIgnore; |
19 | | -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
20 | | -import com.fasterxml.jackson.annotation.JsonInclude; |
21 | | -import com.fasterxml.jackson.annotation.JsonProperty; |
| 18 | +import com.fasterxml.jackson.annotation.*; |
22 | 19 | import com.vonage.client.Jsonable; |
23 | 20 | import java.util.ArrayList; |
24 | 21 | import java.util.List; |
| 22 | +import java.util.Locale; |
25 | 23 | import java.util.Objects; |
26 | 24 | import java.util.regex.Pattern; |
27 | 25 |
|
|
41 | 39 | public class VerificationRequest implements Jsonable { |
42 | 40 | static final Pattern CODE_REGEX = Pattern.compile("[a-zA-Z0-9]{4,10}"); |
43 | 41 |
|
44 | | - protected final Locale locale; |
| 42 | + @JsonProperty("locale") protected final Locale locale; |
45 | 43 | protected final Integer channelTimeout, codeLength; |
46 | 44 | protected final Boolean fraudCheck; |
47 | 45 | protected final String brand, code, clientRef; |
@@ -98,13 +96,18 @@ public String getBrand() { |
98 | 96 | /** |
99 | 97 | * Language for the request in ISO_639-1 format. |
100 | 98 | * |
101 | | - * @return The language as an enum, or {@code null} if not set (the default). |
| 99 | + * @return The locale, or {@code null} if not set (the default). |
102 | 100 | */ |
103 | | - @JsonProperty("locale") |
| 101 | + @JsonIgnore |
104 | 102 | public Locale getLocale() { |
105 | 103 | return locale; |
106 | 104 | } |
107 | 105 |
|
| 106 | + @JsonGetter("locale") |
| 107 | + protected String getLocaleAsString() { |
| 108 | + return locale == null ? null : locale.toString().replace("_", "-").toLowerCase(); |
| 109 | + } |
| 110 | + |
108 | 111 | /** |
109 | 112 | * Specifies the wait time in seconds between attempts to delivery the verification code. |
110 | 113 | * |
@@ -292,17 +295,40 @@ public Builder channelTimeout(int timeout) { |
292 | 295 |
|
293 | 296 | /** |
294 | 297 | * (OPTIONAL) |
295 | | - * Languages that are available to use. |
| 298 | + * Set the language that this request will be delivered in. Refer to |
| 299 | + * <a href=https://developer.vonage.com/en/verify/guides/verify-v2-languages>the documentation</a> |
| 300 | + * for a list of supported locales. |
296 | 301 | * |
297 | | - * @param locale The language locale as an enum. |
| 302 | + * @param locale The language locale. |
298 | 303 | * |
299 | 304 | * @return This builder. |
| 305 | + * |
| 306 | + * @since 8.0.0 |
300 | 307 | */ |
301 | 308 | public Builder locale(Locale locale) { |
| 309 | + if (locale == null || locale.toString().isEmpty()) { |
| 310 | + throw new IllegalArgumentException("Invalid locale"); |
| 311 | + } |
302 | 312 | this.locale = locale; |
303 | 313 | return this; |
304 | 314 | } |
305 | 315 |
|
| 316 | + /** |
| 317 | + * (OPTIONAL) |
| 318 | + * Set the language that this request will be delivered in. |
| 319 | + * |
| 320 | + * @param locale The language locale as a string. This should be a |
| 321 | + * <a href=https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>ISO 639-1 code</a>. |
| 322 | + * |
| 323 | + * @return This builder. |
| 324 | + * |
| 325 | + * @since 8.0.0 |
| 326 | + * @see #locale(Locale) |
| 327 | + */ |
| 328 | + public Builder locale(String locale) { |
| 329 | + return locale(Locale.forLanguageTag(locale)); |
| 330 | + } |
| 331 | + |
306 | 332 | /** |
307 | 333 | * (OPTIONAL) |
308 | 334 | * If this reference is set when the request is sent, it will be included in the callbacks. |
|
0 commit comments