@@ -48,7 +48,6 @@ class Verify(private val client: Verify2Client) {
48
48
properties : VerificationRequest .Builder .() -> Unit ): VerificationResponse =
49
49
client.sendVerification(VerificationRequest .builder().brand(brand).apply (properties).build())
50
50
51
-
52
51
/* *
53
52
* Call this method to work with an existing verification request.
54
53
*
@@ -67,7 +66,7 @@ class Verify(private val client: Verify2Client) {
67
66
fun request (requestId : String ): ExistingRequest = request(UUID .fromString(requestId))
68
67
69
68
/* *
70
- * Call this method to work with an existing verification request.
69
+ * Class for working with an existing verification request.
71
70
*
72
71
* @param uuid UUID of the verification request to work with, as obtained from [VerificationResponse.getRequestId].
73
72
*/
@@ -106,12 +105,14 @@ class Verify(private val client: Verify2Client) {
106
105
*
107
106
* @return A [VerifyCodeResponse] object containing the verification status.
108
107
*
109
- * @throws [VerifyResponseException] If the code could not be checked . This could be for the following reasons:
108
+ * @throws [VerifyResponseException] If the check fails . This could be for the following reasons:
110
109
* - **400**: Invalid code.
111
110
* - **401**: Invalid credentials.
111
+ * - **402**: Account balance too low.
112
112
* - **404**: Request was not found, or it has been verified already.
113
113
* - **409**: The current workflow does not support a code.
114
114
* - **410**: An incorrect code has been provided too many times. Workflow terminated.
115
+ * - **429**: Rate limit exceeded.
115
116
* - **500**: Internal server error.
116
117
*
117
118
* @see isValidVerificationCode For a Boolean-returning version of this method.
@@ -126,6 +127,15 @@ class Verify(private val client: Verify2Client) {
126
127
* @param code The verification code to check, as entered by the user.
127
128
*
128
129
* @return `true` if the code is valid, `false` if it is not.
130
+ *
131
+ * @throws [VerifyResponseException] If the code could not be checked. This could be for the following reasons:
132
+ * - **401**: Invalid credentials.
133
+ * - **402**: Account balance too low.
134
+ * - **404**: Request was not found, or it has been verified already.
135
+ * - **409**: The current workflow does not support a code.
136
+ * - **429**: Rate limit exceeded.
137
+ * - **500**: Internal server error.
138
+ *
129
139
* @see checkVerificationCode For the original implementation which this method delegates to.
130
140
*/
131
141
fun isValidVerificationCode (code : String ): Boolean {
@@ -141,6 +151,237 @@ class Verify(private val client: Verify2Client) {
141
151
}
142
152
}
143
153
}
154
+
155
+ /* *
156
+ * Create a new custom template.
157
+ *
158
+ * @param name Reference name for the template. Must not contain spaces or special characters than `_` and `-`.
159
+ *
160
+ * @return Details of the created template.
161
+ *
162
+ * @throws [VerifyResponseException] If the template could not be created. This could be for the following reasons:
163
+ * - **401**: Invalid credentials.
164
+ * - **402**: Account balance too low.
165
+ * - **403**: Template management is not enabled for your account.
166
+ * - **409**: Template with the same name already exists, or you have 10 templates already.
167
+ * - **429**: Rate limit exceeded.
168
+ * - **500**: Internal server error.
169
+ *
170
+ * @since 1.1.0
171
+ */
172
+ fun createTemplate (name : String ): Template = client.createTemplate(name)
173
+
174
+ /* *
175
+ * List all custom templates for your application.
176
+ *
177
+ * @return A list of all custom templates.
178
+ *
179
+ * @throws [VerifyResponseException] If the templates could not be listed. This could be for the following reasons:
180
+ * - **401**: Invalid credentials.
181
+ * - **402**: Account balance too low.
182
+ * - **429**: Rate limit exceeded.
183
+ * - **500**: Internal server error.
184
+ *
185
+ * @since 1.1.0
186
+ */
187
+ fun listTemplates (): List <Template > = client.listTemplates()
188
+
189
+ /* *
190
+ * Call this method to work with an existing custom template.
191
+ *
192
+ * @param templateId ID of the template to work with as a string.
193
+ *
194
+ * @return An [ExistingTemplate] object with methods to interact with the template.
195
+ *
196
+ * @since 1.1.0
197
+ */
198
+ fun template (templateId : String ): ExistingTemplate = ExistingTemplate (templateId)
199
+
200
+ /* *
201
+ * Class for working with an existing custom template.
202
+ *
203
+ * @param templateId UUID of the template to work with, as obtained from [Template.getId].
204
+ *
205
+ * @since 1.1.0
206
+ */
207
+ inner class ExistingTemplate internal constructor(id : String ): ExistingResource(id) {
208
+ private val templateId = UUID .fromString(id)
209
+
210
+ /* *
211
+ * Get the custom template.
212
+ *
213
+ * @return Details of the custom template.
214
+ *
215
+ * @throws [VerifyResponseException] If the template could not be retrieved. This could be for the following reasons:
216
+ * - **401**: Invalid credentials.
217
+ * - **402**: Account balance too low.
218
+ * - **404**: Template not found.
219
+ * - **429**: Rate limit exceeded.
220
+ * - **500**: Internal server error.
221
+ *
222
+ * @since 1.1.0
223
+ */
224
+ fun get (): Template = client.getTemplate(templateId)
225
+
226
+ /* *
227
+ * Update the custom template. Note that you must specify at least one parameter to change.
228
+ *
229
+ * @param name (OPTIONAL) New reference name for the template.
230
+ * Must not contain spaces or special characters besides `_` and `-`.
231
+ *
232
+ * @param isDefault (OPTIONAL) Whether to set this template as the default.
233
+ *
234
+ * @return Details of the updated template.
235
+ *
236
+ * @throws [VerifyResponseException] If the template could not be updated. This could be for the following reasons:
237
+ * - **401**: Invalid credentials.
238
+ * - **402**: Account balance too low.
239
+ * - **403**: Template management is not enabled for your account.
240
+ * - **404**: Template not found.
241
+ * - **409**: Template with this name already exists.
242
+ * - **429**: Rate limit exceeded.
243
+ * - **500**: Internal server error.
244
+ *
245
+ * @since 1.1.0
246
+ */
247
+ fun update (name : String? = null, isDefault : Boolean? = null): Template =
248
+ client.updateTemplate(templateId, name, isDefault)
249
+
250
+ /* *
251
+ * Delete the custom template.
252
+ *
253
+ * @throws [VerifyResponseException] If the template could not be deleted. This could be for the following reasons:
254
+ * - **401**: Invalid credentials.
255
+ * - **402**: Account balance too low.
256
+ * - **403**: Template management is not enabled for your account.
257
+ * - **404**: Template not found.
258
+ * - **409**: Template is the default or contains undeleted fragments.
259
+ * - **429**: Rate limit exceeded.
260
+ * - **500**: Internal server error.
261
+ *
262
+ * @since 1.1.0
263
+ */
264
+ fun delete (): Unit = client.deleteTemplate(templateId)
265
+
266
+ /* *
267
+ * Create a new template fragment.
268
+ *
269
+ * @param text Text content of the template. There are 4 reserved variables available to use:
270
+ * `${code}`, `${brand}`, `${time-limit}` and `${time-limit-unit}`. You must always use `${code}`.
271
+ * @param locale BCP-47 locale of the fragment.
272
+ * @param channel The channel for the fragment.
273
+ *
274
+ * @return Details of the created fragment.
275
+ *
276
+ * @throws [VerifyResponseException] If the fragment could not be created.
277
+ * This could be for the following reasons:
278
+ *
279
+ * - **401**: Invalid credentials.
280
+ * - **402**: Account balance too low.
281
+ * - **403**: Template management is not enabled for your account.
282
+ * - **404**: Template not found.
283
+ * - **409**: Fragment with the same locale and channel already exists.
284
+ * - **429**: Rate limit exceeded.
285
+ * - **500**: Internal server error.
286
+ *
287
+ * @since 1.1.0
288
+ */
289
+ fun createFragment (text : String , locale : String , channel : FragmentChannel ): TemplateFragment =
290
+ client.createTemplateFragment(templateId, TemplateFragment (channel, locale, text))
291
+
292
+ /* *
293
+ * List all template fragments for the template.
294
+ *
295
+ * @return A list of all template fragments.
296
+ *
297
+ * @throws [VerifyResponseException] If the fragments could not be listed.
298
+ * This could be for the following reasons:
299
+ * - **401**: Invalid credentials.
300
+ * - **402**: Account balance too low.
301
+ * - **404**: Template not found.
302
+ * - **429**: Rate limit exceeded.
303
+ * - **500**: Internal server error.
304
+ *
305
+ * @since 1.1.0
306
+ */
307
+ fun listFragments (): List <TemplateFragment > = client.listTemplateFragments(templateId)
308
+
309
+ /* *
310
+ * Call this method to work with an existing template fragment.
311
+ *
312
+ * @param fragmentId ID of the fragment to work with as a string.
313
+ *
314
+ * @return An [ExistingTemplateFragment] object with methods to interact with the fragment.
315
+ *
316
+ * @since 1.1.0
317
+ */
318
+ fun fragment (fragmentId : String ): ExistingTemplateFragment = ExistingTemplateFragment (fragmentId)
319
+
320
+ /* *
321
+ * Class for working with an existing template fragment.
322
+ *
323
+ * @param fragmentId UUID of the fragment to work with, as obtained from [TemplateFragment.getId].
324
+ *
325
+ * @since 1.1.0
326
+ */
327
+ inner class ExistingTemplateFragment internal constructor(id : String ): ExistingResource(id) {
328
+ private val fragmentId = UUID .fromString(id)
329
+
330
+ /* *
331
+ * Get the template fragment.
332
+ *
333
+ * @return Details of the template fragment.
334
+ *
335
+ * @throws [VerifyResponseException] If the fragment could not be retrieved.
336
+ * This could be for the following reasons:
337
+ * - **401**: Invalid credentials.
338
+ * - **402**: Account balance too low.
339
+ * - **404**: Fragment not found.
340
+ * - **429**: Rate limit exceeded.
341
+ * - **500**: Internal server error.
342
+ *
343
+ * @since 1.1.0
344
+ */
345
+ fun get (): TemplateFragment = client.getTemplateFragment(templateId, fragmentId)
346
+
347
+ /* *
348
+ * Update the template fragment.
349
+ *
350
+ * @param text New text for the fragment. There are 4 reserved variables available to use:
351
+ *`${code}`, `${brand}`, `${time-limit}` and `${time-limit-unit}`. You must always use `${code}`.
352
+ *
353
+ * @return Details of the updated fragment.
354
+ *
355
+ * @throws [VerifyResponseException] If the fragment could not be updated.
356
+ * This could be for the following reasons:
357
+ * - **401**: Invalid credentials.
358
+ * - **402**: Account balance too low.
359
+ * - **403**: Template management is not enabled for your account.
360
+ * - **404**: Fragment not found.
361
+ * - **429**: Rate limit exceeded.
362
+ * - **500**: Internal server error.
363
+ *
364
+ * @since 1.1.0
365
+ */
366
+ fun update (text : String ): TemplateFragment = client.updateTemplateFragment(templateId, fragmentId, text)
367
+
368
+ /* *
369
+ * Delete the template fragment.
370
+ *
371
+ * @throws [VerifyResponseException] If the fragment could not be deleted.
372
+ * This could be for the following reasons:
373
+ * - **401**: Invalid credentials.
374
+ * - **402**: Account balance too low.
375
+ * - **403**: Template management is not enabled for your account.
376
+ * - **404**: Fragment not found.
377
+ * - **429**: Rate limit exceeded.
378
+ * - **500**: Internal server error.
379
+ *
380
+ * @since 1.1.0
381
+ */
382
+ fun delete (): Unit = client.deleteTemplateFragment(templateId, fragmentId)
383
+ }
384
+ }
144
385
}
145
386
146
387
/* *
0 commit comments